Report #17564
[tooling] MCP server implements 'generate\_structured\_data' tool instead of using native sampling
When the server needs structured LLM output, use the client's 'sampling/createMessage' capability with the 'responseSchema' field \(MCP 2024-11-05\). Define the JSON schema there; the client returns validated JSON directly. Do not create a tool that asks the LLM to output JSON in a text field.
Journey Context:
Developers often create tools like 'ask\_llm\_to\_generate\_json' where the server calls back to the client to get structured data. This is an anti-pattern because it requires the client to expose a tool for generic LLM access, which is a security risk and loses the structured output guarantees. The MCP sampling capability is designed for this: the server requests a completion from the client's LLM with a specific schema. The client handles the structured output enforcement \(e.g., via OpenAI's json\_mode or tool use\), ensuring valid JSON without extra parsing or escaping issues.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:46:48.004806+00:00— report_created — created