Skip to content

Commit 102f4a1

Browse files
docs: add FixSpec wrapper for CreateMessageResult schema divergence
Document the intentional divergence between SDK's CreateMessageResult (single content for v1.x backwards compat) and the spec's version (array content per SEP-1577). The full array-capable type is available as CreateMessageResultWithTools. This will be aligned with schema in v2.0.
1 parent 5eb6d54 commit 102f4a1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/examples/server/toolWithSampleServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mcpServer.registerTool(
3333
maxTokens: 500
3434
});
3535

36-
// Since we're not using tools, response.content is guaranteed to be single content
36+
// Since we're not passing tools param to createMessage, response.content is single content
3737
return {
3838
content: [
3939
{

src/spec.types.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ type FixSpecInitializeRequest<T> = T extends { params: infer P } ? Omit<T, 'para
8080

8181
type FixSpecClientRequest<T> = T extends { params: infer P } ? Omit<T, 'params'> & { params: FixSpecInitializeRequestParams<P> } : T;
8282

83+
// Targeted fix: CreateMessageResult in SDK uses single content for v1.x backwards compat.
84+
// The full array-capable type is CreateMessageResultWithTools.
85+
// This will be aligned with schema in v2.0.
86+
// Narrows content from SamplingMessageContentBlock (includes tool types) to basic content types only.
87+
type NarrowToBasicContent<C> = C extends { type: 'text' | 'image' | 'audio' } ? C : never;
88+
type FixSpecCreateMessageResult<T> = T extends { content: infer C; role: infer R; model: infer M }
89+
? {
90+
_meta?: { [key: string]: unknown };
91+
model: M;
92+
role: R;
93+
stopReason?: string;
94+
content: C extends (infer U)[] ? NarrowToBasicContent<U> : NarrowToBasicContent<C>;
95+
}
96+
: T;
97+
8398
const sdkTypeChecks = {
8499
RequestParams: (sdk: RemovePassthrough<SDKTypes.RequestParams>, spec: SpecTypes.RequestParams) => {
85100
sdk = spec;
@@ -369,7 +384,10 @@ const sdkTypeChecks = {
369384
sdk = spec;
370385
spec = sdk;
371386
},
372-
CreateMessageResult: (sdk: RemovePassthrough<SDKTypes.CreateMessageResult>, spec: SpecTypes.CreateMessageResult) => {
387+
CreateMessageResult: (
388+
sdk: RemovePassthrough<SDKTypes.CreateMessageResult>,
389+
spec: FixSpecCreateMessageResult<SpecTypes.CreateMessageResult>
390+
) => {
373391
sdk = spec;
374392
spec = sdk;
375393
},

0 commit comments

Comments
 (0)