Skip to content

Commit 4b0d734

Browse files
authored
Merge pull request #255 from codelion/feat-remote-mcp-servers
Add multi-transport support to MCP plugin
2 parents 509ffa6 + 413577b commit 4b0d734

File tree

6 files changed

+1071
-140
lines changed

6 files changed

+1071
-140
lines changed

README.md

Lines changed: 171 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ response = client.chat.completions.create(
339339

340340
The Model Context Protocol (MCP) plugin enables OptiLLM to connect with MCP servers, bringing external tools, resources, and prompts into the context of language models. This allows for powerful integrations with filesystem access, database queries, API connections, and more.
341341

342+
OptiLLM supports both **local** and **remote** MCP servers through multiple transport methods:
343+
- **stdio**: Local servers (traditional)
344+
- **SSE**: Remote servers via Server-Sent Events
345+
- **WebSocket**: Remote servers via WebSocket connections
346+
342347
#### What is MCP?
343348

344349
The [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) is an open protocol standard that allows LLMs to securely access tools and data sources through a standardized interface. MCP servers can provide:
@@ -351,59 +356,186 @@ The [Model Context Protocol](https://modelcontextprotocol.io/) (MCP) is an open
351356

352357
##### Setting up MCP Config
353358

359+
> **Note on Backwards Compatibility**: Existing MCP configurations will continue to work unchanged. The `transport` field defaults to "stdio" when not specified, maintaining full backwards compatibility with existing setups.
360+
354361
1. Create a configuration file at `~/.optillm/mcp_config.json` with the following structure:
355362

363+
**Local Server (stdio) - Traditional Method:**
356364
```json
357365
{
358366
"mcpServers": {
359367
"filesystem": {
368+
"transport": "stdio",
360369
"command": "npx",
361370
"args": [
362371
"-y",
363372
"@modelcontextprotocol/server-filesystem",
364373
"/path/to/allowed/directory1",
365374
"/path/to/allowed/directory2"
366375
],
376+
"env": {},
377+
"description": "Local filesystem access"
378+
}
379+
},
380+
"log_level": "INFO"
381+
}
382+
```
383+
384+
**Legacy Format (still works):**
385+
```json
386+
{
387+
"mcpServers": {
388+
"filesystem": {
389+
"command": "npx",
390+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"],
367391
"env": {}
368392
}
393+
}
394+
}
395+
```
396+
397+
**Remote Server (SSE) - New Feature:**
398+
```json
399+
{
400+
"mcpServers": {
401+
"github": {
402+
"transport": "sse",
403+
"url": "https://api.githubcopilot.com/mcp",
404+
"headers": {
405+
"Authorization": "Bearer ${GITHUB_TOKEN}",
406+
"Accept": "text/event-stream"
407+
},
408+
"timeout": 30.0,
409+
"sse_read_timeout": 300.0,
410+
"description": "GitHub MCP server for repository access"
411+
}
412+
},
413+
"log_level": "INFO"
414+
}
415+
```
416+
417+
**Remote Server (WebSocket) - New Feature:**
418+
```json
419+
{
420+
"mcpServers": {
421+
"remote-ws": {
422+
"transport": "websocket",
423+
"url": "wss://api.example.com/mcp",
424+
"description": "Remote WebSocket MCP server"
425+
}
426+
},
427+
"log_level": "INFO"
428+
}
429+
```
430+
431+
**Mixed Configuration (Local + Remote):**
432+
```json
433+
{
434+
"mcpServers": {
435+
"filesystem": {
436+
"transport": "stdio",
437+
"command": "npx",
438+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/docs"],
439+
"description": "Local filesystem access"
440+
},
441+
"github": {
442+
"transport": "sse",
443+
"url": "https://api.githubcopilot.com/mcp",
444+
"headers": {
445+
"Authorization": "Bearer ${GITHUB_TOKEN}"
446+
},
447+
"description": "GitHub MCP server"
448+
},
449+
"remote-api": {
450+
"transport": "websocket",
451+
"url": "wss://api.company.com/mcp",
452+
"description": "Company internal MCP server"
453+
}
369454
},
370455
"log_level": "INFO"
371456
}
372457
```
373458

374-
Each server entry in `mcpServers` consists of:
459+
##### Configuration Parameters
460+
461+
**Common Parameters:**
462+
- **Server name**: A unique identifier for the server (e.g., "filesystem", "github")
463+
- **transport**: Transport method - "stdio" (default), "sse", or "websocket"
464+
- **description** (optional): Description of the server's functionality
465+
- **timeout** (optional): Connection timeout in seconds (default: 5.0)
375466

376-
- **Server name**: A unique identifier for the server (e.g., "filesystem")
467+
**stdio Transport (Local Servers):**
377468
- **command**: The executable to run the server
378469
- **args**: Command-line arguments for the server
379470
- **env**: Environment variables for the server process
380-
- **description** (optional): Description of the server's functionality
471+
472+
**sse Transport (Server-Sent Events):**
473+
- **url**: The SSE endpoint URL
474+
- **headers** (optional): HTTP headers for authentication
475+
- **sse_read_timeout** (optional): SSE read timeout in seconds (default: 300.0)
476+
477+
**websocket Transport (WebSocket):**
478+
- **url**: The WebSocket endpoint URL
479+
480+
**Environment Variable Expansion:**
481+
Headers and other string values support environment variable expansion using `${VARIABLE_NAME}` syntax. This is especially useful for API keys:
482+
```json
483+
{
484+
"headers": {
485+
"Authorization": "Bearer ${GITHUB_TOKEN}",
486+
"X-API-Key": "${MY_API_KEY}"
487+
}
488+
}
489+
```
381490

382491
#### Available MCP Servers
383492

384-
You can use any of the [official MCP servers](https://modelcontextprotocol.io/examples) or third-party servers. Some popular options include:
493+
OptiLLM supports both local and remote MCP servers:
494+
495+
##### Local MCP Servers (stdio transport)
496+
497+
You can use any of the [official MCP servers](https://modelcontextprotocol.io/examples) or third-party servers that run as local processes:
385498

386499
- **Filesystem**: `@modelcontextprotocol/server-filesystem` - File operations
387500
- **Git**: `mcp-server-git` - Git repository operations
388501
- **SQLite**: `@modelcontextprotocol/server-sqlite` - SQLite database access
389502
- **Brave Search**: `@modelcontextprotocol/server-brave-search` - Web search capabilities
390503

391-
Example configuration for multiple servers:
504+
##### Remote MCP Servers (SSE/WebSocket transport)
505+
506+
Remote servers provide centralized access without requiring local installation:
507+
508+
- **GitHub MCP Server**: `https://api.githubcopilot.com/mcp` - Repository management, issue tracking, and code analysis
509+
- **Third-party servers**: Any MCP server that supports SSE or WebSocket protocols
510+
511+
##### Example: Comprehensive Configuration
392512

393513
```json
394514
{
395515
"mcpServers": {
396516
"filesystem": {
517+
"transport": "stdio",
397518
"command": "npx",
398519
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/documents"],
399-
"env": {}
520+
"description": "Local file system access"
400521
},
401522
"search": {
523+
"transport": "stdio",
402524
"command": "npx",
403525
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
404526
"env": {
405527
"BRAVE_API_KEY": "your-api-key-here"
406-
}
528+
},
529+
"description": "Web search capabilities"
530+
},
531+
"github": {
532+
"transport": "sse",
533+
"url": "https://api.githubcopilot.com/mcp",
534+
"headers": {
535+
"Authorization": "Bearer ${GITHUB_TOKEN}",
536+
"Accept": "text/event-stream"
537+
},
538+
"description": "GitHub repository and issue management"
407539
}
408540
},
409541
"log_level": "INFO"
@@ -429,11 +561,18 @@ The plugin enhances the system prompt with MCP capabilities so the model knows w
429561

430562
Here are some examples of queries that will engage MCP tools:
431563

564+
**Local Server Examples:**
432565
- "List all the Python files in my documents directory" (Filesystem)
433566
- "What are the recent commits in my Git repository?" (Git)
434567
- "Search for the latest information about renewable energy" (Search)
435568
- "Query my database for all users who registered this month" (Database)
436569

570+
**Remote Server Examples:**
571+
- "Show me the open issues in my GitHub repository" (GitHub MCP)
572+
- "Create a new branch for the feature I'm working on" (GitHub MCP)
573+
- "What are the most recent pull requests that need review?" (GitHub MCP)
574+
- "Get the file contents from my remote repository" (GitHub MCP)
575+
437576
#### Troubleshooting
438577

439578
##### Logs
@@ -447,13 +586,35 @@ Check this log file for connection issues, tool execution errors, and other diag
447586

448587
##### Common Issues
449588

589+
**Local Server Issues (stdio transport):**
590+
450591
1. **Command not found**: Make sure the server executable is available in your PATH, or use an absolute path in the configuration.
451592

452-
2. **Connection failed**: Verify the server is properly configured and any required API keys are provided.
593+
2. **Access denied**: For filesystem operations, ensure the paths specified in the configuration are accessible to the process.
594+
595+
**Remote Server Issues (SSE/WebSocket transport):**
596+
597+
3. **Connection timeout**: Remote servers may take longer to connect. Increase the `timeout` value in your configuration.
598+
599+
4. **Authentication failed**: Verify your API keys and tokens are correct. For GitHub MCP server, ensure your `GITHUB_TOKEN` environment variable is set with appropriate permissions.
600+
601+
5. **Network errors**: Check your internet connection and verify the server URL is accessible.
602+
603+
6. **Environment variable not found**: If using `${VARIABLE_NAME}` syntax, ensure the environment variables are set before starting OptILLM.
604+
605+
**General Issues:**
606+
607+
7. **Method not found**: Some servers don't implement all MCP capabilities (tools, resources, prompts). Verify which capabilities the server supports.
608+
609+
8. **Transport not supported**: Ensure you're using a supported transport: "stdio", "sse", or "websocket".
610+
611+
**Example: Testing GitHub MCP Connection**
453612

454-
3. **Method not found**: Some servers don't implement all MCP capabilities (tools, resources, prompts). Verify which capabilities the server supports.
613+
To test if your GitHub MCP server configuration is working:
455614

456-
4. **Access denied**: For filesystem operations, ensure the paths specified in the configuration are accessible to the process.
615+
1. Set your GitHub token: `export GITHUB_TOKEN="your-github-token"`
616+
2. Start OptILLM and check the logs at `~/.optillm/logs/mcp_plugin.log`
617+
3. Look for connection success messages and discovered capabilities
457618

458619
## Available parameters
459620

optillm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Version information
2-
__version__ = "0.2.10"
2+
__version__ = "0.3.0"
33

44
# Import from server module
55
from .server import (

0 commit comments

Comments
 (0)