Skip to content

Commit 22196ca

Browse files
authored
fix: bump SDK to 1.26.0, add session management to tools_call scenario (#134)
* fix: bump SDK to 1.26.0, add session management to tools_call scenario SDK 1.26.0 made Protocol.connect() throw if already connected to a transport. The tools_call scenario was calling server.connect(transport) on every request with the same Server instance, which now throws. Fixed by adding proper session management: each initialize request creates a new Server + Transport pair, and subsequent requests are routed to the correct transport via the mcp-session-id header. * fix: return 404 for invalid session IDs in tools_call POST handler The else branch was returning 400 for both missing-session and invalid/stale-session cases. The MCP spec requires 404 for invalid session IDs and 400 only for non-initialization requests without any session ID. * refactor: keep tools_call stateless, create fresh server per request Instead of adding session management, simply create a new Server instance per request. This preserves the original stateless design while fixing the SDK 1.26.0 Protocol.connect() restriction.
1 parent 189a31d commit 22196ca

3 files changed

Lines changed: 46 additions & 26 deletions

File tree

package-lock.json

Lines changed: 37 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"vitest": "^4.0.16"
4646
},
4747
"dependencies": {
48-
"@modelcontextprotocol/sdk": "^1.25.2",
48+
"@modelcontextprotocol/sdk": "^1.26.0",
4949
"commander": "^14.0.2",
5050
"eventsource-parser": "^3.0.6",
5151
"express": "^5.1.0",

src/scenarios/client/tools_call.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import express, { Request, Response } from 'express';
99
import { ScenarioUrls } from '../../types';
1010
import { createRequestLogger } from '../request-logger';
1111

12-
function createServer(checks: ConformanceCheck[]): express.Application {
12+
function createMcpServer(checks: ConformanceCheck[]): Server {
1313
const server = new Server(
1414
{
1515
name: 'add-numbers-server',
@@ -84,6 +84,10 @@ function createServer(checks: ConformanceCheck[]): express.Application {
8484
throw new Error(`Unknown tool: ${request.params.name}`);
8585
});
8686

87+
return server;
88+
}
89+
90+
function createServerApp(checks: ConformanceCheck[]): express.Application {
8791
const app = express();
8892
app.use(express.json());
8993

@@ -96,6 +100,8 @@ function createServer(checks: ConformanceCheck[]): express.Application {
96100
);
97101

98102
app.post('/mcp', async (req: Request, res: Response) => {
103+
// Stateless: create a fresh server and transport per request
104+
const server = createMcpServer(checks);
99105
const transport = new StreamableHTTPServerTransport({
100106
sessionIdGenerator: undefined
101107
});
@@ -116,7 +122,7 @@ export class ToolsCallScenario implements Scenario {
116122

117123
async start(): Promise<ScenarioUrls> {
118124
this.checks = [];
119-
this.app = createServer(this.checks);
125+
this.app = createServerApp(this.checks);
120126
this.httpServer = this.app.listen(0);
121127
const port = this.httpServer.address().port;
122128
return { serverUrl: `http://localhost:${port}/mcp` };

0 commit comments

Comments
 (0)