[Schema] Add _meta to CallToolResult #148
Merged
+26
−10
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.
Summary
Add
_metafield support toCallToolResultto allow passing metadata in tool call responses.Motivation and Context
The MCP specification supports a
_metafield for passing additional metadata in responses. This field was missing from theCallToolResultclass, preventing servers from including metadata such as execution time, cache status, version information, or other contextual data in tool call responses.This change brings
CallToolResultin line with other schema classes that already support the_metafield (likeTool,Resource, etc.), providing a consistent API across the SDK.How Has This Been Tested?
metaparameter is properly added to the constructorsuccess()anderror()static methods accept and pass themetaparameterfromArray()correctly deserializes the_metafieldjsonSerialize()includes_metain the output when presentBreaking Changes
None. This is a backward-compatible change:
metaparameter is optional with a default value ofnull_metafield is only included in JSON output when explicitly providedTypes of changes
Checklist
Additional context
Changes made:
metaparameter to constructor with PHPDocsuccess()static method to accept and passmetaerror()static method to accept and passmetafromArray()to deserialize_metafrom inputjsonSerialize()to include_metain output when presentThe
_metafield follows the MCP convention of using an underscore prefix to distinguish it from standard protocol fields.