Allow CallToolResult to be returned directly to support _meta field for OpenAI Apps #1459
+145
−3
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