mcp-aggregator

mcp-aggregator

Aggregates multiple MCP servers into a single Streamable HTTP endpoint, compressing tools to manage registration limits.

Category
访问服务器

README

mcp-aggregator

Builds a container image that presents any number of MCP servers to a local client as a single Streamable HTTP endpoint, collapsed behind the two tools that mcp-compress-router exposes: get_tool_schema and invoke_tool.

Agent clients cap the number of registered tools — 128 for GitHub Copilot CLI — and every registered tool consumes context whether or not it is called. Routing servers through the compressor keeps them all reachable at a fixed cost of two tools.

Architecture

flowchart LR
    client["MCP client"]

    subgraph container["container"]
        sg["supergateway<br/>PID 1"]
        router["mcp-compress-router"]
        sg -->|stdio| router
    end

    gh["github<br/>http"]
    fs["filesystem<br/>stdio"]
    int["internal<br/>streamable-http"]

    client -->|"Streamable HTTP<br/>127.0.0.1:20000/stream"| sg
    router --> gh
    router --> fs
    router --> int

Configuration is baked into the image at build time as build secrets, so a running container needs no host configuration beyond a state volume.

Requirements

  • Node.js >= 24 on the build host. build.cjs itself needs only 20.12 for process.loadEnvFile(), but the OAuth login path runs mcp-compress-router through npx, and that package requires Node 24
  • Podman, or Docker via build.engine
  • npm install once, for the ajv schema validator

Configuration

build.json is gitignored and must be created before the first build. It is validated against build.schema.json on every run; the $schema reference enables editor completion and inline validation.

Key Purpose
build.engine podman or docker
build.name / build.tag Image coordinates, overridable with the IMAGE_NAME environment variable
build.port Streamable HTTP port, used inside the container and for the published host binding. Optional, default 20000
build.args --build-arg values, and the source of truth for the pinned SUPERGATEWAY_VERSION and MCP_ROUTER_VERSION. The ARG defaults in the Containerfile are fallbacks
build.podman.generate_quadlet_unit Emit a <name>.container systemd unit alongside the image
mcp.servers Downstream servers, written verbatim into the router's mcp.json under mcpServers
mcp.oauth Server names requiring an interactive login on the build host

A server is stdio and requires command, or http / streamable-http and requires url. Unknown fields pass through to mcp.json untouched, so router features absent from the schema still work. Recognised extras include compressionLevel, allowedTools and disabledTools (picomatch globs), and enabled.

{
  "$schema": "build.schema.json",
  "build": {
    "engine": "podman",
    "name": "mcp-aggregator",
    "tag": "latest",
    "port": 20000,
    "args": [
      "MCP_ROUTER_VERSION=1.5.2",
      "SUPERGATEWAY_VERSION=3.4.3"
    ],
    "podman": {
      "generate_quadlet_unit": true
    }
  },
  "mcp": {
    "servers": {
      "github": {
        "type": "http",
        "url": "https://api.githubcopilot.com/mcp/",
        "description": "GitHub MCP Server",
        "compressionLevel": "high",
        "headers": {
          "Authorization": "Bearer ${GITHUB_MCP_PAT}"
        }
      },
      "filesystem": {
        "type": "stdio",
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/server-filesystem", "/data"],
        "env": {
          "LOG_LEVEL": "${FS_LOG_LEVEL:-warn}"
        },
        "disabledTools": ["*write*", "*delete*"]
      },
      "internal": {
        "type": "streamable-http",
        "url": "${INTERNAL_MCP_URL}",
        "compressionLevel": "max",
        "allowedTools": ["search_*", "get_*"],
        "oauth": {
          "clientId": "${INTERNAL_CLIENT_ID}",
          "scope": "read",
          "callbackPort": 33418
        }
      }
    },
    "oauth": ["internal"]
  }
}

Placeholders

Credentials belong in placeholders, not in build.json. Any ${VAR} in mcp.servers resolves against the environment, falling back to a .env file in the repository root. ${VAR:-default} is supported, and an unset placeholder without a default aborts the build. Environment values take precedence over .env.

.env and credentials.json are gitignored and excluded from the build context. They reach the image only through --secret mounts, which leave no trace in any layer.

Building

npm install          # once
npm run build        # or: node build.cjs
flowchart TD
    bj["build.json"] --> val["validate against<br/>build.schema.json"]
    val --> exp["resolve placeholders<br/>from environment and .env"]
    exp --> mj["mcp.json<br/>temp file"]

    cache["credentials.json<br/>repository root"] --> gate{"tokens missing for<br/>any mcp.oauth server?"}
    gate -->|yes| login["interactive login<br/>on build host"]
    login --> cj["credentials.json<br/>temp file"]
    gate -->|no| cj

    mj --> rev["CONFIG_REVISION<br/>digest of both files"]
    cj --> rev
    rev --> eng["engine build<br/>with both files as secrets"]
    eng --> img["image"]
    eng --> unit["name.container unit"]

build.cjs invokes the engine directly with no connection argument, so with Podman the image is created on whichever connection is currently default. podman system connection list shows which that is.

OAuth

The router's authorization-code flow needs a browser, which a container build cannot provide, so login runs on the build host. The resulting token store is cached in credentials.json at the repository root and later builds are non-interactive. Only servers with no stored access_token are authorized:

npm run login    # or: node build.cjs --login — re-authorize every server in mcp.oauth

Deploying

With generate_quadlet_unit enabled, a successful build writes mcp-aggregator.container:

mkdir -p ~/.config/containers/systemd
cp mcp-aggregator.container ~/.config/containers/systemd/
systemctl --user daemon-reload
systemctl --user start mcp-aggregator

Quadlet honours [Install], so daemon-reload is sufficient for the unit to start at boot and there is no enable step. A rootless service that must survive logout also needs loginctl enable-linger "$USER" once.

The unit binds to 127.0.0.1 only, mounts the host CA bundle read-only, keeps router state in a named volume, and runs with RunInit=true.

Connecting a client

http://127.0.0.1:20000/stream

The path is set in the generated launcher and is not supergateway's default of /mcp. The port follows build.port.

Runtime behaviour

Configuration storage

The named volume holds router state across rebuilds, which means image content written beneath it is seeded exactly once. The two configuration files therefore live in different places:

flowchart LR
    subgraph vol["named volume — persists across rebuilds"]
        link["mcp.json<br/>symlink"]
        cred["credentials.json<br/>rewritten on token refresh"]
    end

    subgraph img["image layer — replaced on every build"]
        cfg["/home/mcp/config/mcp.json"]
    end

    link --> cfg

credentials.json persists because the router rewrites it whenever a token refreshes, and those tokens must outlive a rebuild. mcp.json is a symlink out to plain image content, so a rebuild always supplies the current server configuration.

Layer caching

Container engines do not invalidate a cached RUN when the contents of a mounted secret change. build.cjs hashes the generated mcp.json and credentials.json and passes the digest as CONFIG_REVISION, so that layer rebuilds when the configuration changes and only then.

Entrypoint

Exec-form ENTRYPOINT performs no variable substitution, so the Containerfile writes /usr/local/bin/entrypoint at build time with build.port already substituted. The script execs supergateway, which therefore remains PID 1 and receives signals directly. It exists only inside the image.

Sessions

supergateway runs in stateful mode, so one router process serves every session. In stateless mode it starts a router per session, and concurrent processes overwrite each other's refreshed OAuth tokens.

Health

supergateway registers --healthEndpoint and --cors only for SSE and WebSocket output modes, so neither is available over Streamable HTTP. The quadlet restarts the container when the process exits, and cannot detect a process that is running but unresponsive.

Build context

The Containerfile has no COPY, and .containerignore excludes everything except the Containerfile and files matching podman-build-secret-*. Both negations are load-bearing. With * alone the build cannot resolve the Containerfile, and podman-remote transports --secret sources inside the context tarball under generated names of that form, so excluding them fails the build with a server-side rename error. Docker sends secrets over the BuildKit session rather than the context, where the second negation is inert.

Files

Path Role
build.cjs Build driver: validate, resolve, authorize, build, emit unit
build.json Build and server configuration (gitignored)
build.schema.json JSON Schema for build.json
Containerfile Image definition
.containerignore Deny-all with a single exception
.env Placeholder values (gitignored)
credentials.json Cached OAuth token store (gitignored, created on first login)
mcp-aggregator.container Generated Quadlet unit (gitignored)

Licence

MIT © Džiugas Eiva

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选