Skip to content

Conversation

@bhosmer-ant
Copy link
Contributor

@bhosmer-ant bhosmer-ant commented May 20, 2025

For compatibility with apps built against SDKs older than 1.11.4, we want to preserve the invariant that CallToolResult.content is always non-optional, even though it will become optional in the next version of the spec when structuredContent is present.

The spec revision states that a compatibility-preserving content field may be returned alongside structuredContent, and McpServer in this SDK already does this automatically. However, in 1.11.4 there are two remaining potential compatibility issues:

  • in SDK 1.11.4, the CallToolResult type defined content as optional when structuredContent was returned, following the new spec. This optionality could cause existing apps that import this type to fail typechecking.
  • since non-McpServer servers following the new spec may not guarantee a compatibility content array, existing apps could fail at runtime when calling structured tools hosted by one of these servers, even when using the Client from SDK 1.11.4.

This PR makes the following changes:

  • ensures that all results returned from Client.callTool() carry a content array, by generating one from structuredContent if none was received.
  • defines a new type CallToolResultWithContent with content as non-optional, and uses this as the return type for Client.callTool(). This should ensure that apps written against pre-1.11.4 versions of the SDK continue to typecheck.

Motivation and Context

Preserve backward compatibility with the users of the old, non-optional CallToolResult.content array.

How Has This Been Tested?

Test added (tool returns structuredContent only, client receives generated content).

Breaking Changes

No - fixes typecheck build break in 1.11.4

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

@bhosmer-ant bhosmer-ant marked this pull request as ready for review May 21, 2025 02:57
@bhosmer-ant bhosmer-ant requested a review from ihrpr May 21, 2025 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants