mcp-server-and-gw
by: boilingdata
An MCP stdio to HTTP SSE transport gateway with example server and MCP client
📌Overview
Purpose: To enable connection from Claude Desktop to remote servers through HTTP SSE using a bridge script.
Overview: The MCP Gateway facilitates communication between the standard input/output (stdio) and HTTP Server-Sent Events (SSE) endpoints. This allows Claude Desktop to utilize functionalities and resources from remote servers, enhancing its capabilities.
Key Features:
-
Bridge Implementation: The node JavaScript bridge script connects stdio with HTTP SSE, allowing Claude Desktop to interact with external services in real-time.
-
Independent Server and Client Development: Users can independently run the SSE server and client for quick testing and iterations, improving development efficiency and streamlining the process of integrating server functionalities.
MCP Gateway, Server, and Client
Claude Desktop does not currently support connecting to remote servers directly. This script runs a bridge from stdio to HTTP SSE (Server-Sent Events) endpoint.
Install mcp-server-and-gw
# 1. Install globally
npm install -g mcp-server-and-gw
# 2. Or run directly with npx
npx mcp-server-and-gw http://localhost:8808/
# You can also use environment variables
MCP_HOST=localhost MCP_PORT=8808 npx mcp-server-and-gw
Add Configuration into Claude
The bridge script is written in Node.js, but your server code can use any language.
Model Context Protocol (MCP) gateway bridges from stdio to HTTP SSE transport.
# 1. Build
yarn install
yarn build
# 2. Update claude_desktop_config.json
echo '{
"mcpServers": {
"Claude Gateway Example": {
"command": "npx",
"args": [
"mcp-server-and-gw", "http://localhost:8808/"
]
}
}
}' > ~/Library/Application\ Support/Claude/claude_desktop_config.json
# 3. Start server for Claude to connect for discovering resources, tools, etc.
PORT=8808 node examples/server.js
# 4. Start Claude Desktop
Example Server and Client
Develop the SSE server separately from Claude Desktop for faster iterations. Use src/server.ts
as the server and src/client.ts
as the client.
Start the server:
node examples/server.js
Example server output on receiving connections and requests:
Server is running on port 8808
--> Received connection: /sse
New SSE connection.
--> Received message (post)
{
jsonrpc: '2.0',
id: 0,
method: 'initialize',
params: {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'example-client', version: '1.0.0' }
}
}
<-- 202 Accepted
...
Start the client in another terminal:
node examples/client.js
Example client output:
Connecting...
Connected: { resources: {}, tools: {}, templates: {} }
{ resources: [] }
{
tools: [
{
name: 'query',
description: 'Run a read-only SQL query on a DuckDB database',
inputSchema: { type: 'object', properties: { sql: { type: 'string' } } }
},
{
name: 'visualise',
description: 'Visualise SQL query results as an Apache ECharts chart.',
inputSchema: {
type: 'object',
properties: { sql: { type: 'string' }, chart: { type: 'string' } }
}
}
]
}
{
content: [ { type: 'text', text: '[\n {\n "42": 42\n }\n]' } ],
isError: false
}
Testing with MCP Inspector
Start the example server:
node examples/server.js
Start the gateway:
npx @modelcontextprotocol/inspector node ./build/mcp-server-and-gw.js