mcp-bridge

module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT

README

mcp-bridge

CI Go Go Reference Downloads MIT License

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/holon-sh/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

go get github.com/holon-sh/mcp-bridge@v0.0.4

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/holon-sh/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"

    "github.com/holon-sh/mcp-bridge/proxy"
    mcpbridge "github.com/holon-sh/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}))
    client.Transport = proxy.NewRemoteTransport(client.Transport)
    return mcpbridge.Run(ctx,
        &mcp.StreamableClientTransport{Endpoint: "https://example.com/mcp", HTTPClient: client},
        &mcp.StdioTransport{},
    )
}

Legacy SSE

import (
    "context"

    mcpbridge "github.com/holon-sh/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{},
    )
}
Custom proxies

Use proxy to forward messages between existing MCP connections, list tools across pages, or handle MCP HTTP headers in your own bridge. For example, relay an upstream server connection to a downstream client connection:

err := proxy.Relay(ctx, upstream, downstream)

Both connections close when forwarding ends. See the API reference for details.

Directories

Path Synopsis
cmd
mcp-bridge command
Package mcphttp makes stdio MCP servers available over Streamable HTTP and legacy SSE.
Package mcphttp makes stdio MCP servers available over Streamable HTTP and legacy SSE.
internal
translate
Package translate decides which MCP features survive translation between a current and a legacy session.
Package translate decides which MCP features survive translation between a current and a legacy session.
Package proxy provides reusable operations for custom MCP bridges.
Package proxy provides reusable operations for custom MCP bridges.
Package mcpstdio makes remote MCP servers available through a local transport, typically stdio.
Package mcpstdio makes remote MCP servers available through a local transport, typically stdio.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL