Skip to content

Commit 866c08d

Browse files
fix(core): allow additional JSON Schema properties in elicitInput requestedSchema (#1768)
Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
1 parent 0021561 commit 866c08d

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed
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
@@ -1861,11 +1861,13 @@ export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.ex
18611861
* A restricted subset of JSON Schema.
18621862
* Only top-level properties are allowed, without nesting.
18631863
*/
1864-
requestedSchema: z.object({
1865-
type: z.literal('object'),
1866-
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1867-
required: z.array(z.string()).optional()
1868-
})
1864+
requestedSchema: z
1865+
.object({
1866+
type: z.literal('object'),
1867+
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
1868+
required: z.array(z.string()).optional()
1869+
})
1870+
.catchall(z.unknown())
18691871
});
18701872

18711873
/**

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)