Skip to content

Conversation

BrandonShar
Copy link

@BrandonShar BrandonShar commented Oct 9, 2025

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 use Annotated types to still support output schemas with CallToolResult returns.

Users will have a choice of either:

  1. No return typehint, no output schema (same behavior as now)
  2. CallToolResult return typehint -> no output schema.
  3. Annotated[CallToolResult, SomeClass] -> SomeClass output schema

How Has This Been Tested?

MCP Inspector with a new example file
Screenshot 2025-10-09 at 9 40 07 PM

Screenshot 2025-10-09 at 9 43 32 PM Screenshot 2025-10-09 at 9 44 05 PM

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@BrandonShar BrandonShar changed the title Allow ToolCallResult to be returned directly to support _meta field Allow CallToolResult to be returned directly to support _meta field Oct 9, 2025
@BrandonShar BrandonShar changed the title Allow CallToolResult to be returned directly to support _meta field Allow CallToolResult to be returned directly to support _meta field for OpenAI Apps Oct 10, 2025
@BrandonShar
Copy link
Author

@felixweinberger could you add this to the Meta improvements milestone?

@maxisbey maxisbey added enhancement New feature or request P1 Significant bug affecting many users, highly requested feature needs more eyes Needs alignment among maintainers whether this is something we want to add labels Oct 10, 2025
@felixweinberger felixweinberger added this to the META Improvements milestone Oct 10, 2025
@BrandonShar BrandonShar mentioned this pull request Oct 10, 2025
3 tasks
@maxisbey
Copy link
Contributor

maxisbey commented Oct 13, 2025

Related:

@felixweinberger felixweinberger added needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention and removed needs more eyes Needs alignment among maintainers whether this is something we want to add labels Oct 13, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants