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
This commit is contained in:
cliffhall 2025-06-16 16:34:46 -04:00
commit 5a8af45c09

View file

@ -178,10 +178,10 @@ const getServer = () => {
server.registerResource(
'example-file-1',
'file:///example/file1.txt',
{
{
title: 'Example File 1',
description: 'First example file for ResourceLink demonstration',
mimeType: 'text/plain'
mimeType: 'text/plain'
},
async (): Promise<ReadResourceResult> => {
return {
@ -198,10 +198,10 @@ const getServer = () => {
server.registerResource(
'example-file-2',
'file:///example/file2.txt',
{
{
title: 'Example File 2',
description: 'Second example file for ResourceLink demonstration',
mimeType: 'text/plain'
mimeType: 'text/plain'
},
async (): Promise<ReadResourceResult> => {
return {
@ -338,15 +338,13 @@ const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};
// MCP POST endpoint with optional auth
const mcpPostHandler = async (req: Request, res: Response) => {
console.log('Received MCP request:', req.body);
const sessionId = req.headers['mcp-session-id'] as string | undefined;
console.log(sessionId? `Received MCP request for session: ${sessionId}`: 'Received MCP request:', req.body);
if (useOAuth && req.auth) {
console.log('Authenticated user:', req.auth);
}
try {
// Check for existing session ID
const sessionId = req.headers['mcp-session-id'] as string | undefined;
let transport: StreamableHTTPServerTransport;
if (sessionId && transports[sessionId]) {
// Reuse existing transport
transport = transports[sessionId];