Skip to content
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