-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Our MCP server does not implement Server-Sent Events (SSE). When using McpToolRegistryProvider.fromTransport with a StreamableHttpClientTransport, the application crashes with an SSEClientException. The response body contains:
RESPONSE: 405 Method Not Allowed
Problem Description
The crash occurs because the transport implementation calls startSseSession, which does not handle the case where SSE is unsupported. Instead of detecting and failing gracefully, the SDK throws an unhandled SSEClientException.
The root issue appears to be in the Ktor SSE implementation. Specifically, the HttpClient.sseSession method maps all exceptions (except cancellations) to SSEClientException, which causes the try/catch block in StreamableHttpClientTransport to be ineffective if it only handles ClientRequestException.
Steps to Reproduce
1. Use an MCP server that does not support SSE.
2. Provide a HttpClient using the CIO or OkHttp engine with the SSE plugin installed.
3. Initialize the registry:
val mcpToolRegistry = McpToolRegistryProvider.fromTransport( transport = MyStreamableHttpClientTransport( client = HttpClient { install(SSE) }, url = "https://your-mcp-url", reconnectionTime = 500.milliseconds ), )
4. Initialize the agent.
5. Observe the crash on startup.
Proposal
Since StreamableHttpClientTransport is built on top of the Ktor client, updating the try/catch block to catch SSEClientException instead of ClientRequestException should prevent the crash and allow graceful fallback or error reporting.
Let me know if a pull request would be helpful — I’d be happy to contribute a fix.