Skip to content

feat: Add _meta field to classes across MCPSchema #368

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

Closed

Conversation

pantanurag555
Copy link
Contributor

@pantanurag555 pantanurag555 commented Jul 2, 2025

Motivation and Context

_meta field was added to multiple classes in the schema to make it easy to pass metadata when communicating between an MCP client and server. Relevant spec PR: modelcontextprotocol/modelcontextprotocol#710

This PR adds _meta field across all relevant classes in MCPSchema. It also creates new interfaces for Result and Notifications to ensure that this field is added to any future classes created that implement these interfaces.

Currently MCPSchema in java SDK is missing classes for different list requests (ListResourcesRequest, ListToolsRequest etc-) opting to create the JSONRPCRequest and send it directly to the server instead. Similarly the class for RootsListChangedNotification is missing as well. Therefore, it is not possible to add _meta field to these exchanges between the server and client as of now. Relevant classes should be added to the java SDK in the future to maintain parity with the specification. This PR does not address this issue.

Resolves #344

How Has This Been Tested?

Added relevant unit tests for all classes.

Breaking Changes

None. Added relevant backward compatible constructors to ensure

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

Copy link
Contributor

@tzolov tzolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pantanurag555 , thank you for the PR,
I've started reviewing it and put some comments. Also making the Resource not implement a ResourceContent is suspicious?

But since you've made a lot unnecessary formatting changes it is very hard to review.
Can you please revert all non-essential changes (like formatting) to make it a more readable.

cheers

@pantanurag555
Copy link
Contributor Author

@pantanurag555 , thank you for the PR, I've started reviewing it and put some comments. Also making the Resource not implement a ResourceContent is suspicious?

But since you've made a lot unnecessary formatting changes it is very hard to review. Can you please revert all non-essential changes (like formatting) to make it a more readable.

cheers

Addressed the feedback. It should be easier to understand when taking a look at the diff. The PR needs to be rebased due to other changes on the same files (which can be quite laborious). Waiting for any additional feedback before attempting the final rebase.

@msievers
Copy link

I’m very glad to see that active work is already being done on supporting the _meta field in the SDK. This could potentially enable new use cases and serve as a building block to potentially allow for things like ToolContext propagation between MCP client and server in SpringAI.

Even though it can't yet be said with certainty whether it will be used for that purpose in the future, support for it in the SDK will at least create the possibility for it.

tzolov pushed a commit that referenced this pull request Jul 17, 2025
- Add _meta field to all MCP schema records for extensible metadata support
- Introduce Result and Notification sealed interfaces for better type organization
- Update Request interface to include SubscribeRequest and UnsubscribeRequest
- Add backwards-compatible constructors for existing record types
- Enhance test coverage for metadata field functionality

Breaking change: Modifyibng the Request seald inteface is a breaking change.
@tzolov
Copy link
Contributor

tzolov commented Jul 17, 2025

Thank you @pantanurag555

@tzolov tzolov added this to the 0.11.0 milestone Jul 17, 2025
@tzolov tzolov self-assigned this Jul 17, 2025
@tzolov
Copy link
Contributor

tzolov commented Jul 17, 2025

Squashed and merged at 87cdaf8

@tzolov tzolov closed this Jul 17, 2025
@pantanurag555 pantanurag555 deleted the metadata branch July 17, 2025 15:37
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.

feat: Add support for _meta across fields defined in MCPSchema
3 participants