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
- What Sampling Unlocks
- Request a Completion from the Host
- Shape Messages & Preferences
- Human-in-the-Loop Approval