python-sdk
python-sdk copied to clipboard
Add support for _meta attributes in resource contents
This change enables MCP servers to include metadata in resource content using the _meta field, which is part of the MCP specification. This allows servers to provide additional context about resources, such as domain information or other custom metadata.
Changes:
- Added meta field to ReadResourceContents helper class
- Added _meta field to Resource base class with proper alias
- Updated lowlevel server handler to pass through _meta when creating TextResourceContents and BlobResourceContents
- Updated FastMCP server to pass resource._meta to ReadResourceContents
- Added comprehensive tests for _meta support in both lowlevel and FastMCP resources
The implementation maintains backward compatibility - resources without _meta continue to work as before with meta=None.
Motivation and Context
How Has This Been Tested?
Breaking Changes
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
related: https://github.com/modelcontextprotocol/python-sdk/pull/1476
Before this is merged, is there any workaround?