Skip to content

Commit 5a8af45

Browse files
committed
In src/examples/server/simpleStreamableHttp.ts
- In mcpPostHandler, - Get `mcp-session-id` header early so that it can be reported in every incoming request. - Helpful for troubleshooting Inspector's ability to retain the session id for the Proxy <-> Server leg
1 parent e89137f commit 5a8af45

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/examples/server/simpleStreamableHttp.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ const getServer = () => {
178178
server.registerResource(
179179
'example-file-1',
180180
'file:///example/file1.txt',
181-
{
181+
{
182182
title: 'Example File 1',
183183
description: 'First example file for ResourceLink demonstration',
184-
mimeType: 'text/plain'
184+
mimeType: 'text/plain'
185185
},
186186
async (): Promise<ReadResourceResult> => {
187187
return {
@@ -198,10 +198,10 @@ const getServer = () => {
198198
server.registerResource(
199199
'example-file-2',
200200
'file:///example/file2.txt',
201-
{
201+
{
202202
title: 'Example File 2',
203203
description: 'Second example file for ResourceLink demonstration',
204-
mimeType: 'text/plain'
204+
mimeType: 'text/plain'
205205
},
206206
async (): Promise<ReadResourceResult> => {
207207
return {
@@ -338,15 +338,13 @@ const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};
338338

339339
// MCP POST endpoint with optional auth
340340
const mcpPostHandler = async (req: Request, res: Response) => {
341-
console.log('Received MCP request:', req.body);
341+
const sessionId = req.headers['mcp-session-id'] as string | undefined;
342+
console.log(sessionId? `Received MCP request for session: ${sessionId}`: 'Received MCP request:', req.body);
342343
if (useOAuth && req.auth) {
343344
console.log('Authenticated user:', req.auth);
344345
}
345346
try {
346-
// Check for existing session ID
347-
const sessionId = req.headers['mcp-session-id'] as string | undefined;
348347
let transport: StreamableHTTPServerTransport;
349-
350348
if (sessionId && transports[sessionId]) {
351349
// Reuse existing transport
352350
transport = transports[sessionId];

0 commit comments

Comments
 (0)