Fix optional argument handling in prompts for Zod V4 (#1199)
Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>
This commit is contained in:
parent
ae0eaf4163
commit
5aaf6ee67e
1 changed files with 48 additions and 3 deletions
|
|
@ -3879,6 +3879,51 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
|
|||
expect(result.resources[0].description).toBe('Overridden description');
|
||||
expect(result.resources[0].mimeType).toBe('text/markdown');
|
||||
});
|
||||
|
||||
test('should support optional prompt arguments', async () => {
|
||||
const mcpServer = new McpServer({
|
||||
name: 'test server',
|
||||
version: '1.0'
|
||||
});
|
||||
|
||||
const client = new Client({
|
||||
name: 'test client',
|
||||
version: '1.0'
|
||||
});
|
||||
|
||||
mcpServer.registerPrompt(
|
||||
'test-prompt',
|
||||
{
|
||||
argsSchema: {
|
||||
name: z.string().optional()
|
||||
}
|
||||
},
|
||||
() => ({
|
||||
messages: []
|
||||
})
|
||||
);
|
||||
|
||||
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
||||
|
||||
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
|
||||
|
||||
const result = await client.request(
|
||||
{
|
||||
method: 'prompts/list'
|
||||
},
|
||||
ListPromptsResultSchema
|
||||
);
|
||||
|
||||
expect(result.prompts).toHaveLength(1);
|
||||
expect(result.prompts[0].name).toBe('test-prompt');
|
||||
expect(result.prompts[0].arguments).toEqual([
|
||||
{
|
||||
name: 'name',
|
||||
description: undefined,
|
||||
required: false
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Tool title precedence', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue