MCP gateway/proxy: multiplexes tool calls across upstream MCP servers into one catalog.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent — or use 1-click editor setup below.
💡 Paste into ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
Русская версия — README_RU.md.
A gateway / proxy for MCP servers (Model Context Protocol) written in Go. It presents itself to an MCP client (Claude Code, Cursor, etc.) as one MCP server, while under the hood it multiplexes calls across several upstream MCP servers, aggregates their tools, prompts and resources into one catalog, and logs every call.
Status: MVP complete (Stages 0–6) + post-MVP Stages 7–17b shipped, latest release v0.4.0. Phase 1 — multiplexing stdio upstreams behind a stdio endpoint with a call log; Phase 2 — HTTP/SSE client-facing transport, HTTP upstreams, a CLI log viewer (
mcp-gate logs); release pipeline (goreleaser, cross-compiled for linux/darwin/windows × amd64/arm64, no CGO). Post-MVP added upstream auto-restart, hot config reload, tool filtering/renaming,doctor, and — in v0.3.0 — fullprompts/resources/resources/templates/completionaggregation,ping, progress forwarding and real cancellation,logging/setLevelfan-out, per-upstream call limits (rate limit / concurrency / result truncation / timeout), a lazy catalog andtools/listpagination, and SSE server→client streams on both the client and the upstream side. v0.4.0 completed the server→client direction: all three server-initiated methods —elicitation/create,sampling/createMessageandroots/list— are proxied in all four transport combinations (stdio or HTTP on the client side × stdio or HTTP on the upstream side); the gateway now declares to an upstream exactly the capabilities its own client declared instead of a blanket{}; the HTTP transport gained server-sideMcp-Session-Idsessions withDELETE /mcptermination.Upgrading to v0.4.0: no config-file change, but two observable HTTP-mode behaviour changes — a session id is now mandatory on
POST /mcpafterinitialize(the header is returned by theinitializeresponse), and the upstream registry starts lazily on the first real MCP request instead of at process start.Not implemented: a per-client access policy.
Cross-platform binaries are built via goreleaser
(.goreleaser.yaml): linux/darwin/windows × amd64/arm64, no CGO,
the version is baked in via -ldflags -X main.version=..., checksums land in
SHA256SUMS. Local dry run: goreleaser release --snapshot --clean.
Besides the raw release binaries, the gateway ships as an OCI image on GitHub Container Registry and as an npm wrapper package — the two formats MCP registries install from.
Docker:
-i is mandatory: the gateway talks MCP over stdio, so the client must keep
stdin open (without it the container sees EOF and exits immediately). The
image has no config of its own, so mount yours — the example above mounts it
onto the default path /config.yaml; any other path works with serve -c.
To reproduce a registry sandbox check (Glama.ai etc.) without any real upstream, use the demo config baked into the image — this exact command is what a sandbox should run:
npx (downloads the prebuilt binary for your platform on first install and verifies its SHA256 checksum):
Image policy: the OCI image contains only the mcp-gate binary — no
runtimes for stdio upstreams (no node/npx, python, shells). If your config
launches stdio upstream servers, extend the image yourself and install what
they need; HTTP upstreams work out of the box (CA certificates are included).
Demo config: demo.config.yaml and the hidden
__demo-echo subcommand exist only so registry sandboxes (Glama.ai) can
introspect the gateway without any real upstream — never use them in a real
deployment.
An active MCP user typically has several servers configured (filesystem,
GitHub, search, custom ones), each one duplicated in every client's own
config. aiMCPGate gives you:
<upstream>__<tool> so names never collide), plus their
resources and resource templates (addressed by URI, so never renamed).Solo pet project: the priority is learning Go (concurrency, os/exec,
JSON-RPC 2.0, the stdio and HTTP/SSE transports). Cost — $0/month by
default (a local process), no telemetry.
All commands except token --generate, completion and skill (which falls
back to a built-in guide) load the config: pass --config, or drop a
config.yaml next to the binary (see Configuration below).
serve, doctor, call and catalog also accept --env-file ./.env — a
minimal KEY=VALUE parser applied before the config is loaded, so ${VAR}
references inside the config resolve from that file. The real process
environment always wins over the file.
Mcp-Session-Id)In http mode the gateway runs Streamable HTTP sessions: the reply to
initialize carries an Mcp-Session-Id header, and every request after it
— POST, the GET SSE stream, DELETE — must send that header back. Without it the
answer is 400; with an unknown or expired id, 404, which tells the
client to initialize again. A session is released by DELETE /mcp (204),
or after 30 minutes with no requests — an open SSE stream counts as activity and
keeps it alive.
MCP clients do all of this for you. For hand-made curl calls, take the header
from the initialize response and echo it back:
The session also makes the call log honest: every call is audited under the
clientInfo of the session that made it, so several HTTP clients are told apart
in calls.jsonl instead of sharing one blank client field.
elicitation, sampling, roots)When an upstream asks something mid-call — elicitation/create,
sampling/createMessage, roots/list — the question is delivered as an SSE
event on the GET /mcp stream of one session, and the client answers with
an ordinary POST carrying a JSON-RPC response with the same id and the same
Mcp-Session-Id. Only the session the question was put to may answer it; an
answer from any other session is ignored. If nobody has declared the capability
with a stream open, the upstream is refused right away in the shape the spec
prescribes ({"action":"decline"} for elicitation, -32601 for the other two)
rather than being left to time out — and the same happens if the session is
terminated while a question is outstanding.
Three consequences worth knowing:
-32603 and the
gateway exits with the error, as it did when it started them eagerly.tools/call can surface in the other's UI.The upstream side of the same exchange works over HTTP too: a remote MCP
server reached with url: may ask its question as an SSE frame — either on its
long-lived GET stream or interleaved into the stream answering one of the
gateway's own POSTs, which is where SDK servers put an elicitation/create
raised inside a tools/call. The gateway proxies it through the same pipeline
and sends the client's answer back as one ordinary POST carrying a JSON-RPC
response under the server's own request id. Such an upstream is told the
gateway's client capabilities by the same honest policy as a stdio one — a
capability is offered only when the gateway's own client declared it, and
doctor/call/catalog, which have no client at all, keep declaring exactly
{}. The answer POST is not retried: an upstream that does not get it falls
back on its own timeout.
The journal at log_file holds two kinds of line: one per tool call, and
one per operator event — a gateway state you would otherwise never learn
about. In stdio mode the MCP client owns the terminal, so the gateway's stderr is
invisible to you, and several of these conditions were only ever logged at debug
level. They are now written to the same file mcp-gate logs reads:
| Event | What it means |
|---|---|
upstream_start_failed | An upstream never came up; its tools are absent from the catalog. |
upstream_gave_up | The supervisor stopped restarting an upstream (attempts exhausted, restart disabled by a reload, or no liveness channel) and dropped it from the catalog. |
notification_dropped | A subscriber's buffer was full, so a forwarded notification was dropped — forwarding is non-blocking by design. |
server_request_dropped | An upstream asked something only the client could answer (elicitation/sampling/roots) and no transport took the question, so the tool call was refused on its behalf. |
sse_stream_unavailable | An HTTP upstream offers no GET SSE stream, so tools/list_changed from it will never arrive until the gateway restarts. |
catalog_collision | Two entries claimed the same client-facing tool/prompt name or resource URI; keep-first won and the loser is hidden from the client. |
catalog_bad_template | A resource URI template does not compile: it is listed to the client but can never match a read. |
result_truncation_skipped | A result exceeded max_result_bytes but had no truncatable text (e.g. images only), so it passed through whole. |
Events show up inline with calls, marked EVT; mcp-gate logs --events shows
only them, and --stats gains a per-event table. --tool and --status are
call-only filters, so events are excluded while either is set (--upstream
applies to both). One consequence worth knowing: notification_dropped names no
upstream — a drop is a property of the subscriber whose buffer was full, not of
whoever sent the notification — so --upstream X never shows it. Look for it
without that filter. Repeated drops are coalesced — the first one is written at
once, further ones within a minute are counted into the count= of the next
line for that key, and the remainder is flushed at shutdown. A line that carries
such a backlog says so in its detail=, naming the time of the oldest
occurrence it folds in — the line's own timestamp is the newest one, so the two
together bound when the burst actually happened.
Two practical notes:
log_file. With it empty the journal goes to stderr, which in stdio
mode belongs to the MCP client — the events would be written where you cannot
see them."kind" field older versions do not know, so mcp-gate logs from
≤ v0.4.0 renders them as sparse, mostly empty records.Nothing about this is visible to the MCP client: no error codes, result bodies or capabilities changed — the events go to the journal only.
The gateway reloads its configuration live on SIGHUP — no restart, no
dropped client connection. Edit config.yaml and send the signal:
On reload the gateway diffs the new config against the running upstreams and
applies the minimum change: newly added upstreams are launched, removed (or
enabled: false) ones are shut down, upstreams whose launch fields
(command/args/url/env/headers) changed are relaunched, and upstreams
where only the tool filter changed (allow/deny/rename, or the catalog
projection rules strip_annotations/strip_output_schema/max_description/
describe) are re-projected
without any restart. Call limits (rate_limit, max_concurrent,
max_result_bytes, call_timeout — global or per-upstream) are also applied
live: they never require a relaunch, the next call simply uses the new values.
Unchanged upstreams keep running untouched. A bad edit
(invalid YAML, failed validation) is logged and ignored — the currently running
config stays live, so a typo never takes the gateway down.
Behavioural note: since the gateway installs a SIGHUP handler, SIGHUP no longer terminates the process the way the OS default would. To stop the gateway use Ctrl-C, SIGINT, or SIGTERM.
SIGHUP is Unix-only. On Windows — or anywhere you would rather not send signals — use the opt-in polling alternative instead:
It stats the config file's mtime on that interval and applies the same reload path SIGHUP takes. Running it alongside the SIGHUP handler is safe.
Without --config, the gateway looks for config.yaml next to its own
binary (e.g. if mcp-gate is installed at /etc/gate/, it looks for
/etc/gate/config.yaml — regardless of the working directory it was launched
from). If that file doesn't exist and --config wasn't passed either, it
errors explicitly instead of starting an empty gateway. Relative paths inside
the config (log_file, skill_file, debug_payload_log) resolve against the
config file's own directory, not the current working directory.
Unknown keys are a startup error. The config is parsed strictly: a
misspelled or unrecognized key stops the gateway with the key name and its line
number, instead of being silently ignored as it once was. The concrete win: a
typo in enabled can no longer leave an upstream quietly running. Custom x-
scratch keys are rejected too — to share a block, put a YAML anchor on the first
real upstream and merge it (<<: *anchor) into the others; anchors and merge
keys work as usual.
An upstream is enabled by default: omit enabled: entirely and it is
launched like any other. To keep one out of the gateway without deleting its
config, disable it explicitly with enabled: false — it then appears
neither in tools/list nor in mcp-gate doctor's table. Careful: a valueless
enabled: (or enabled: null) reads as omitted, so commenting the value out
leaves the upstream running — only the literal false disables it.
Note: the "next to the binary" lookup uses the path of the running executable. Under
go run ./cmd ...that executable is a throwaway build in a temp directory, so the default lookup will not find yourconfig.yaml— pass--configexplicitly when usinggo run, or run a built binary.
Full example with every field — config.example.yaml.
The set of upstream servers is declared in YAML; secrets (tokens) go through
env/.env (${VAR} expansion at load time), never committed in the config.
Each upstream sets exactly one of command (stdio subprocess) or url
(HTTP server, Streamable HTTP) — the connection kind is inferred automatically.
MIT — see LICENSE.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/aimcpgate)<a href="https://allmcps.com/mcp/aimcpgate"><img src="https://allmcps.com/api/badge/aimcpgate?style=directory" alt="Aimcpgate on AllMCPs" /></a>