Skip to content

Conversation

@aharvard
Copy link
Contributor

@aharvard aharvard commented Aug 22, 2025

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-actions github-actions bot 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
Copy link

@Kvadratni Kvadratni left a comment

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
Contributor Author

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

@aharvard aharvard force-pushed the fix/add-meta-field-to-call-tool-result branch from e327541 to 6cd9273 Compare August 22, 2025 20:49
@github-actions github-actions bot 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 aharvard force-pushed the fix/add-meta-field-to-call-tool-result branch from 6cd9273 to 4c88e25 Compare September 2, 2025 16:52
@github-actions github-actions bot 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 aharvard force-pushed the fix/add-meta-field-to-call-tool-result branch from 4c88e25 to d9d26ba Compare September 2, 2025 16:54
@aharvard aharvard changed the title fix: add required _meta field to CallToolResult struct feat(rmcp): add optional _meta to CallToolResult, EmbeddedResource, and ResourceContents Sep 2, 2025
@aharvard aharvard marked this pull request as ready for review September 2, 2025 17:08
@aharvard aharvard requested a review from Kvadratni September 2, 2025 17:08
Copy link

@Kvadratni Kvadratni left a comment

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
Copy link
Collaborator

@alexhancock alexhancock left a comment

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:main Sep 2, 2025
11 checks passed
@github-actions github-actions bot mentioned this pull request Sep 2, 2025
@aharvard
Copy link
Contributor Author

aharvard commented Sep 2, 2025

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 free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-model Model/data structure changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants