Skip to content

Conversation

@bb-c24
Copy link
Contributor

@bb-c24 bb-c24 commented Nov 13, 2025

Summary

Add _meta field support to CallToolResult to allow passing metadata in tool call responses.

Motivation and Context

The MCP specification supports a _meta field for passing additional metadata in responses. This field was missing from the CallToolResult class, preventing servers from including metadata such as execution time, cache status, version information, or other contextual data in tool call responses.

This change brings CallToolResult in line with other schema classes that already support the _meta field (like Tool, Resource, etc.), providing a consistent API across the SDK.

How Has This Been Tested?

  • Verified that the meta parameter is properly added to the constructor
  • Confirmed that success() and error() static methods accept and pass the meta parameter
  • Checked that fromArray() correctly deserializes the _meta field
  • Verified that jsonSerialize() includes _meta in the output when present
  • Ensured backward compatibility - all parameters are optional with null defaults

Breaking Changes

None. This is a backward-compatible change:

  • The meta parameter is optional with a default value of null
  • Existing code will continue to work without modifications
  • The _meta field is only included in JSON output when explicitly provided

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

Changes made:

  1. Added meta parameter to constructor with PHPDoc
  2. Updated success() static method to accept and pass meta
  3. Updated error() static method to accept and pass meta
  4. Updated fromArray() to deserialize _meta from input
  5. Updated jsonSerialize() to include _meta in output when present
  6. Updated all PHPDoc type annotations to reflect the new field

The _meta field follows the MCP convention of using an underscore prefix to distinguish it from standard protocol fields.

@bb-c24 bb-c24 force-pushed the add_meta_to_response branch from 71d55ff to bfe77e3 Compare November 13, 2025 17:10
@chr-hertel chr-hertel merged commit 7a3b473 into modelcontextprotocol:main Nov 13, 2025
10 checks passed
@chr-hertel chr-hertel changed the title Add _meta to CallToolResult [Schema] Add _meta to CallToolResult Nov 13, 2025
@chr-hertel chr-hertel added the Schema Issues & PRs related to the Schema component label Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Schema Issues & PRs related to the Schema component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants