Enhanced version of supergateway, adding streamable http, OpenAPI and higress MCP template support.
927
McpGateway is a versatile protocol conversion tool for Model Context Protocol (MCP) servers, enabling:
Run McpGateway via npx:
npx -y @michlyn/mcpgateway --stdio "uvx mcp-server-git"
--stdio "command": Command that runs an MCP server over stdio--sse "https://mcp-server-url.example.com": SSE URL to connect to (SSE→stdio mode)--outputTransport stdio | sse | ws | streamable-http: Output MCP transport (default: sse with --stdio, stdio with --sse)--port 8000: Port to listen on (default: 8000)--baseUrl "http://localhost:8000": Base URL for SSE, WS, or Streamable HTTP clients (optional)--header "x-user-id: 123": Add custom headers (can be used multiple times)--oauth2Bearer "some-access-token": Add an Authorization header with the provided Bearer token--logLevel info | none: Control logging level (default: info)--cors: Enable CORS (use with no values to allow all origins, or specify allowed origins)--healthEndpoint /healthz: Register endpoints that respond with "ok"--ssePath "/sse": Path for SSE subscriptions (default: /sse)--messagePath "/message": Path for messages (default: /message)--httpPath "/mcp": Path for Streamable HTTP (default: /mcp)--api "./openapi.json": OpenAPI document or MCP template file (JSON or YAML)--apiHost "https://api.example.com": Base URL for the API serverMcpGateway is available as a Docker image, making it easy to run without installing Node.js locally.
Available on Docker Hub: michlyn/mcpgateway
docker run -it --rm -p 8000:8000 michlyn/mcpgateway \
--stdio "npx -y @modelcontextprotocol/server-filesystem /" \
--port 8000 --ssePath /sse --messagePath /message
docker run -it --rm -p 8000:8000 michlyn/mcpgateway \
--stdio "npx -y @modelcontextprotocol/server-filesystem /" \
--outputTransport streamable-http --port 8000 --httpPath /mcp
docker run -it --rm -p 8000:8000 michlyn/mcpgateway \
--stdio "npx -y @modelcontextprotocol/server-filesystem /" \
--outputTransport ws --port 8000 --messagePath /message
docker run -it --rm michlyn/mcpgateway \
--sse "https://mcp-server-example.supermachine.app" \
--outputTransport stdio
docker run -it --rm -p 8000:8000 michlyn/mcpgateway \
--sse "https://mcp-server-example.supermachine.app" \
--outputTransport streamable-http --port 8000 --httpPath /mcp
docker run -it --rm -p 8000:8000 michlyn/mcpgateway \
--api /path/to/openapi.json --apiHost https://api.example.com \
--outputTransport sse --port 8000 --ssePath /sse --messagePath /message
docker run -it --rm -p 8000:8000 michlyn/mcpgateway \
--api /path/to/openapi.json --apiHost https://api.example.com \
--outputTransport streamable-http --port 8000 --httpPath /mcp
To provide files from your host system:
docker run -it --rm -p 8000:8000 -v $(pwd):/workspace michlyn/mcpgateway \
--stdio "npx -y @modelcontextprotocol/server-filesystem /workspace" \
--port 8000
Share your local MCP server publicly: npx -y @michlyn/mcpgateway --port 8000 --stdio "npx -y @modelcontextprotocol/server-filesystem ."
ngrok http 8000
The MCP server will be available at a URL similar to: https://1234-567-890-12-456.ngrok-free.app/sse
## Troubleshooting SSE Connections
If you encounter issues with SSE connections or tool calls not being processed:
1. **Check Session IDs**: Ensure the client is using the session ID returned by the server in the SSE response headers:
```javascript
// Example JavaScript client code
const sseConnection = new EventSource('/sse');
let sessionId;
sseConnection.onopen = (event) => {
// Get session ID from response headers
sessionId = event.target.getResponseHeader('mcp-session-id');
console.log('Connected with session ID:', sessionId);
};
// Use that session ID for message requests
async function callTool(toolName, parameters) {
const response = await fetch('/message', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'mcp-session-id': sessionId
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'tools/call',
params: { name: toolName, arguments: parameters },
id: Date.now()
})
});
return await response.json();
}
Standard MCP tools/call Format: Use the standard MCP tools/call message format:
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "toolName",
"arguments": {
"param1": "value1",
"param2": "value2"
}
},
"id": 1
}
Note: The arguments field is used instead of parameters. This is required for compatibility with the standard MCP tools/call format and direct-intercept mode.
Use the Debug Tool: The server includes a built-in debug tool to test tool invocation:
curl -X POST \
-H "Content-Type: application/json" \
-H "mcp-session-id: YOUR_SESSION_ID" \
http://localhost:8080/message \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "debug",
"arguments": {
"message": "Testing connection",
"testMode": true
}
},
"id": 1
}'
Check Server Logs: Look for detailed logs showing:
Common Issues:
Authentication Headers Handling:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "mcp-session-id: YOUR_SESSION_ID" \
http://localhost:8000/message \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "debug",
"arguments": {
"message": "Testing auth headers",
"testMode": true
}
},
"id": 1
}'
tools/call Direct Interception:
Request Body Handling:
Request Headers Pass-through:
Model Context Protocol standardizes AI tool interactions. McpGateway converts between different MCP transport types (stdio, SSE, WS, and Streamable HTTP), simplifying integration and debugging with various clients.
The Streamable HTTP transport is the latest MCP standard, offering improved performance and better compatibility with modern web infrastructure. McpGateway makes it easy to use this transport with any MCP server, regardless of the transport it natively supports.
Issues and PRs welcome. Please open one if you encounter problems or have feature suggestions.
欢迎有兴趣的伙伴+v入群技术交流:
Content type
Image
Digest
sha256:ab4c71a21…
Size
102.7 MB
Last updated
over 1 year ago
docker pull michlyn/mcpgateway