-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Allow CallToolResult to be returned directly to support _meta field for OpenAI Apps #1459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
maxisbey
merged 5 commits into
modelcontextprotocol:main
from
BrandonShar:allow-tool-call-result-to-be-returned-directly
Oct 21, 2025
Merged
Allow CallToolResult to be returned directly to support _meta field for OpenAI Apps #1459
maxisbey
merged 5 commits into
modelcontextprotocol:main
from
BrandonShar:allow-tool-call-result-to-be-returned-directly
Oct 21, 2025
+445
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@felixweinberger could you add this to the Meta improvements milestone? |
9 tasks
Add validation to prevent CallToolResult from being used with Union or Optional types, which creates ambiguous behavior and validation issues.
d8b704b
to
350dee0
Compare
Thank you for the submission! I've added some code to error on registration if the function has a union type with CallToolResults as that would kinda break stuff. Also added some documentation for using this. |
maxisbey
approved these changes
Oct 21, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
New feature or request
needs maintainer action
Potentially serious issue - needs proactive fix and maintainer attention
P1
Significant bug affecting many users, highly requested feature
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows tools to directly return
CallToolResult
instead of having it cast automatically by the lowlevel server.Motivation and Context
OpenAI's Apps SDK uses the
_meta
field of a tool call result to allow passing data to app components without them being seen by the model. This behavior is supported by the protocol, but isn't implemented in the SDK.In order to maximize discoverability and future change-abililty, I added the ability to directly return the
CallToolResult
, which already supports the _meta field, rather than add additional tuple fields.The drawback to this method is that output schemas can't be used since they're based on the method's return type. I think that's a fair tradeoff though because the user is basically saying they want to take control themselves.We can useAnnotated
types to still support output schemas withCallToolResult
returns.Users will have a choice of either:
CallToolResult
return typehint -> no output schema.Annotated[CallToolResult, SomeClass]
->SomeClass
output schemaHow Has This Been Tested?
MCP Inspector with a new example file

Breaking Changes
None.
Types of changes
Checklist
Additional context