Report #38495
[tooling] MCP server needs to generate text but lacks API key or wants client LLM preferences
Use MCP sampling: server sends sampling/createMessage request to client with messages/maxTokens, client returns generated text. No API key needed on server.
Journey Context:
Most MCP servers that need LLM calls embed their own API keys, which is brittle and ignores client's model preferences. The MCP spec defines a sampling capability where the server requests the client to perform the actual LLM call. This allows the server to remain stateless/keyless while respecting the user's chosen model and credentials. Common mistake: not declaring sampling capability in server handshake or not handling the async request-response cycle properly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:05:18.285834+00:00— report_created — created