Skip to content

Commit 444e7aa

Browse files
committed
feat(transport): make session ID optional and improve handling in HttpTransport
1 parent 2880173 commit 444e7aa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Client/Transport/Http/HttpTransport.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function isConnected(): bool
230230
{
231231
// For new protocol, we don't require SSE to be always connected
232232
if ($this->protocolVersion === '2025-03-26') {
233-
return $this->connected && $this->sessionId !== null;
233+
return $this->connected;
234234
}
235235

236236
// For legacy protocol, SSE must be connected
@@ -559,9 +559,9 @@ protected function connectStreamableHttp(): void
559559
$this->sessionId = $this->extractSessionId($initResponse);
560560
$this->stats['session_id'] = $this->sessionId;
561561

562-
// Validate that we got a session ID
562+
// Session ID is optional - if not provided, continue without it
563563
if (! $this->sessionId) {
564-
throw new TransportError('Server did not return a session ID in initialize response');
564+
$this->logger->debug('No session ID returned by server, continuing without session management');
565565
}
566566

567567
// Send initialized notification
@@ -856,7 +856,13 @@ protected function sendLegacyProtocol(JsonRpcMessage $message): void
856856
*/
857857
protected function sendTerminationRequest(): void
858858
{
859-
if (! $this->sessionId || $this->connectionManager === null || $this->authenticator === null) {
859+
if ($this->connectionManager === null || $this->authenticator === null) {
860+
return;
861+
}
862+
863+
// Only send termination request if we have a session ID
864+
if (! $this->sessionId) {
865+
$this->logger->debug('No session ID available, skipping termination request');
860866
return;
861867
}
862868

@@ -890,10 +896,8 @@ protected function ensureConnected(): void
890896
}
891897

892898
// For new protocol, we don't require SSE to be always connected
899+
// Session ID is optional - if not available, continue without session management
893900
if ($this->protocolVersion === '2025-03-26') {
894-
if ($this->sessionId === null) {
895-
throw new TransportError('Session ID is not available');
896-
}
897901
return;
898902
}
899903

0 commit comments

Comments
 (0)