mcp-server-and-gw

MCP.Pizza Chef: boilingdata

The mcp-server-and-gw is a versatile MCP client that acts as a gateway bridging the Model Context Protocol (MCP) stdio transport to an HTTP Server-Sent Events (SSE) endpoint. It enables seamless communication between local MCP environments and remote servers, especially useful for setups like Claude Desktop that lack native remote server support. This Node.js-based tool includes an example MCP server and client, facilitating easy integration and deployment. Installation is straightforward via npm or npx, and it supports environment variable configuration for flexible usage. By converting stdio streams to HTTP SSE, it ensures real-time, structured context flow between LLM hosts and MCP servers, enhancing interoperability and remote access capabilities.

Use This MCP client To

Bridge local MCP stdio to remote HTTP SSE endpoints Enable remote server connections for Claude Desktop Run example MCP server and client for testing Facilitate real-time context streaming over HTTP SSE Integrate MCP with Node.js environments easily

README

MCP Gateway, Server, and Client

As long as Claude Desktop does not support connecting to remote servers, you can use this script to run a bridge from stdio to HTTP SSE (Server-Sent Events) endpoint.

Install mcp-server-and-gw

# 1. install
npm install -g mcp-server-and-gw
# 2. Or run directly with npx
npx mcp-server-and-gw http://localhost:8808/
# ...you can use environment variables too
MCP_HOST=localhost MCP_PORT=8808 npx mcp-server-and-gw

Add Configuration into Claude

The bridge script is node javasscript, but your server code can be whatever you use.

A Model Context Protocol gateway src/mcp-server-and-gw.ts from stdio to HTTP SSE transport.

## 1. Build
yarn install
yarn build

## 2. Copy the code or update the claude_desktop_config.json
##    NOTE: Ensure that npx is in the PATH, or use full path like /opt/homebrew/bin/npx
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 so that claude can connect to it for discoverying its resources, tools, etc.
PORT=8808 node examples/server.js

## 4. Start Claude Desktop

Example Server and Client

You can also develop the SSE server independently from Claude Desktop so you get faster iterations. For example, run the src/server.ts and use the src/client.ts as the client.

Start server, once you start the client on another terminal, you see the server output.

% node examples/server.js
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
--> Received message (post)
{ jsonrpc: '2.0', method: 'notifications/initialized' }
<-- 202 Accepted
--> Received message (post)
{ jsonrpc: '2.0', id: 1, method: 'resources/list' }
<-- 202 Accepted
--> Received message (post)
{ jsonrpc: '2.0', id: 2, method: 'tools/list' }
<-- 202 Accepted
--> Received message (post)
{
  jsonrpc: '2.0',
  id: 3,
  method: 'tools/call',
  params: { name: 'query', arguments: { sql: 'SELECT 42;' } }
}
<-- 202 Accepted

Start the client

% node examples/client.js
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. Provide the SQL clause that produces the data for the visualisation. Provide chart JSON configuration for Apache ECharts.',
      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 on one terminal

node examples/server.js

...and the gateway on another terminal

npx @modelcontextprotocol/inspector node ./build/mcp-server-and-gw.js

mcp-server-and-gw FAQ

How do I install mcp-server-and-gw?
You can install it globally using npm with 'npm install -g mcp-server-and-gw' or run it directly with npx using 'npx mcp-server-and-gw http://localhost:8808/'.
Can I configure mcp-server-and-gw using environment variables?
Yes, you can set environment variables like MCP_HOST and MCP_PORT to configure the connection endpoint before running the gateway.
What programming languages can I use for my MCP server with this gateway?
While the gateway script is written in Node.js, your MCP server code can be implemented in any language that supports HTTP SSE.
Does mcp-server-and-gw support real-time data streaming?
Yes, it uses HTTP Server-Sent Events (SSE) to stream real-time structured context data between MCP hosts and servers.
Is mcp-server-and-gw compatible with multiple LLM providers?
Yes, it is provider-agnostic and works with LLMs like OpenAI, Anthropic Claude, and Google Gemini by facilitating MCP transport bridging.
How do I build the mcp-server-and-gw from source?
Clone the repository, run 'yarn install' to install dependencies, then 'yarn build' to compile the project before use.
Can I use mcp-server-and-gw to test MCP client-server interactions?
Yes, it includes example server and client implementations to help you test and develop MCP integrations.
What problem does mcp-server-and-gw solve for Claude Desktop users?
It enables Claude Desktop to connect to remote MCP servers by bridging its stdio transport to HTTP SSE, which Claude Desktop does not natively support.