feat: add _meta field support to tool definitions #922
+103
−2
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
_meta
field in tool definitions, but the TypeScript SDK wasn't implementing it. This change was needed to:_meta
usageWithout 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?
_meta
fieldstools/list
requests_meta
continue to work and returnundefined
_meta
functionalityThe 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:
_meta
continue to work unchanged_meta
field is optional in all interfacesTypes of changes
Checklist
Additional context
Implementation Details:
_meta?: Record<string, unknown>
toRegisteredTool
typeregisterTool
config interface to accept_meta
parameter_createRegisteredTool
method to handle_meta
storage and updatesListToolsRequestSchema
handler to include_meta
in responsesDesign Decisions:
Record<string, unknown>
type to allow maximum flexibility while maintaining type safety_meta
is completely separate from the request-level_meta
(used for progress tokens)annotations
_meta
field guidelinesSecurity Considerations:
_meta
and tool definition_meta