Skip to content

Commit c168bb6

Browse files
authored
Merge pull request #42 from Wolfgang-check24/fix-version-negatiation-issue
fixes Protocol version negotiation incorrect #41
2 parents 759c309 + 955c094 commit c168bb6

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

src/Server/MCPServer.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,8 @@ private function getValidatedProtocolVersion(string $requestedVersion): string
240240
return $requestedVersion;
241241
}
242242

243-
// Throw error for unsupported protocol version
244-
throw new JsonRpcErrorException(
245-
message: 'Unsupported protocol version',
246-
code: JsonRpcErrorCode::INVALID_PARAMS,
247-
data: [
248-
'supported' => $supportedVersions,
249-
'requested' => $requestedVersion,
250-
]
251-
);
243+
//return latest version
244+
return MCPProtocolInterface::PROTOCOL_VERSION_STREAMABE_HTTP;
252245
}
253246

254247
/**

tests/Server/MCPServerTest.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -558,21 +558,12 @@ public function test_initialize_throws_exception_for_unsupported_protocol_versio
558558
$unsupportedVersion = '2025-12-01';
559559
$initializeData = new InitializeData('2.0', ['mock-capability' => true], $unsupportedVersion);
560560

561-
// Act & Assert
562-
try {
563-
$server->initialize($initializeData);
564-
$this->fail('Expected JsonRpcErrorException not thrown');
565-
} catch (JsonRpcErrorException $e) {
566-
$this->assertEquals(-32602, $e->getJsonRpcErrorCode());
567-
$this->assertEquals('Unsupported protocol version', $e->getMessage());
568-
569-
$errorData = $e->getErrorData();
570-
$this->assertIsArray($errorData);
571-
$this->assertArrayHasKey('supported', $errorData);
572-
$this->assertArrayHasKey('requested', $errorData);
573-
$this->assertEquals($unsupportedVersion, $errorData['requested']);
574-
$this->assertContains(MCPProtocolInterface::PROTOCOL_VERSION_SSE, $errorData['supported']);
575-
$this->assertContains(MCPProtocolInterface::PROTOCOL_VERSION_STREAMABE_HTTP, $errorData['supported']);
576-
}
561+
// Act
562+
$initializeResource = $server->initialize($initializeData);
563+
564+
// Assert
565+
$this->assertInstanceOf(InitializeResource::class, $initializeResource);
566+
$this->assertEquals(MCPProtocolInterface::PROTOCOL_VERSION_STREAMABE_HTTP, $initializeResource->protocolVersion);
567+
$this->assertEquals($serverInfo, $initializeResource->serverInfo);
577568
}
578569
}

0 commit comments

Comments
 (0)