mcp-broker

io.github.NavinAgrawal由 GitHub 帳號 NavinAgrawal 發布v1.4.1更新於 Nov 3, 2026

Local MCP broker that exposes one compact entry for many upstream servers.

已驗證STDIO僅桌面開發者工具AI 與機器學習

概覽

AI 產生的概覽

本機 MCP 代理,把多個上游 MCP 伺服器收攏到一個精簡的 stdio 入口,提供搜尋、描述、呼叫、狀態與關閉工作階段工具。

可以做什麼
  • 透過代理介面搜尋並描述上游工具,依需求取得工具 schema
  • 經代理路由呼叫上游工具,可在伺服器端裁剪回傳結果
  • 查看目前設定可見的上游狀態、驗證探測結果與最近錯誤,且不會啟動工具
  • 釋放呼叫端自己的按工作階段上游程序,不影響共用上游
  • 依需求啟動、重用、隔離並清理上游 MCP 伺服器,支援設定層級的工具預算與變更類工具閘門
  • 產生、備份與回復 MCP 用戶端設定,並提供 LaunchAgent、systemd 與 Windows 排程工作安裝流程
適用情境
適合開發者的 MCP 用戶端(如 Codex、Claude Code、AGY 等)掛載的上游伺服器與工具定義過多、每個工作階段都嫌臃腫時使用;也適合需要統一管理重複的上游程序、分散的 OAuth 狀態與殘留程序的場景。
執行需求
以本機程序在使用者電腦上執行,可透過 PyPI(pipx、uv 或 Homebrew)或複製儲存庫安裝。需要以 python3 提供的 Python 3.10 或更新版本、make,以及供 Makefile 流程使用的儲存庫副本;npm 類上游需要 Node.js 與 npx。macOS 的 LaunchAgent 需要 launchctl,Linux 與 Windows 分別使用 systemd 或 PowerShell 排程工作。需從公開範本建立私有 YAML 設定。
安裝前請注意
它會在你的電腦上啟動與停止其他 MCP 伺服器,並在家目錄下的執行期根目錄寫入狀態、日誌、通訊端與產生的用戶端設定。設定產生會修改 MCP 用戶端設定檔,請使用試跑、備份與回復步驟。不要把密鑰值寫進設定,應使用環境變數名稱或密鑰檔案。變更類上游預設隱藏,需設定允許清單才會暴露;不支援託管執行。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 mcp-broker,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

mcp-broker

[mcp-broker routing backbone brand header]

mcp-broker is a local Model Context Protocol process broker for MCP clients.

Think PgBouncer for MCP: one stable local endpoint in front of many upstream MCP servers. The broker owns upstream startup, reuse, cleanup, profile exposure, status, and safe tool routing.

The core idea is simple: do not make every agent session load every upstream tool definition before the user asks a task.

Why this exists

AI coding sessions with many MCP servers tend to accumulate the same problems:

  • every client config repeats the same MCP server list
  • every new session can start duplicate upstream processes
  • OAuth, browser state, local files, and database handles spread across tools
  • raw tool lists consume context before the task begins
  • hosted connector caches can duplicate local MCP tools
  • orphaned MCP processes survive after client sessions exit

mcp-broker puts a small broker facade in front of those upstreams. It is not a hosted workflow builder; it is local infrastructure for keeping MCP clients small, predictable, and under one config contract.

text
Client profile        |        | one local MCP entry        v  mcp-broker-client        |        | Unix socket        v  mcp-broker-daemon        |        | profile gates, namespace routing, status, cleanup        v  upstream MCP servers

The client sees a small set of broker tools:

text
broker_search_toolsbroker_describe_toolbroker_call_toolbroker_statusbroker_close_session

The upstream MCPs still exist. They are discovered and called through the broker when a task needs them.

Measured context reduction

On 2026-05-24, the measured Codex setup went from many raw MCP and hosted app tool definitions to one broker facade plus a pruned codex_apps cache.

SurfaceBeforeAfterReduction
Direct Codex MCP server entries11190.91%
MCP tool definitions414499.03%
Hosted codex_apps tool definitions1953980.00%
Combined always-loaded tool definitions6094392.94%
Combined serialized tool payload bytes1,026,171185,87781.89%
Combined o200k_base tool tokens276,98945,28183.65%

The 92.94% number is a tool-definition count reduction. The 83.65% number is a token reduction for canonical serialized tool payloads measured with tiktoken o200k_base.

See docs/context-reduction-measurement.md for evidence and caveats.

What it does

  • Runs one local broker daemon over a Unix socket.
  • Exposes one lightweight stdio client shim to MCP clients.
  • Starts upstream MCP servers on demand.
  • Reuses shared upstreams across sessions when configured.
  • Isolates per-session upstreams when state must not be shared.
  • Maps upstream tools into stable namespaces.
  • Exposes compact search, describe, call, status, and caller-bound session-close tools.
  • Enforces profile-level tool budgets and exposure gates.
  • Blocks mutating upstream exposure unless a profile allowlist grants it.
  • Stores runtime state under $HOME/mcp/mcp-broker, outside the repo.
  • Renders MCP client config entries with dry-run, backup, and rollback.
  • Provides LaunchAgent install and uninstall flows for macOS.
  • Provides Linux systemd user-service render, install, unload, and removal flows.
  • Provides Windows PowerShell Scheduled Task render, install, and removal flows.
  • Includes unit, journey, live, and e2e tests through Makefile targets.

Core differentiators:

  • Profile-scoped exposure: each MCP client gets a configured view of upstreams instead of every tool by default.
  • Mutating-tool gates: mutating upstreams stay hidden until a profile allowlist grants access.
  • Lifecycle ownership: shared and per-session upstreams are started, watched, stopped, and reaped by the broker.
  • Client parity checks: rendered profiles can be validated through the same compact broker facade before config is applied.

Who this is for

Use mcp-broker if you:

  • use Codex, Claude Code, AGY CLI, or other MCP clients
  • have more MCP tools than you want in every session
  • need shared local MCP servers without duplicate process startup
  • want one place for OAuth state, browser state, sockets, logs, and cleanup
  • need per-client profiles instead of the same tool list everywhere
  • want a small broker facade instead of raw upstream tool dumps

This repo is not an enterprise MCP control plane. It is local desktop infrastructure for developer-agent workflows.

Current status

Implemented:

  • YAML config loading from config/broker.private.yaml, created from config/broker.example.yaml.
  • Strict YAML contract validation for runtime, clients, profiles, upstreams, and policy blocks.
  • Public JSON Schema validation through config/broker.schema.json.
  • Runtime path derivation from runtime.root.
  • Tool namespace mapping from configured upstream prefixes.
  • Local upstream subprocess lifecycle management and process-group cleanup.
  • Broker daemon over Unix socket.
  • MCP client shim and renderers for configured MCP client profiles, including Codex, Claude, and AGY.
  • AGY profile rendering to .gemini/config/mcp_config.json, including its MCP allowed-server policy.
  • Dry-run client config rendering, apply-time backups, and rollback.
  • LaunchAgent render and install scripts with dry-run defaults.
  • Compact broker facade for search, describe, call, status, and caller-bound session close.
  • Profile validation from YAML smoke probes.
  • Discovery parity checks between compact client profiles.
  • Public and maintainer quality gates through Makefile targets.
  • Shared-runtime guardrail contracts through P3.8 E2E proof while hosted execution remains disabled by default.

Wiring status:

  • Codex is wired through the broker.
  • Claude is wired through the broker after profile validation and manual /mcp acceptance.
  • AGY is wired through the broker by rendering .gemini/config/mcp_config.json.

Public release status:

  • The repo is designed to stay public-safe.
  • Private upstream inventory, account paths, OAuth state, secrets, sockets, logs, and generated client configs stay outside git.
  • Stable release metadata is validated by make release-version-check; publication proof is tracked in docs/distribution.md.
  • Docker image support is available for container-friendly configs. Docker MCP Catalog submission still requires Docker review.
  • MCPB metadata is present at mcpb/manifest.json for local directory review.

See ROADMAP.md for public-facing release work.

Architecture

mcp-broker has three runtime layers:

LayerResponsibility
Client shimPresents one stdio MCP server entry to each MCP client and forwards JSON-RPC over the broker socket.
Broker daemonOwns profile gates, namespace routing, upstream lifecycle, status, logging, and cleanup.
Upstream MCP serversRun as configured stdio, HTTP, streamable HTTP, or SSE connectors with shared or per-session process policy.

The config file is the contract. Profiles decide exposure, upstreams define transport and lifecycle behavior, and smoke probes define safe read calls for validation.

Comparison

ApproachBest fitTradeoff
Raw MCP client configSmall setups with a few tools.Every session loads the full tool list and each client repeats config.
Simple MCP proxyForwarding one server to one client.Does not own upstream lifecycle, profile budgets, or cross-client cleanup.
Hosted app connectorsSaaS tools managed by the client provider.Local MCP state and cross-client parity remain outside user control.
mcp-brokerLocal developers with many upstream MCPs across MCP clients.Adds a local daemon and config contract that must be installed and monitored.

Screenshots Or GIF

The quickstart flow should look like this:

[mcp-broker quickstart terminal]

text
make config-initmake config-validatemake broker-statusmake codex-facade-smoke

In an MCP client, /mcp should show one mcp-broker entry. Use broker_status to inspect profile-visible upstream state.

Quickstart

Prerequisites:

  • macOS with launchctl for LaunchAgent use.
  • Python 3.10 or newer available as python3.
  • make.
  • Node.js and npx for npm-based upstream MCP servers.
  • A clone of this repo.

Package installs:

bash
pipx install mcp-brokeruv tool install mcp-brokerbrew tap ${HOMEBREW_TAP_REF}brew install mcp-broker

Homebrew installs the same console scripts as the Python package. Package installs do not write MCP client config; client wiring stays an explicit Makefile action.

Docker is for container-friendly configs:

bash
docker build -t mcp-broker:local .docker run --rm -i mcp-broker:local

Local stdio clients and MCPB-style installs use the package-owned lifecycle:

bash
mcp-broker stdio --init-if-missing

Create the local venv, install dependencies, and verify runtime layout:

bash
make setup

Create private config from the public template:

bash
make config-init

config-init creates the destination directory when needed and copies the public template as the starting point. It does not import local MCP inventory, user paths, or secrets.

Edit config/broker.private.yaml for local upstreams. Keep secret values out of config. Use environment variable names or files under:

text
$HOME/mcp/mcp-broker/secrets/

Run the quality gate:

bash
make quality-gate

Validate the configured YAML contract:

bash
make config-validate

Start the broker:

bash
make broker-start

Check status:

bash
make broker-status

For the full install flow, see docs/install.md. For a clone-to-running adoption flow, see docs/adoption-guide.md#clone-to-running-path. For shared-runtime boundaries, see docs/shared-runtime-guardrails.md. P3.8 E2E proof covers tenant isolation, authz denial, quota denial, session affinity, audit events, rollback, degraded mode, local-only routing, and shared-eligible routing. Hosted execution remains unsupported in the public local broker.

Runtime layout

Default runtime root:

text
$HOME/mcp/mcp-broker/|- backups/|- logs/|- renders/|- run/|- secrets/|- sockets/`- state/   `- upstreams/

Runtime files are not repo files. Upstream OAuth state, browser state, secret files, sockets, logs, rendered client configs, backups, and daemon state belong under the runtime root.

See docs/runtime-layout.md.

Client wiring

Back up a client config:

bash
make config-backup CLIENT=codex

Dry-run render:

bash
make config-render CLIENT=codex CONFIG_RENDER_APPLY=0

Apply after reviewing the rendered file under $HOME/mcp/mcp-broker/renders/:

bash
make config-render CLIENT=codex CONFIG_RENDER_APPLY=1

Rollback:

bash
make config-rollback CLIENT=codex

Use CLIENT=claude or CLIENT=agy after that profile smoke passes and that client is intended to use the broker. For new JSON-based MCP clients, generate a starter block:

bash
make profile-snippet NEW_PROFILE=local-client NEW_CLIENT_FORMAT=mcp-settings-json

See docs/add-profile.md for the full new-profile flow.

Compact broker facade

The compact facade keeps chat-facing profiles small:

ToolPurpose
broker_search_toolsSearch configured upstream tools by query. Results carry name, description, upstream, purpose, tags, and mutating flag; the heavy inputSchema is omitted and fetched on demand from broker_describe_tool.
broker_describe_toolReturn schema and metadata for one upstream tool.
broker_call_toolCall one upstream tool through broker routing. Accepts an optional projection ({"paths": [...], "max_array_items": N}) that trims the response server-side before it reaches the client.
broker_statusShow profile-visible upstream state, passive auth probes, and last errors without starting tools.
broker_close_sessionRelease caller-owned per-session upstream processes without stopping shared upstreams or another client session.

Codex /mcp shows the single mcp-broker entry by design. Per-upstream visibility, status, and socket path come from broker_status.

Profiles and safety

Profiles decide which upstreams a client can see and call.

Supported concepts:

  • max_tools protects clients from huge tool lists.
  • compact_tools_enabled exposes broker facade tools instead of raw upstream tools.
  • broker_tool_name_style adapts broker facade names for clients that cannot surface dotted tool names.
  • result_size_chars declares anthropic/maxResultSizeChars on broker_call_tool (at most 500000), so Claude Code keeps larger results inline.
  • result_budget_chars sends mcp-broker/result_budget_chars in the _meta of every forwarded tools/call, so upstreams can size answers for the client. See docs/add-profile.md.
  • mcp_allowed_servers renders client settings for MCP clients that require an explicit server allowlist.
  • allow_mutating_upstreams is required before a mutating upstream can be exposed.
  • shared mode reuses one upstream process where shared account state is acceptable.
  • per_session mode isolates upstream state per client session.
  • per_call mode starts a fresh stdio process for each tool call or tool-list operation, then stops that process before returning.
  • disabled mode keeps compatibility records without exposing the upstream.

Status reports active_call_count for in-flight per_call operations, including tool discovery. It returns to zero after success, failure, or timeout cleanup. This count is separate from session_count and is not a count of saved threads. Reading status does not start an upstream; profile-hidden upstreams stay hidden.

Protected surfaces such as OAuth, browser state, filesystem roots, and databases require explicit config and validation. Public examples stay disabled or placeholder-based.

See docs/security-review.md and docs/upstream-compatibility-matrix.md. For a deeper safety checklist, see docs/safety.md.

Config contract

The public template is config/broker.example.yaml. The matching JSON Schema is config/broker.schema.json.

Supported top-level sections:

yaml
schema_version: 1runtime: {}broker: {}profiles: {}clients: {}upstreams: {}

The loader rejects unknown keys. Runtime placeholders such as {runtime.root}, {runtime.state_dir}, and {runtime.secrets_dir} can be used in upstream command, args, working directory, and env file paths.

make config-validate checks the selected CONFIG_PATH against the public JSON Schema first, then runs the runtime loader so semantic rules are enforced from the same code path the broker uses.

Each enabled upstream exposed to a profile should define a safe smoke probe:

yaml
smoke:  query: read example graph  tool: example-store.read_graph  arguments: {}  call: true

make profile-validation PROFILE=<profile> validates every enabled upstream visible to that profile through broker_status, broker_search_tools, broker_describe_tool, and the configured safe broker_call_tool.

Codex operator acceptance

Repo-owned tests validate broker behavior through the local client shim. The last Codex-specific check has to run inside an active Codex session because that is where the deferred MCP wrapper tools exist.

Generate the current acceptance steps from YAML:

bash
make codex-deferred-acceptance

The target reads the configured smoke probes and prints the exact mcp__mcp_broker__ wrapper calls for search, describe, and safe call. It does not invoke Codex, does not call an external LLM session, and is not part of make quality-gate.

See docs/codex-deferred-tool-acceptance.md.

LaunchAgent

Render without writing:

bash
make launchagent-install

Apply and load:

bash
make launchagent-install LAUNCHAGENT_APPLY=1make launchagent-loadmake broker-status

Unload or remove:

bash
make launchagent-unloadmake launchagent-uninstall LAUNCHAGENT_APPLY=1

systemd

Linux user-service install uses the same runtime root and config path contract:

bash
make systemd-installmake systemd-install SYSTEMD_APPLY=1make systemd-load

For package installs, set MCP_BROKER_DAEMON_COMMAND to the installed daemon path before applying the service.

Windows

Windows startup uses PowerShell Scheduled Task commands with the same runtime root and config path contract:

bash
make windows-installmake windows-install WINDOWS_APPLY=1make windows-load

Remove it with:

bash
make windows-unloadmake windows-uninstall WINDOWS_APPLY=1

Test and release gates

Run all test tiers:

bash
make test

Run the public quality gate:

bash
make quality-gate

The coverage gate uses line and branch coverage for Python source.

Run the release gate when preparing a tag:

bash
make release-gate

release-gate runs package, smoke, and mutation checks. Mutation receives a release-scoped child count derived from LOCAL_CPU_BUDGET and RELEASE_GATE_JOBS, so it does not take the full CPU budget while other release children run. Mutation runs public unit and journey tests last and writes var/quality/mutation_stats.json with total counts, score, and ranked blocked_by_file entries. On macOS, the release gate runs mutation inside a Linux container to avoid local mutmut fork failures. E2E tests remain in make quality-gate.

Run smoke and runtime cleanup checks:

bash
make config-validatemake broker-smokemake broker-stopmake broker-reapmake doctormake release-smoke

Release or client config apply should wait for:

  • make quality-gate
  • make config-validate
  • make broker-smoke
  • dry-run config render for each intended client
  • rollback test
  • make release-smoke
  • make release-gate before tagging
  • make doctor with no stale broker-owned resources

See docs/release-checklist.md.

Public commands

These targets use this repo plus declared Python and Node prerequisites:

For source contributions, install gitleaks on PATH and run make hooks-install in each checkout. The tracked pre-commit hook requires a redacted staged secret scan, then runs commit-tier affected tests through Make. Missing scanner tools, empty staged scope, and scan or test failures block the commit. GITLEAKS and PYTHON select the scanner and maintainer interpreter. Installation uses Git's worktree-specific config and refuses unknown existing hooks or common core.worktree/bare settings that need migration. No hosted workflow is started.

bash
make setupmake config-initmake testmake test-unitmake test-journeymake test-livemake test-e2emake test-covmake precommitmake quality-gatemake release-gatemake config-validatemake broker-smokemake broker-startmake broker-statusmake broker-stopmake broker-reapmake doctormake config-backupmake codex-app-policymake config-rendermake config-rollbackmake tools-countmake facade-smokemake codex-facade-smokemake claude-facade-smokemake agy-facade-smokemake profile-validationmake codex-profile-validationmake claude-profile-validationmake agy-profile-validationmake discovery-paritymake codex-claude-discovery-paritymake codex-deferred-acceptancemake launchagent-installmake launchagent-loadmake launchagent-unloadmake launchagent-uninstallmake systemd-installmake systemd-loadmake systemd-unloadmake systemd-uninstallmake windows-installmake windows-loadmake windows-unloadmake windows-uninstallmake linux-container-smokemake windows-powershell-smokemake release-smokemake mutationmake mutation-linux

make quality-gate is repo-local. It does not call personal scripts outside this repo.

make codex-deferred-acceptance is maintainer-only. It does not invoke Codex or an external LLM session. It reads the same YAML smoke probes and prints the exact mcp__mcp_broker__ deferred wrapper calls to run inside an active Codex session. See docs/codex-deferred-tool-acceptance.md.

Project tree

text
mcp-broker/|- .gitignore|- Makefile|- README.md|- pyproject.toml|- requirements.txt|- config/|  |- broker.example.yaml|  |- broker.private.yaml        # local, ignored by git|  `- broker.schema.json|- docs/|- registry/|- scripts/|  `- check_mutation_stats.py|- src/|  `- mcp_broker/|- tests/|  |- unit/|  |- journey/|  |- live/|  |- e2e/|  `- support/`- var/                         # tracked skeleton; generated contents ignored

Generated reports stay under var/, especially var/coverage/, var/test-logs/, and var/quality/.

Docs

Design rules

  • Keep upstream definitions in central config.
  • Keep runtime state under $HOME/mcp/mcp-broker.
  • Keep private upstream inventory in config/broker.private.yaml, which is ignored by git.
  • Keep secret values out of config and source.
  • Do not hardcode personal paths in source, tests, docs, or public config.
  • Run build, test, runtime, and config operations through the Makefile.

來源:README.md,提交 5245398

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.4.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分