fill in compatible CallToolResult.content field on client side #523
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For compatibility with apps built against SDKs older than 1.11.4, we want to preserve the invariant that
CallToolResult.contentis always non-optional, even though it will become optional in the next version of the spec whenstructuredContentis present.The spec revision states that a compatibility-preserving
contentfield may be returned alongsidestructuredContent, andMcpServerin this SDK already does this automatically. However, in 1.11.4 there are two remaining potential compatibility issues:CallToolResulttype definedcontentas optional whenstructuredContentwas returned, following the new spec. This optionality could cause existing apps that import this type to fail typechecking.McpServerservers following the new spec may not guarantee a compatibilitycontentarray, existing apps could fail at runtime when calling structured tools hosted by one of these servers, even when using theClientfrom SDK 1.11.4.This PR makes the following changes:
Client.callTool()carry acontentarray, by generating one fromstructuredContentif none was received.CallToolResultWithContentwithcontentas non-optional, and uses this as the return type forClient.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.contentarray.How Has This Been Tested?
Test added (tool returns
structuredContentonly, client receives generatedcontent).Breaking Changes
No - fixes typecheck build break in 1.11.4
Types of changes
Checklist
Additional context