
mpc-bridge
from AgentForgeEngine
http stream to stdin/stdout and back
โ labsco summary โ our analysis, not the vendor's
What it is โ a Go application that wraps subprocess-based MCP servers with HTTP streaming (SSE), so web-based MCP clients can talk to stdio MCP servers; compatible with llama.cpp's StreamableHTTP transport.
What you get โ
- HTTP streaming server โ
GET /mcp/{namespace}(SSE) andPOST /mcp/{namespace}/message, with CORS and lifecycle management - Subprocess management โ on-demand spawning, connection reuse, exponential-backoff restarts, graceful SIGTERM/SIGINT shutdown
- Full MCP handling โ
initialize,tools/list,tools/call,pingover JSON-RPC 2.0, with message-size and connection limits - Ops built in โ
/healthchecks,/metricsPrometheus endpoint, and/debugdashboard with real-time message log
Requirements โ nothing โ runs out of the box; a Go application with no API keys. You bring the MCP server subprocess to bridge.
Cost snapshot โ free (no license stated in the excerpt); self-hosted Go binary.
Setup effort โ self-host: build and run the Go bridge, point clients at its HTTP endpoints.
Our take โ A solid infrastructure piece for exposing stdio MCP servers over HTTP/SSE, especially with llama.cpp; note it's developer plumbing โ "Master Documentation" for a bridge, not an end-user tool โ and the excerpt references a bundled test-server, so you supply the real servers.
Source: the project README โ summarized 2026-07-08.
โ readme from github โ mirrored (latest on GitHub โ)
Go MCP HTTP Bridge - Master Documentation
Overview
A Go application that wraps MCP (Model Context Protocol) servers with HTTP streaming (SSE), fully compatible with llama.cpp's StreamableHTTP transport. This bridge allows web-based MCP clients to communicate with subprocess-based MCP servers.
Architecture
โโโโโโโโโโโโโโโโโโโ
โ Client โ
โ (LLM/App) โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โ HTTP POST + SSE Stream
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Go MCP HTTP Bridge โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ HTTP Server โ โ
โ โ - POST /mcp/{ns}/msg โ โ
โ โ - GET /mcp/{ns} (SSE) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Protocol Handler โ โ
โ โ - initialize โ โ
โ โ - tools/list โ โ
โ โ - tools/call โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Subprocess Manager โ โ
โ โ - test-server โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโFeatures
โ Implemented (All Phases 1-6 Complete)
-
HTTP Streaming Server
- SSE streaming (
GET /mcp/{namespace}) - HTTP POST endpoint (
POST /mcp/{namespace}/message) - Proper CORS support
- Connection lifecycle management
- SSE streaming (
-
Subprocess Management
- On-demand spawning
- Connection reuse
- Exponential backoff restarts (1s, 2s, 4s... up to 60s)
- Graceful shutdown (SIGTERM/SIGINT handling)
- Process state tracking
-
JSON-RPC 2.0
- Request/response parsing
- Message validation
- Error handling
- Notification support
-
MCP Protocol Support
initialize- Handshake with server infotools/list- List available toolstools/call- Execute toolsping- Health check
-
Security
- Input validation (JSON-RPC, arguments)
- Command injection prevention
- CORS and origin validation
- Message size limits (1MB request, 10MB response)
- Connection limits (configurable, default: 5)
-
Logging
- Structured JSON logging with
slog - Context-aware logs (namespace, session, request ID)
- Connection event tracking
- Subprocess event logging
- Structured JSON logging with
-
Debug Tools
/debug- Dashboard/debug/stream- Real-time message log
-
Health Checks
/health- Bridge status/health/{namespace}- Per-server status
-
Prometheus Metrics
/metricsendpoint- HTTP request metrics (mcp_http_requests_total, mcp_http_request_duration_seconds)
- Tool call metrics (mcp_tool_calls_total, mcp_tool_calls_duration_seconds, mcp_tool_errors_total)
- Active sessions gauge (mcp_active_sessions)
- Subprocess state metrics (mcp_subprocess_state)
-
Enhanced Debug Streaming
/debug/stream- Real-time DEBUG and INFO logs- JSON-RPC 2.0 compliant SSE format
- No verbose flag needed
๐ง Configuration
Full configuration example:
bridge:
port: 8080
allowed_origins:
- http://localhost:3000
- http://127.0.0.1:3000
request_timeout: 30s
idle_timeout: 5m
connection_limit: 5
request_size_limit: 1048576
response_size_limit: 10485760
servers:
filesystem:
name: "filesystem"
binary: "/usr/bin/node"
args:
- "/path/to/mcp-filesystem-server/index.js"
env:
HOME: "/home/user"
timeout: 30s
max_restarts: 3
auto_start: true
git:
name: "git"
binary: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-git"
timeout: 60s
max_restarts: 5
auto_start: falseFor complete configuration options, see docs/CONFIG.md.
๐ Quick Start
-
Build
cd go-mcp-bridge make build -
Configure Create
config.yamlwith your MCP server settings:bridge: port: 8080 allowed_origins: - http://localhost:3000 servers: git: name: "git" binary: "npx" args: - "-y" - "@modelcontextprotocol/server-git" -
Run
./bin/bridge --config config.yaml -
Test
# Health check curl http://localhost:8080/health # Send initialize request curl -X POST http://localhost:8080/mcp/git \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{...}}' # Check metrics curl http://localhost:8080/metrics # View debug stream curl http://localhost:8080/debug/stream
๐ก API Endpoints
Primary MCP Endpoint
GET /mcp/{namespace} โ Start SSE stream
POST /mcp/{namespace}/message โ Send JSON-RPC requestExample Request:
curl -X POST http://localhost:8080/mcp/test/message \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{...}}'Health Check
GET /health โ Bridge health
GET /health/{namespace} โ Namespace healthDebug Endpoint
GET /debug โ Debug dashboard (HTML)
GET /debug/stream โ Debug message stream (SSE)Project Structure
go-mcp-bridge/
โโโ cmd/
โ โโโ bridge/main.go # Main entry point
โ โโโ test-server/ # Go test MCP server
โ โโโ test-mcp-server/ # TypeScript test MCP server
โโโ internal/
โ โโโ config/
โ โ โโโ loader.go # YAML config parser
โ โโโ mcp/
โ โ โโโ handler.go # Protocol handler
โ โ โโโ jsonrpc.go # JSON-RPC 2.0
โ โ โโโ types.go # MCP types
โ โโโ process/
โ โ โโโ manager.go # Subprocess manager
โ โโโ router/
โ โ โโโ namespace.go # Namespace routing
โ โโโ server/
โ โโโ http.go # HTTP server
โ โโโ sse.go # SSE writer
โ โโโ metrics.go # Prometheus metrics
โโโ docs/ # Documentation
โ โโโ CONFIG.md # Configuration reference
โ โโโ API.md # API specification
โ โโโ EXAMPLES.md # Usage examples
โ โโโ DEBUG.md # Debug endpoint guide
โ โโโ TESTING.md # Testing guide
โโโ testdata/ # Test configurations
โโโ bin/ # Built binaries
โโโ config.yaml # Configuration
โโโ Makefile # Build automation
โโโ test-tool-metrics.sh # Tool metrics test script
โโโ README.md # This fileTesting
Unit Tests
# Run all unit tests
go test ./... -v
# Specific package
go test ./internal/mcp/... -vEnd-to-End Test
# Start bridge in background
./bin/bridge --config config.yaml &
BRIDGE_PID=$!
# Run tests
./test.sh
# Stop bridge
kill $BRIDGE_PIDIntegration Tests (Complete)
# Test with real subprocess
./test-tool-metrics.sh
# Or run all tests
go test ./... -vGit Branches
master- Current stable (All phases 1-6 complete)
Roadmap
โ Phase 1-2: Core Architecture (COMPLETE)
- โ HTTP streaming server
- โ Subprocess management
- โ Basic JSON-RPC handling
โ Phase 3: MCP Protocol Support (COMPLETE)
- โ JSON-RPC 2.0 handling
- โ Initialize method
- โ Tools/list and tools/call
- โ Request-response correlation
โ Phase 4: Security & Error Handling (COMPLETE)
- โ Input validation (JSON-RPC, arguments)
- โ Command injection prevention
- โ Resource limits (size, connections)
- โ Exponential backoff restarts
- โ Graceful shutdown
- โ Structured JSON logging
โ Phase 5: Testing & Documentation (COMPLETE)
- โ
Unit tests (45 tests)
- JSON-RPC parsing (20 tests)
- Config loading (14 tests)
- Namespace routing (11 tests)
- โ
Integration tests (45+ tests)
- HTTP server tests (20+ tests)
- Process manager tests (15+ tests)
- Namespace isolation tests (10 tests)
- โ Complete documentation (docs/CONFIG.md, docs/API.md, docs/EXAMPLES.md, docs/DEBUG.md, docs/TESTING.md)
โ Phase 6: Build & Monitoring (COMPLETE)
- โ
6.1 Prometheus metrics (/metrics endpoint)
- โ HTTP request metrics (mcp_http_requests_total, mcp_http_request_duration_seconds)
- โ Active sessions gauge (mcp_active_sessions)
- โ Subprocess state metrics (mcp_subprocess_state)
- โ Tool call metrics (mcp_tool_calls_total, mcp_tool_calls_duration_seconds, mcp_tool_errors_total)
- โ Metrics endpoint at /metrics
- โ
6.2 Structured logging with slog
- โ Replace fmt.Printf with slog
- โ JSON structured logging
- โ Context-aware logs (namespace, session, request_id)
- โ
6.3 Enhanced debug streaming
- โ Stream DEBUG and INFO logs to /debug/stream
- โ JSON-RPC 2.0 compliant SSE format
- โ No verbose flag needed
- โ
6.4 Configuration cleanup
- โ Remove unused debug_port configuration
- โ Keep debug endpoints on main port 8080
- โ 6.5 Test script for tool metrics (test-tool-metrics.sh)
- โ 6.6 End-to-end verification of tool metrics recording
All phases complete as of Phase 6 merge to master.
Compatibility
โ llama.cpp web frontend
- Compatible with StreamableHTTP transport
- Works with latest llama.cpp build
โ MCP SDK
- Uses standard JSON-RPC 2.0 format
- Supports MCP protocol versions:
- 2025-06-18 (latest)
- 2025-03-26 (default)
- 2024-11-05 (backward compat)
Known MCP Servers
These servers can be used with the bridge:
-
Git MCP (NPM)
servers: git: name: "git" binary: "npx" args: ["-y", "@modelcontextprotocol/server-git"] -
Filesystem MCP (uvx)
servers: filesystem: name: "filesystem" binary: "uvx" args: ["mcp-server-filesystem", "--allowed-directory", "/data"] -
Memory MCP (Docker)
servers: memory: name: "memory" binary: "docker" args: ["run", "-i", "mcp/memory-server"] -
Custom Binary
servers: custom: name: "custom" binary: "./my-mcp-server" args: ["--port", "8080"]
See EXAMPLES.md for more configuration examples.
Documentation
| Document | Description |
|---|---|
| docs/CONFIG.md | Complete configuration reference |
| docs/API.md | HTTP API specification |
| docs/EXAMPLES.md | Usage examples and configurations |
| docs/DEBUG.md | Debug endpoint guide |
| docs/TESTING.md | Testing guide and test infrastructure |
bridge:
port: 8080
allowed_origins:
- http://localhost:3000
- http://127.0.0.1:3000
request_timeout: 30s
idle_timeout: 5m
connection_limit: 5
request_size_limit: 1048576
response_size_limit: 10485760
servers:
filesystem:
name: "filesystem"
binary: "/usr/bin/node"
args:
- "/path/to/mcp-filesystem-server/index.js"
env:
HOME: "/home/user"
timeout: 30s
max_restarts: 3
auto_start: true
git:
name: "git"
binary: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-git"
timeout: 60s
max_restarts: 5
auto_start: falseTroubleshooting
Subprocess won't start
- Check binary path is correct:
which npx - Verify binary is executable:
chmod +x ./bin/test-server - Check environment variables in config
- Look at structured logs for errors
Connection fails
- Verify namespace exists in config
- Check
allowed_originsincludes client origin - Look at
/debug/streamfor real-time errors - Check
/health/{namespace}for subprocess status
Messages not streaming
- Ensure subprocess outputs JSON-RPC to stdout
- Check for newline termination on messages (
\n) - Verify SSE headers are set correctly
- Use
/debug/streamto see raw messages
High restart count
- Check subprocess logs for errors
- Increase timeout if subprocess is slow
- Verify args are correct
- Check resource limits
Security errors
- Verify argument sanitization
- Check allowed hosts/origins
- Ensure binary path is safe (no shell injection)
License
MIT