Skip to content

Commit 9f455cd

Browse files
fix(core): allow additional JSON Schema properties in elicitInput requestedSchema
Adds .catchall(z.unknown()) to requestedSchema, matching the pattern used by inputSchema/outputSchema (SEP-1613). Fixes type incompatibility when using Zod v4's .toJSONSchema() output which includes extra properties like $schema and additionalProperties. Fixes #1362
1 parent 40174d2 commit 9f455cd

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/core': patch
3+
---
4+
5+
Allow additional JSON Schema properties in elicitInput's requestedSchema type by adding .catchall(z.unknown()), matching the pattern used by inputSchema. This fixes type incompatibility when using Zod v4's .toJSONSchema() output which includes extra properties like $schema and additionalProperties.

packages/core/src/types/schemas.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,11 +1855,13 @@ export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.ex
18551855
* A restricted subset of JSON Schema.
18561856
* Only top-level properties are allowed, without nesting.
18571857
*/
1858-
requestedSchema: z.object({
1859-
type: z.literal('object'),
1860-
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1861-
required: z.array(z.string()).optional()
1862-
})
1858+
requestedSchema: z
1859+
.object({
1860+
type: z.literal('object'),
1861+
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1862+
required: z.array(z.string()).optional()
1863+
})
1864+
.catchall(z.unknown())
18631865
});
18641866

18651867
/**

packages/core/test/types.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
CreateMessageRequestSchema,
77
CreateMessageResultSchema,
88
CreateMessageResultWithToolsSchema,
9+
ElicitRequestFormParamsSchema,
910
LATEST_PROTOCOL_VERSION,
1011
PromptMessageSchema,
1112
ResourceLinkSchema,
@@ -983,4 +984,31 @@ describe('Types', () => {
983984
}
984985
});
985986
});
987+
988+
describe('ElicitRequestFormParamsSchema', () => {
989+
test('accepts requestedSchema with extra JSON Schema metadata keys', () => {
990+
// Mirrors what z.toJSONSchema() emits — includes $schema, additionalProperties, etc.
991+
// See https://github.com/modelcontextprotocol/typescript-sdk/issues/1362
992+
const params = {
993+
message: 'Please provide your name',
994+
requestedSchema: {
995+
$schema: 'https://json-schema.org/draft/2020-12/schema',
996+
type: 'object',
997+
properties: {
998+
name: { type: 'string' }
999+
},
1000+
required: ['name'],
1001+
additionalProperties: false
1002+
}
1003+
};
1004+
1005+
const result = ElicitRequestFormParamsSchema.safeParse(params);
1006+
expect(result.success).toBe(true);
1007+
if (result.success) {
1008+
expect(result.data.requestedSchema.type).toBe('object');
1009+
expect(result.data.requestedSchema.$schema).toBe('https://json-schema.org/draft/2020-12/schema');
1010+
expect(result.data.requestedSchema.additionalProperties).toBe(false);
1011+
}
1012+
});
1013+
});
9861014
});

0 commit comments

Comments
 (0)