MCP Academy · Lesson

Request a Completion from the Host

Call the client to run an LLM prompt.

The Request Method

To ask for a generation, your server sends a sampling/createMessage request to the client over the protocol.

{ "method": "sampling/createMessage" }

Reach the Client via Context

Inside a tool you get a Context object. Its session is your line back to the client that can run sampling.

async def tool(topic: str, ctx: Context) -> str:
    ...

All lessons in this course

  1. What Sampling Unlocks
  2. Request a Completion from the Host
  3. Shape Messages & Preferences
  4. Human-in-the-Loop Approval
← Back to MCP Academy