fix(core): allow additional JSON Schema properties in elicitInput requestedSchema (#1768)
Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
This commit is contained in:
parent
0021561942
commit
866c08d364
2 changed files with 40 additions and 5 deletions
|
|
@ -1861,11 +1861,13 @@ export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.ex
|
|||
* A restricted subset of JSON Schema.
|
||||
* Only top-level properties are allowed, without nesting.
|
||||
*/
|
||||
requestedSchema: z.object({
|
||||
type: z.literal('object'),
|
||||
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
|
||||
required: z.array(z.string()).optional()
|
||||
})
|
||||
requestedSchema: z
|
||||
.object({
|
||||
type: z.literal('object'),
|
||||
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
|
||||
required: z.array(z.string()).optional()
|
||||
})
|
||||
.catchall(z.unknown())
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
CreateMessageRequestSchema,
|
||||
CreateMessageResultSchema,
|
||||
CreateMessageResultWithToolsSchema,
|
||||
ElicitRequestFormParamsSchema,
|
||||
LATEST_PROTOCOL_VERSION,
|
||||
PromptMessageSchema,
|
||||
ResourceLinkSchema,
|
||||
|
|
@ -983,4 +984,31 @@ describe('Types', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('ElicitRequestFormParamsSchema', () => {
|
||||
test('accepts requestedSchema with extra JSON Schema metadata keys', () => {
|
||||
// Mirrors what z.toJSONSchema() emits — includes $schema, additionalProperties, etc.
|
||||
// See https://github.com/modelcontextprotocol/typescript-sdk/issues/1362
|
||||
const params = {
|
||||
message: 'Please provide your name',
|
||||
requestedSchema: {
|
||||
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string' }
|
||||
},
|
||||
required: ['name'],
|
||||
additionalProperties: false
|
||||
}
|
||||
};
|
||||
|
||||
const result = ElicitRequestFormParamsSchema.safeParse(params);
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.requestedSchema.type).toBe('object');
|
||||
expect(result.data.requestedSchema.$schema).toBe('https://json-schema.org/draft/2020-12/schema');
|
||||
expect(result.data.requestedSchema.additionalProperties).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue