feat: add _meta field support to tool definitions #922
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.
Enables tools to include arbitrary metadata that gets returned in tools/list responses. Includes comprehensive tests and maintains backward compatibility.
Motivation and Context
The MCP specification already defines support for the
_metafield in tool definitions, but the TypeScript SDK wasn't implementing it. This change was needed to:_metausageWithout this feature, tool authors had no way to provide additional context about their tools beyond the basic name, description, and schema.
How Has This Been Tested?
_metafieldstools/listrequests_metacontinue to work and returnundefined_metafunctionalityThe implementation has been tested with various metadata scenarios including nested objects, arrays, and different data types.
Breaking Changes
None. This is a fully backward-compatible addition:
_metacontinue to work unchanged_metafield is optional in all interfacesTypes of changes
Checklist
Additional context
Implementation Details:
_meta?: Record<string, unknown>toRegisteredTooltyperegisterToolconfig interface to accept_metaparameter_createRegisteredToolmethod to handle_metastorage and updatesListToolsRequestSchemahandler to include_metain responsesDesign Decisions:
Record<string, unknown>type to allow maximum flexibility while maintaining type safety_metais completely separate from the request-level_meta(used for progress tokens)annotations_metafield guidelinesSecurity Considerations:
_metaand tool definition_meta