Skip to content

Commit 606704b

Browse files
author
Pascual Munoz Galian
committed
fix: mark client initialized after initialize handshake
Many real-world MCP clients (Claude Code, Gemini/Antigravity) complete the initialize handshake and immediately call tools/list or tools/call without sending the notifications/initialized notification. Currently, initialized is only set to true in handleNotificationInitialized(), so these clients get permanently locked out with "Client session not initialized" errors. This change marks the session as initialized right after a successful initialize response. If a client still sends notifications/initialized, handleNotificationInitialized() sets the flag again — a harmless no-op. Discovered while running a production MCP server (Cohete blog) that serves Claude Code and other MCP clients over SSE transport.
1 parent d2c5833 commit 606704b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Dispatcher.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ public function handleInitialize(InitializeRequest $request, SessionInterface $s
128128
$session->set('client_info', $request->clientInfo->toArray());
129129
$session->set('protocol_version', $protocolVersion);
130130

131+
// Mark client as initialized immediately after successful handshake.
132+
// Many real-world MCP clients (Claude Code, Gemini) skip
133+
// the notifications/initialized step, causing "Client session not
134+
// initialized" errors on all subsequent requests.
135+
$session->set('initialized', true);
136+
131137
$serverInfo = $this->configuration->serverInfo;
132138
$capabilities = $this->configuration->capabilities;
133139
$instructions = $this->configuration->instructions;

0 commit comments

Comments
 (0)