typescript-sdk/examples/legacy-routing/client.ts
Felix Weinberger 1823aae891
Implement MCP 2026-07-28 (#2286)
Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com>
Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-06-26 14:01:10 +01:00

24 lines
1.3 KiB
TypeScript

/**
* Connects to the routing fork as both a plain 2025 client (lands on the
* existing sessionful transport, `era=legacy`) and a 2026-capable client
* (lands on the strict modern entry, `era=modern`).
*/
import { check, parseExampleArgs } from '@mcp-examples/shared';
import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
const { url } = parseExampleArgs();
// 2025 client → routed to the existing sessionful deployment.
const legacy = new Client({ name: 'legacy-routing-client', version: '1.0.0' });
await legacy.connect(new StreamableHTTPClientTransport(new URL(url)));
const lr = await legacy.callTool({ name: 'greet', arguments: { name: 'A' } });
check.match(lr.content?.[0]?.type === 'text' ? lr.content[0].text : '', /era=legacy/);
await legacy.close();
// 2026 client → routed to the strict modern entry.
const modern = new Client({ name: 'legacy-routing-client', version: '1.0.0' }, { versionNegotiation: { mode: 'auto' } });
await modern.connect(new StreamableHTTPClientTransport(new URL(url)));
check.equal(modern.getNegotiatedProtocolVersion(), '2026-07-28');
const mr = await modern.callTool({ name: 'greet', arguments: { name: 'B' } });
check.match(mr.content?.[0]?.type === 'text' ? mr.content[0].text : '', /era=modern/);
await modern.close();