mcp-bridge

A Go library and CLI that forwards MCP between stdio and HTTP using the
official Go MCP SDK.
Install
curl -LsSf https://raw.githubusercontent.com/hughhan1/mcp-bridge/main/install.sh | sh
CLI
stdio to HTTP
Launch the MCP server as a subprocess and serve streamable HTTP at /mcp and
legacy SSE at /sse.
flowchart LR
client["MCP client"]
subgraph host["Server machine"]
bridge["mcp-bridge"] <-->|stdio| server["MCP server"]
end
client <-->|"streamable HTTP or SSE"| bridge
mcp-bridge serve --listen 127.0.0.1:8080 -- /path/to/mcp-server --stdio
mcp-bridge serve --help
Expose a stdio MCP server over Streamable HTTP and legacy SSE
Usage:
mcp-bridge serve [flags] -- SERVER [ARG...]
Flags:
--allow-origin origin Trusted browser origin (repeatable)
--cwd string Server working directory
--env KEY=VALUE Server environment override KEY=VALUE (repeatable)
-h, --help help for serve
--listen string HTTP listening address (default "127.0.0.1:8080")
--protocol-version string Require one MCP protocol version (default: automatic negotiation)
HTTP to stdio
Launch the bridge as a subprocess and expose a remote streamable HTTP or legacy
SSE MCP server over stdio.
flowchart LR
subgraph host["Client machine"]
client["MCP client"] <-->|stdio| bridge["mcp-bridge"]
end
bridge <-->|"streamable HTTP or SSE"| server["MCP server"]
mcp-bridge connect https://example.com/mcp
mcp-bridge connect --transport sse https://example.com/sse
mcp-bridge connect --header 'Authorization: Bearer example' https://example.com/mcp
mcp-bridge connect --help
Expose a remote Streamable HTTP or legacy SSE MCP server over stdio
Usage:
mcp-bridge connect [flags] URL
Flags:
--header header Remote header as Name: value (repeatable)
-h, --help help for connect
--transport string Remote transport: streamable-http or sse (default "streamable-http")
MCP client configuration
For clients using an mcpServers configuration:
Connect a stdio client to a streamable HTTP server
{
"mcpServers": {
"example-mcp": {
"command": "mcp-bridge",
"args": ["connect", "https://example.com/mcp"]
}
}
}
Connect to a legacy SSE server
{
"mcpServers": {
"example-mcp": {
"command": "mcp-bridge",
"args": ["connect", "--transport", "sse", "https://example.com/sse"]
}
}
}
Include authentication and an additional HTTP header
{
"mcpServers": {
"example-mcp": {
"command": "mcp-bridge",
"args": [
"connect", "https://example.com/mcp",
"--header", "Authorization: Bearer TOKEN",
"--header", "X-Tenant: example"
]
}
}
}
Go API
This repository provides these Go packages:
They run inside your Go program without invoking the CLI.
stdio to HTTP
import (
"context"
"errors"
"net/http"
"os/exec"
mcpbridge "github.com/hughhan1/mcp-bridge/http"
)
func serve(ctx context.Context) error {
bridge, err := mcpbridge.Start(ctx, func() *exec.Cmd {
return exec.Command("/path/to/mcp-server", "--stdio")
}, mcpbridge.Options{})
if err != nil {
return err
}
defer bridge.Close()
// Serve locally, with cross-origin browser protection.
server := &http.Server{
Addr: "127.0.0.1:8080",
Handler: http.NewCrossOriginProtection().Handler(bridge),
}
defer server.Close()
go func() { bridge.Wait(); server.Close() }()
if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
return err
}
return bridge.Wait()
}
HTTP to stdio
Streamable HTTP
import (
"context"
mcpbridge "github.com/hughhan1/mcp-bridge/stdio"
"github.com/modelcontextprotocol/go-sdk/mcp"
"golang.org/x/oauth2"
)
func connect(ctx context.Context, token string) error {
client := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}))
return mcpbridge.Run(ctx,
&mcp.StreamableClientTransport{Endpoint: "https://example.com/mcp", HTTPClient: client},
&mcp.StdioTransport{},
)
}
Legacy SSE
import (
"context"
mcpbridge "github.com/hughhan1/mcp-bridge/stdio"
"github.com/modelcontextprotocol/go-sdk/mcp"
"golang.org/x/oauth2"
)
func connectSSE(ctx context.Context, token string) error {
client := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}))
return mcpbridge.Run(ctx,
&mcp.SSEClientTransport{Endpoint: "https://example.com/sse", HTTPClient: client},
&mcp.StdioTransport{},
)
}