Skip to content

feat(rmcp): add optional _meta to CallToolResult, EmbeddedResource, and ResourceContents - #386

Merged
alexhancock merged 2 commits into
modelcontextprotocol:mainfrom
aharvard:fix/add-meta-field-to-call-tool-result
Sep 2, 2025
Merged

feat(rmcp): add optional _meta to CallToolResult, EmbeddedResource, and ResourceContents#386
alexhancock merged 2 commits into
modelcontextprotocol:mainfrom
aharvard:fix/add-meta-field-to-call-tool-result

Conversation

@aharvard

@aharvardaharvard commented Aug 22, 2025

Copy link
Copy Markdown
Contributor

Summary

Support the optional _meta field across core MCP results and resources so protocol-level metadata can be exchanged and properly serialized/deserialized per the MCP spec.

Problem

The MCP spec allows an optional _meta field on results and certain content forms. The Rust SDK only partially supported this, limiting interoperability (e.g., clients expecting _meta could not round-trip metadata).

Changes

  • CallToolResult
    • Add optional _meta (serde rename to "_meta", skip when None)
    • Custom deserializer accepts incoming "_meta"
  • EmbeddedResource
    • RawEmbeddedResource now supports optional _meta (serde rename to "_meta")
  • ResourceContents
    • TextResourceContents and BlobResourceContents now support optional _meta (serde rename to "_meta")
  • Meta
    • Derive PartialEq and schemars::JsonSchema for testing and schema generation
  • Schemas
    • Update JSON schema snapshots to reflect the new optional fields

Tests

  • Added
    • crates/rmcp/tests/test_tool_result_meta.rs: serialize/deserialize CallToolResult with and without _meta
    • crates/rmcp/tests/test_embedded_resource_meta.rs: serialize/deserialize EmbeddedResource and inner Text/Blob contents with and without _meta
  • Updated
    • tests/test_message_schema/client_json_rpc_message_schema.json
    • tests/test_message_schema/server_json_rpc_message_schema.json

Backward compatibility

No breaking changes: all new fields are optional and omitted when None.

Examples

CallToolResult:

{
"content": [{"type":"text","text":"ok"}],
"_meta": {"foo":"bar"}
}

EmbeddedResource with Text contents:

{
"type": "resource",
"_meta": {"top": 1},
"resource": {
"uri": "str://example",
"mimeType": "text/plain",
"text": "hello",
"_meta": {"inner": 2}
}
}

Notes

  • Removed references to success_with_meta() / error_with_meta() helpers (not included).
  • Python integration tests may fail locally; unit and schema tests pass.

@github-actionsgithub-actionsBot added T-test Testing related changes T-config Configuration file changes T-core Core library changes T-model Model/data structure changes labels Aug 22, 2025

@KvadratniKvadratni left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aharvard
aharvard marked this pull request as draft August 22, 2025 20:44
@aharvard

Copy link
Copy Markdown
ContributorAuthor

i need to clean up the test fixtures. not quite ready for final review.

@aharvard
aharvardforce-pushed the fix/add-meta-field-to-call-tool-result branch from e327541 to 6cd9273CompareAugust 22, 2025 20:49
@github-actionsgithub-actionsBot added T-documentation Documentation improvements T-dependencies Dependencies related changes T-CI Changes to CI/CD workflows and configuration T-examples Example code changes T-handler Handler implementation changes T-macros Macro changes T-service Service layer changes T-transport Transport layer changes labels Aug 22, 2025
@aharvard
aharvardforce-pushed the fix/add-meta-field-to-call-tool-result branch from 6cd9273 to 4c88e25CompareSeptember 2, 2025 16:52
@github-actionsgithub-actionsBot removed T-documentation Documentation improvements T-dependencies Dependencies related changes T-CI Changes to CI/CD workflows and configuration T-examples Example code changes T-handler Handler implementation changes T-macros Macro changes T-service Service layer changes T-transport Transport layer changes labels Sep 2, 2025
…ntents
- Add optional _meta to RawEmbeddedResource and ResourceContents (text/blob)
- Update constructors/usages to set meta: None by default
- Add tests to lock behavior (embedded text/blob + CallToolResult)
- Update JSON Schemas to include optional _meta fields
@aharvard
aharvardforce-pushed the fix/add-meta-field-to-call-tool-result branch from 4c88e25 to d9d26baCompareSeptember 2, 2025 16:54
@aharvardaharvard changed the title fix: add required _meta field to CallToolResult structfeat(rmcp): add optional _meta to CallToolResult, EmbeddedResource, and ResourceContentsSep 2, 2025
@aharvard
aharvard marked this pull request as ready for review September 2, 2025 17:08

@KvadratniKvadratni left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@alexhancock
alexhancock self-requested a review September 2, 2025 17:44

@alexhancockalexhancock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow up to make sure we're not missing it on any other required types but this LGTM for these types!

@alexhancock
alexhancock merged commit 7d46b39 into modelcontextprotocol:mainSep 2, 2025
11 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Sep 2, 2025
@aharvard

Copy link
Copy Markdown
ContributorAuthor

Let's follow up to make sure we're not missing it on any other required types but this LGTM for these types!

sounds good, doing an analysis now

takumi-earth pushed a commit to earthlings-dev/rmcp that referenced this pull request Jan 27, 2026
…nd ResourceContents (modelcontextprotocol#386)
* feat(rmcp): support optional _meta on EmbeddedResource and ResourceContents
- Add optional _meta to RawEmbeddedResource and ResourceContents (text/blob)
- Update constructors/usages to set meta: None by default
- Add tests to lock behavior (embedded text/blob + CallToolResult)
- Update JSON Schemas to include optional _meta fields
* style(rmcp): rustfmt after _meta changes and tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-configConfiguration file changesT-coreCore library changesT-modelModel/data structure changesT-testTesting related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@aharvard@alexhancock@Kvadratni