Skip to content

Conversation

@macbookandrew
Copy link

This adds the ability for MCP tools to return a structuredContent key/value object as defined in the spec.

This will be useful for building ChatGPT Apps and passing tool responses to the app UI:

@grachov
Copy link

grachov commented Oct 10, 2025

@macbookandrew This is a really nice feature - I was actually thinking about implementing something similar myself, but you beat me to it 😄
According to the specification, the content text should match the same JSON that’s sent in the structuredContent field: https://modelcontextprotocol.io/specification/draft/server/tools#structured-content.
It would also be great to include an outputSchema property for better alignment with the spec and to make the output more consistent.

@nunomaduro Were you considering using a different library for JSON Schema? The current one seems a bit limited - for example, it doesn’t support all properties defined in the spec.

@macbookandrew
Copy link
Author

According to the specification, the content text should match the same JSON that’s sent in the structuredContent field: https://modelcontextprotocol.io/specification/draft/server/tools#structured-content.

Hmm...good point. So maybe instead of ->withStructuredContent() it makes more sense to add a new Response::structured(...) instead?

@grachov
Copy link

grachov commented Oct 10, 2025

Yes, or even a separate response class to build and validate CallTool response easier.

@macbookandrew macbookandrew marked this pull request as draft October 11, 2025 12:06
@davidhole
Copy link

Looks really great! I think your suggestion @macbookandrew of Response::structured(...) seems like a really good approach.

I guess we'd also need to define the output schema as we do the input schema as per the spec also?

And then a few JSON assertions on the test response and it'd be perfect.

Let me know if you like me to contribute!

@macbookandrew
Copy link
Author

Thanks for your input guys! I'm not sure we need the output schema so haven't added it yet, but this now uses Response::structured(...) and I'm going to start testing this branch in a work project tomorrow to get a feel for real-world use.

Any thoughts on this so far? Anybody want to add the output schema?

@wpalani
Copy link

wpalani commented Oct 22, 2025

Working on a project now and this fit exactly what i need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants