|
| 1 | +/** |
| 2 | + * Regression test for https://github.com/modelcontextprotocol/typescript-sdk/issues/1277 |
| 3 | + * |
| 4 | + * Zod v4 stores `.describe()` descriptions directly on the schema object, |
| 5 | + * not in `._zod.def.description`. This test verifies that descriptions are |
| 6 | + * correctly extracted for prompt arguments. |
| 7 | + */ |
| 8 | + |
| 9 | +import { Client } from '../../src/client/index.js'; |
| 10 | +import { InMemoryTransport } from '../../src/inMemory.js'; |
| 11 | +import { ListPromptsResultSchema } from '../../src/types.js'; |
| 12 | +import { McpServer } from '../../src/server/mcp.js'; |
| 13 | +import { zodTestMatrix, type ZodMatrixEntry } from '../../src/__fixtures__/zodTestMatrix.js'; |
| 14 | + |
| 15 | +describe.each(zodTestMatrix)('Issue #1277: $zodVersionLabel', (entry: ZodMatrixEntry) => { |
| 16 | + const { z } = entry; |
| 17 | + |
| 18 | + test('should preserve argument descriptions from .describe()', async () => { |
| 19 | + const mcpServer = new McpServer({ |
| 20 | + name: 'test server', |
| 21 | + version: '1.0' |
| 22 | + }); |
| 23 | + const client = new Client({ |
| 24 | + name: 'test client', |
| 25 | + version: '1.0' |
| 26 | + }); |
| 27 | + |
| 28 | + mcpServer.prompt( |
| 29 | + 'test', |
| 30 | + { |
| 31 | + name: z.string().describe('The user name'), |
| 32 | + value: z.string().describe('The value to set') |
| 33 | + }, |
| 34 | + async ({ name, value }) => ({ |
| 35 | + messages: [ |
| 36 | + { |
| 37 | + role: 'assistant', |
| 38 | + content: { |
| 39 | + type: 'text', |
| 40 | + text: `${name}: ${value}` |
| 41 | + } |
| 42 | + } |
| 43 | + ] |
| 44 | + }) |
| 45 | + ); |
| 46 | + |
| 47 | + const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); |
| 48 | + |
| 49 | + await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]); |
| 50 | + |
| 51 | + const result = await client.request( |
| 52 | + { |
| 53 | + method: 'prompts/list' |
| 54 | + }, |
| 55 | + ListPromptsResultSchema |
| 56 | + ); |
| 57 | + |
| 58 | + expect(result.prompts).toHaveLength(1); |
| 59 | + expect(result.prompts[0].name).toBe('test'); |
| 60 | + expect(result.prompts[0].arguments).toEqual([ |
| 61 | + { name: 'name', required: true, description: 'The user name' }, |
| 62 | + { name: 'value', required: true, description: 'The value to set' } |
| 63 | + ]); |
| 64 | + }); |
| 65 | +}); |
0 commit comments