[Proposal] Suggested Response Format #315
Replies: 2 comments 1 reply
-
|
This sounds great. I like that I can tell a GPT model that I want structured output and provide a schema for it. But that's up to the model to sort out. Here, we're calling a tool, which may or may not make a sampling request to a model and pass on this desired format. And even if it did, all models may not be great at structured output. This is more like GraphQL where the client is driving the response shape. Except we don't have a handy server-side framework for handling that sort of thing. The server logic has to be prepared to respond to any requested schema shape, or ignore the suggestion. Super simple exampleLet's say it's a tool that gets the current temperature and barometric pressure for a given city. No model involved, just hitting an API and returning results. And, let's say the client's author is Spanish-speaking, and instead of the default response of: {
"city": "string",
"temperature": "number",
"pressure": "number"
}They would like: {
"ciudad": "string"
"temperatura": "number",
"presión": "number"
}How is the server supposed to handle that? The shape is the same but the properties are different. Examples where the shape is different are bigger problem, but they could be mixed. I'm just thinking about how to code tools when the server isn't dictating the response format. If this client-suggested response format was a thing, how many server developers would attempt to support it? I suspect most would return the format that makes most sense to them and set Possible ways this could workUse an LLM
Template, not schemaThe client sends something akin to a handlebars template, with variables for the fields this tool normally returns. That template could be JSON shaped of course, but it's not a schema. The tool looks for the variable names it knows about and replaces them in the template, returning that. More work for everyone?
Am I missing the point?I'm not totally writing off the idea, I just don't think anyone would really use it because of the extra development burden. And even if we went to all the work to implement this, I'm not certain what the value proposition actually is. Tools are intended to be called by an LLM, and they are pretty good at handling unstructured data. It is the LLM that you want to ask for structured responses from, so that they can be machine-readable. Seen in this light, the above example is kind of hilarious, because the LLM would have sent a tool call with a suggested response format and then the tool would ask the LLM to format it correctly, so it could then return the formatted value to the LLM? |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @cliffhall for detailed thought, a premise here is that tools are useful beyond LLMs also, quoting from this thread: #97 (comment): With this premise an immediate thing that MCP can include is being discussed in: #97. Essentially tools describe their outputSchema and that output is clearly incorporated in result. I think suggestions in #97 should definitely adopted, seems like a clear value add. An additional dimension being covered in this(#315 ) thread is if server is an agent, then an important functionality that client app can use is to prescribe a schema for response. For example: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses. I do realize this maybe early though, trying to gather feedback. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Pre-submission Checklist
Your Idea
This was an excellent approach from PydanticAI, got adopted by hosted agents and other protocols too. I see in forums lot of developers find it useful. Caveat is that LLMs have become better, so they can possibly work with unstructured results or there can be specialized transformation abstractions that clients can integrated which offload this work from agent developers. Would be great to get feedback on all of these dimensions.
Abstract
This proposal outlines a mechanism to enable MCP clients to request structured outputs from tool calls, allowing the client to specify a desired response format (such as JSON with a specific schema). By supporting structured outputs, MCP can better serve developer use cases requiring machine-processable responses, particularly for agentic workflows and application integrations.
Motivation
Current MCP tool responses are primarily designed for human readability, returning free-form text that requires additional parsing to extract structured data. This approach creates several challenges:
Many MCP use cases involve integrating tools into workflows that require structured data processing. By allowing clients to request specific output formats, we can improve developer experience and enable more robust integrations.
Proposal Details
We propose extending the
tools/callrequest to include a schema specification that indicates the client's suggested response format.Changes to Request Schema
Response Format
The server would return a response conforming to the requested format whenever possible:
For JSON responses, the formatted content would be provided as a valid JSON string within a
TextContentobject ofCallToolResult:Extend tool annotation
Extend tool annotations to hint if it supports formatting.
Request Flow Examples
Server Behavior
Servers implementing this proposal should:
suggestedFormatfield in requests when presentformatApplied: truein metadata when successfully meeting format requirementsClient Behavior
Clients using this feature should:
Backward Compatibility
This proposal maintains full backward compatibility:
Alternatives
References
Scope
Beta Was this translation helpful? Give feedback.
All reactions