Skip to content

Commit 108ffac

Browse files
claudecodelion
authored andcommitted
Port MCP plugin to mcp 2.x
mcp 2.x removed the WebSocket client and renamed or reshaped several APIs, which broke the MCP plugin import on fresh installs. - McpError -> MCPError; tool/result fields are snake_case (input_schema, mime_type, is_error). - Add the Streamable HTTP transport ("streamable_http", also "streamable-http"/"http") with headers and timeouts via create_mcp_http_client. "websocket" now fails with a clear error pointing to streamable_http or sse. - LoggingClientSession logs the method/params of 2.x request and notification objects. - Detect server capabilities by value; hasattr was always true. - Handle non-CallToolResult results (e.g. InputRequiredResult). - Share header env expansion between SSE and Streamable HTTP. - Require mcp>=2,<3 (replaces the earlier <2 pin); update README and tests. Verified against real mcp 2.2.0 servers over stdio, SSE and Streamable HTTP (connect, discover, call tool). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6a60585 commit 108ffac

5 files changed

Lines changed: 170 additions & 80 deletions

File tree

‎README.md‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ The Model Context Protocol (MCP) plugin enables OptiLLM to connect with MCP serv
377377
OptiLLM supports both **local** and **remote** MCP servers through multiple transport methods:
378378
- **stdio**: Local servers (traditional)
379379
- **SSE**: Remote servers via Server-Sent Events
380-
- **WebSocket**: Remote servers via WebSocket connections
380+
- **Streamable HTTP**: Remote servers via the MCP Streamable HTTP transport
381381

382382
#### What is MCP?
383383

@@ -449,14 +449,17 @@ The [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) is an open
449449
}
450450
```
451451

452-
**Remote Server (WebSocket) - New Feature:**
452+
**Remote Server (Streamable HTTP):**
453453
```json
454454
{
455455
"mcpServers": {
456-
"remote-ws": {
457-
"transport": "websocket",
458-
"url": "wss://api.example.com/mcp",
459-
"description": "Remote WebSocket MCP server"
456+
"remote-http": {
457+
"transport": "streamable_http",
458+
"url": "https://api.example.com/mcp",
459+
"headers": {
460+
"Authorization": "Bearer ${API_TOKEN}"
461+
},
462+
"description": "Remote Streamable HTTP MCP server"
460463
}
461464
},
462465
"log_level": "INFO"
@@ -482,8 +485,8 @@ The [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) is an open
482485
"description": "GitHub MCP server"
483486
},
484487
"remote-api": {
485-
"transport": "websocket",
486-
"url": "wss://api.company.com/mcp",
488+
"transport": "streamable_http",
489+
"url": "https://api.company.com/mcp",
487490
"description": "Company internal MCP server"
488491
}
489492
},
@@ -495,7 +498,7 @@ The [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) is an open
495498

496499
**Common Parameters:**
497500
- **Server name**: A unique identifier for the server (e.g., "filesystem", "github")
498-
- **transport**: Transport method - "stdio" (default), "sse", or "websocket"
501+
- **transport**: Transport method - "stdio" (default), "sse", or "streamable_http"
499502
- **description** (optional): Description of the server's functionality
500503
- **timeout** (optional): Connection timeout in seconds (default: 5.0)
501504

@@ -509,8 +512,12 @@ The [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) is an open
509512
- **headers** (optional): HTTP headers for authentication
510513
- **sse_read_timeout** (optional): SSE read timeout in seconds (default: 300.0)
511514

512-
**websocket Transport (WebSocket):**
513-
- **url**: The WebSocket endpoint URL
515+
**streamable_http Transport (Streamable HTTP):**
516+
- **url**: The MCP endpoint URL
517+
- **headers** (optional): HTTP headers for authentication
518+
- **sse_read_timeout** (optional): Read timeout in seconds (default: 300.0)
519+
520+
The `websocket` transport was removed in MCP Python SDK 2.x and is no longer supported; use `streamable_http` or `sse` instead.
514521

515522
**Environment Variable Expansion:**
516523
Headers and other string values support environment variable expansion using `${VARIABLE_NAME}` syntax. This is especially useful for API keys:
@@ -536,12 +543,12 @@ You can use any of the [official MCP servers](https://modelcontextprotocol.io/ex
536543
- **SQLite**: `@modelcontextprotocol/server-sqlite` - SQLite database access
537544
- **Brave Search**: `@modelcontextprotocol/server-brave-search` - Web search capabilities
538545

539-
##### Remote MCP Servers (SSE/WebSocket transport)
546+
##### Remote MCP Servers (SSE/Streamable HTTP transport)
540547

541548
Remote servers provide centralized access without requiring local installation:
542549

543550
- **GitHub MCP Server**: `https://api.githubcopilot.com/mcp` - Repository management, issue tracking, and code analysis
544-
- **Third-party servers**: Any MCP server that supports SSE or WebSocket protocols
551+
- **Third-party servers**: Any MCP server that supports the SSE or Streamable HTTP transports
545552

546553
##### Example: Comprehensive Configuration
547554

@@ -627,7 +634,7 @@ Check this log file for connection issues, tool execution errors, and other diag
627634

628635
2. **Access denied**: For filesystem operations, ensure the paths specified in the configuration are accessible to the process.
629636

630-
**Remote Server Issues (SSE/WebSocket transport):**
637+
**Remote Server Issues (SSE/Streamable HTTP transport):**
631638

632639
3. **Connection timeout**: Remote servers may take longer to connect. Increase the `timeout` value in your configuration.
633640

@@ -641,7 +648,7 @@ Check this log file for connection issues, tool execution errors, and other diag
641648

642649
7. **Method not found**: Some servers don't implement all MCP capabilities (tools, resources, prompts). Verify which capabilities the server supports.
643650

644-
8. **Transport not supported**: Ensure you're using a supported transport: "stdio", "sse", or "websocket".
651+
8. **Transport not supported**: Ensure you're using a supported transport: "stdio", "sse", or "streamable_http".
645652

646653
**Example: Testing GitHub MCP Connection**
647654

0 commit comments

Comments
 (0)