Skip to content

StreamableHTTPServerTransport should support multiple initializations #344

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/server/streamableHttp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,13 @@ describe("StreamableHTTPServerTransport in stateless mode", () => {
await stopTestServer({ server, transport });
});

it("should support multiple initializations in stateless mode", async () => {
await sendPostRequest(baseUrl, TEST_MESSAGES.initialize);
const initResponse = await sendPostRequest(baseUrl, TEST_MESSAGES.initialize);
expect(initResponse.status).toBe(200);
expect(initResponse.headers.get("mcp-session-id")).toBeNull();
});

it("should operate without session ID validation", async () => {
// Initialize the server first
const initResponse = await sendPostRequest(baseUrl, TEST_MESSAGES.initialize);
Expand Down
3 changes: 2 additions & 1 deletion src/server/streamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ export class StreamableHTTPServerTransport implements Transport {
if (isInitializationRequest) {
// If it's a server with session management and the session ID is already set we should reject the request
// to avoid re-initialization.
if (this._initialized) {
// sessionId undefined means stateless mode, so we don't need to check for re-initialization
if (this._initialized && this.sessionId !== undefined) {
res.writeHead(400).end(JSON.stringify({
jsonrpc: "2.0",
error: {
Expand Down