From 547600ca51e0d1e06ddf79e41e2a43c74b0adc4c Mon Sep 17 00:00:00 2001 From: Andre Schade Date: Thu, 19 Nov 2026 22:24:51 +0100 Subject: [PATCH] [Server] Include the request id in the error for an initialize request with a session ID Co-Authored-By: Claude Opus 5.5 --- src/Server/Protocol.php | 2 +- tests/Unit/Server/ProtocolTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Server/Protocol.php b/src/Server/Protocol.php index 90c40e81..0f75a3b7 100644 --- a/src/Server/Protocol.php +++ b/src/Server/Protocol.php @@ -1214,7 +1214,7 @@ private function resolveSession(TransportInterface $transport, ?Uuid $sessionId, if ($message instanceof InitializeRequest) { // Spec: An initialize request must not have a session ID. if ($sessionId) { - $error = Error::forInvalidRequest('A session ID MUST NOT be sent with an "initialize" request.'); + $error = Error::forInvalidRequest('A session ID MUST NOT be sent with an "initialize" request.', self::findRequestId($message)); $this->sendResponse($transport, $error, null, ['status_code' => 400]); return null; diff --git a/tests/Unit/Server/ProtocolTest.php b/tests/Unit/Server/ProtocolTest.php index 292d9acc..f2f92814 100644 --- a/tests/Unit/Server/ProtocolTest.php +++ b/tests/Unit/Server/ProtocolTest.php @@ -259,6 +259,7 @@ public function testInitializeRequestWithSessionIdReturnsError(): void $decoded = json_decode($data, true); return isset($decoded['error']) + && 1 === ($decoded['id'] ?? null) && str_contains($decoded['error']['message'], 'session ID MUST NOT be sent'); }), $this->anything()