Skip to content

feat: add session management for streamableHttp [MCP-52] #379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 18, 2025
Merged

Conversation

fmenezes
Copy link
Collaborator

@fmenezes fmenezes commented Jul 16, 2025

Proposed changes

add session management for streamableHttp

Checklist

@fmenezes fmenezes marked this pull request as ready for review July 16, 2025 17:40
@fmenezes fmenezes requested a review from a team as a code owner July 16, 2025 17:40
Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

import logger, { LogId } from "./logger.js";

export class SessionStore {
private sessions: { [sessionId: string]: StreamableHTTPServerTransport | undefined } = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] Is there a reason why they value is nullable?
I don't see any location where the value (StreamableHTTPServerTransport) is set to undefined/removed

Copy link
Collaborator Author

@fmenezes fmenezes Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the case where a key is not found

app.use(express.json());

const handleRequest = async (req: express.Request, res: express.Response) => {
const sessionId = req.headers["mcp-session-id"] as string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the better way to write this be:

const sessionId = req.headers["mcp-session-id"];
if (typeof sessionId !== 'string' || !sessionId) {

Or at least use as string | undefined, instead of as string, which is incorrect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I had an issue on my IDE before I think

const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined,
});
const sessionId = req.headers["mcp-session-id"] as string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous remark

@fmenezes fmenezes merged commit ac40e8a into MCP-42 Jul 18, 2025
7 of 8 checks passed
@fmenezes fmenezes deleted the MCP-52 branch July 18, 2025 15:55
@fmenezes fmenezes mentioned this pull request Jul 21, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants