Use sampling when the client should provide the model
Sampling is useful when the connected client already has the right model, credentials, policy, or user context. Good fits:
Do not use sampling for deterministic server logic, authorization decisions, or work that must succeed in clients without sampling support.
Check client support
Only callctx.sample() when the client advertises the sampling capability. Provide a deterministic fallback.
Keep prompts narrow
Sampling works best when the prompt asks for one clear output. Put server-side data into the prompt and ask for a bounded result.Use full control when needed
Use the full request form when the tool needs a system prompt, multiple messages, or model preferences.Report long-running progress
Sampling can take time. If the client supplied a progress token, mcp-use can report progress while waiting. For custom progress handling or intervals, see the Tool context API reference. For long non-sampling work, usectx.reportProgress directly:
Handle sampling failures
Sampling can fail when the client rejects the request, disconnects, times out, or returns content your tool does not expect.Test sampling locally
Run a server with a sampling tool and call it from a client that supports sampling, such as the Inspector.Next steps
Tool context API reference
Look up
ctx.sample() overloads, options, progress behavior, and return
shapes.Elicitation
Ask the user for input during tool execution.
Notifications
Send status, progress, and custom notifications to connected clients.
Client sampling
Configure sampling support in a TypeScript MCP client.