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>
This commit is contained in:
parent
e4227d135c
commit
1823aae891
4 changed files with 69131 additions and 9001 deletions
5
examples/stateless-legacy/README.md
Normal file
5
examples/stateless-legacy/README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# stateless-legacy
|
||||
|
||||
The minimal `createMcpHandler` deployment, on its default posture: 2026-07-28 traffic served per request, 2025-era traffic served stateless from the same factory. This is the one-liner replacement for the 1.x "new transport + new server per POST" stateless idiom.
|
||||
|
||||
**HTTP-only** by definition; see `dual-era/` for the stdio analogue.
|
||||
25
examples/stateless-legacy/client.ts
Normal file
25
examples/stateless-legacy/client.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Connects to the minimal `createMcpHandler` deployment as both a plain 2025
|
||||
* client (`versionNegotiation: { mode: 'legacy' }` — the `initialize`
|
||||
* handshake, served stateless from the factory) and a 2026-capable client
|
||||
* (`versionNegotiation: { mode: 'auto' }`, served per request). Asserts the
|
||||
* same `greet` tool answers identically either way.
|
||||
*
|
||||
* HTTP-only — `createMcpHandler`'s `legacy: 'stateless'` posture is an HTTP
|
||||
* hosting concern; a stdio leg would bypass it. The story body drives BOTH
|
||||
* eras itself, so only `url` is read from argv.
|
||||
*/
|
||||
import { check, parseExampleArgs } from '@mcp-examples/shared';
|
||||
import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
|
||||
|
||||
const { url } = parseExampleArgs();
|
||||
|
||||
for (const mode of ['legacy', 'auto'] as const) {
|
||||
const client = new Client({ name: 'stateless-legacy-client', version: '1.0.0' }, { versionNegotiation: { mode } });
|
||||
await client.connect(new StreamableHTTPClientTransport(new URL(url)));
|
||||
const tools = await client.listTools();
|
||||
check.ok(tools.tools.some(t => t.name === 'greet'));
|
||||
const result = await client.callTool({ name: 'greet', arguments: { name: 'world' } });
|
||||
check.equal(result.content?.[0]?.type === 'text' ? result.content[0].text : '', 'Hello, world!');
|
||||
await client.close();
|
||||
}
|
||||
26
examples/stateless-legacy/package.json
Normal file
26
examples/stateless-legacy/package.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "@mcp-examples/stateless-legacy",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"server": "tsx server.ts",
|
||||
"client": "tsx client.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mcp-examples/shared": "workspace:*",
|
||||
"@modelcontextprotocol/client": "workspace:*",
|
||||
"@modelcontextprotocol/node": "workspace:*",
|
||||
"@modelcontextprotocol/server": "workspace:*",
|
||||
"zod": "catalog:runtimeShared"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "catalog:devTools"
|
||||
},
|
||||
"example": {
|
||||
"transports": [
|
||||
"http"
|
||||
],
|
||||
"era": "modern",
|
||||
"//": "The story body manages its own era internally; pinned so the runner runs it once per transport."
|
||||
}
|
||||
}
|
||||
36
examples/stateless-legacy/server.ts
Normal file
36
examples/stateless-legacy/server.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* The minimal `createMcpHandler` deployment, on its default posture.
|
||||
*
|
||||
* One factory, one endpoint: 2026-07-28 traffic is served per request, and
|
||||
* 2025-era (non-envelope) traffic is served stateless from the same factory
|
||||
* (`legacy: 'stateless'`, the default). This replaces the hand-wired
|
||||
* "new transport + new server per POST" stateless idiom of the 1.x SDK with
|
||||
* a one-liner.
|
||||
*
|
||||
* HTTP-only — `createMcpHandler`'s `legacy: 'stateless'` posture is an HTTP
|
||||
* hosting concern; a stdio leg would bypass it. See `dual-era/` for the stdio
|
||||
* analogue.
|
||||
*/
|
||||
import { createServer } from 'node:http';
|
||||
|
||||
import { parseExampleArgs } from '@mcp-examples/shared';
|
||||
import { toNodeHandler } from '@modelcontextprotocol/node';
|
||||
import { createMcpHandler, McpServer } from '@modelcontextprotocol/server';
|
||||
import * as z from 'zod/v4';
|
||||
|
||||
function buildServer(): McpServer {
|
||||
const server = new McpServer({ name: 'stateless-legacy-example', version: '1.0.0' }, { capabilities: { logging: {} } });
|
||||
server.registerTool(
|
||||
'greet',
|
||||
{ description: 'A simple greeting tool', inputSchema: z.object({ name: z.string() }) },
|
||||
async ({ name }) => ({ content: [{ type: 'text', text: `Hello, ${name}!` }] })
|
||||
);
|
||||
return server;
|
||||
}
|
||||
|
||||
const { port } = parseExampleArgs();
|
||||
|
||||
const handler = createMcpHandler(buildServer);
|
||||
createServer(toNodeHandler(handler)).listen(port, () => {
|
||||
console.error(`[server] listening on http://127.0.0.1:${port}/mcp`);
|
||||
});
|
||||
Loading…
Reference in a new issue