Skip to content

Conversation

@cetra3
Copy link
Contributor

@cetra3 cetra3 commented Aug 18, 2025

Adjusts the content field to always be present

Motivation and Context

The MCP schema has the content field as mandatory: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/3b3874b4fc010f34ef5b106f044a4867534a9499/schema/2025-06-18/schema.ts#L782

Some of the MCP implementations (I.e, zed editor) assume (& rightly so) that this field is always present.

How Has This Been Tested?

Running tests

Breaking Changes

It is essentially a breaking change on the type CallToolResult

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

@github-actions github-actions bot added T-test Testing related changes T-config Configuration file changes T-core Core library changes labels Aug 18, 2025
@cetra3 cetra3 force-pushed the match_mcp_calltoolresult_schema branch from e7b34e8 to 5102dfd Compare August 18, 2025 04:29
@4t145 4t145 requested a review from Copilot August 18, 2025 06:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modifies the CallToolResult schema to make the content field mandatory and always present, aligning with the MCP (Model Context Protocol) schema specification. The change ensures compatibility with MCP implementations that expect the content field to always exist.

Key changes:

  • Changed content field from Option<Vec<Content>> to Vec<Content> in the CallToolResult struct
  • Updated JSON schema to make content a required field and remove null type
  • Updated all test code to work with the non-optional content field

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
crates/rmcp/src/model.rs Modified CallToolResult struct to make content field mandatory and updated related methods
crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json Updated JSON schema to make content required and remove null type
crates/rmcp/tests/test_tool_macros.rs Updated test code to handle non-optional content field
crates/rmcp/tests/test_structured_output.rs Updated test assertions and content access for mandatory content field

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

(Some(value), _) => return serde_json::from_value(value),
(None, Some(contents)) => {
if let Some(text) = contents.first().and_then(|c| c.as_text()) {
if let Some(text) = contents.as_text() {
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

The pattern match (None, Some(contents)) is unreachable because self.content is now a Vec<Content> (not Option<Vec<Content>>), so it can never be Some(contents). This should be (None, contents) and the condition should check if contents is not empty.

Copilot uses AI. Check for mistakes.
(Some(value), _) => return serde_json::from_value(value),
(None, Some(contents)) => {
if let Some(text) = contents.first().and_then(|c| c.as_text()) {
if let Some(text) = contents.as_text() {
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

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

The variable contents is now of type &Content (from first()) rather than &Vec<Content>, so calling contents.as_text() directly is incorrect. This should be accessing the first content item's text method.

Copilot uses AI. Check for mistakes.
@4t145
Copy link
Collaborator

4t145 commented Aug 18, 2025

fix ci please

@github-actions github-actions bot added the T-examples Example code changes label Aug 19, 2025
BREAKING CHANGE: makes the `content` field non-optional
@cetra3 cetra3 force-pushed the match_mcp_calltoolresult_schema branch from e1f79f2 to 38e42a7 Compare August 19, 2025 03:58
@4t145
Copy link
Collaborator

4t145 commented Aug 19, 2025

thanks

@4t145 4t145 merged commit a47cbaa into modelcontextprotocol:main Aug 19, 2025
11 checks passed
@github-actions github-actions bot mentioned this pull request Aug 19, 2025
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-examples Example code changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants