mcp-context-router
Reusable MCP bootstrap and routing toolkit for repo-local agent workflows.
It packages a practical pattern:
- mcporter is the live MCP backend.
- context-mode is the default high-output wrapper.
- repo-local
mcp_servers.json becomes the strong MCP catalog with category + decision guidance.
- agent snippets / injected instructions teach Codex, Claude, and similar agents how to choose the right MCP before tool calls.
This is designed for repos where MCP context is not natively loaded into the agent and you want a lighter, more explicit workflow.
Prerequisites
The generated wrapper currently expects:
Use mcp-context-router doctor <repo> to verify those prerequisites after bootstrap.
What it creates
When you run bootstrap, it generates:
mcp_servers.json
scripts/mcp/discover.sh
docs/MCP.md
docs/integrations/mcp-tools.md
.mcp-context-router.json
.mcp-context-routerrc.json
.mcp-context-router/agents/*.md
- optional generated MCP instructions appended into repo or global agent docs
Core idea
Use MCP in this order:
- Discover by category
- Inspect the server
- Inspect the tool
- Call the tool
That means the preferred flow is:
<repo-mcp-command>
<repo-mcp-command> <domain>
<repo-mcp-command> <server>
<repo-mcp-command> <server> <tool>
<repo-mcp-command> call <server> <tool> '{"...":"..."}'
<repo-mcp-command> --doctor [server]
Where <repo-mcp-command> is usually one of:
pnpm mcp
npm run mcp
bun run mcp
Why this exists
Non-native MCP setups often have two problems:
- the agent does not start with the MCP schema in-context
- agents overuse raw MCP output and waste context
This package fixes that by:
- generating a repo-local catalog with strong “use this when...” wording
- steering discovery through context-mode
- giving agents a task-to-category-to-server decision path
- rendering agent instructions with the repo’s package-manager command (
pnpm, npm run, or bun run)
Install
Use as a package
npm install -D mcp-context-router
Or run directly:
npx mcp-context-router init .
CLI
mcp-context-router init <repo> [--non-interactive] [--include-global] [--include a,b] [--exclude a,b] [--agent-exploration] [--scope repo|global|snippet]
mcp-context-router sync <repo>
mcp-context-router doctor <repo>
mcp-context-router install-agent <repo> <codex|claude|repo> [--scope repo|global|snippet]
mcp-context-router install-plugin <repo> [codex|claude]
mcp-context-router uninstall-plugin <repo> [codex|claude]
mcp-context-router prune-global-mcp [--dry-run] [--apply] [--all-global] [--prune-servers a,b]
mcp-context-router uninstall <repo>
Recommended bootstrap
mcp-context-router init /path/to/repo
Defaults:
- interactive-first bootstrap
- repo-local MCP catalog generation
- context-mode-first discovery guidance
- agent exploration is off by default and opt-in via
--agent-exploration
- generated Codex + Claude snippets
- repo AGENTS injection by default
- global MCP discovery disabled by default unless explicitly enabled
If you want bootstrap to pull from user-level Codex and Claude MCP config too:
mcp-context-router init /path/to/repo --include-global
If you explicitly want agent-assisted categorization during bootstrap:
mcp-context-router init /path/to/repo --agent-exploration
Agent installation modes
Repo scope
Append generated MCP operating instructions into <repo>/AGENTS.md.
mcp-context-router install-agent /path/to/repo codex --scope repo
Global scope
Append generated MCP operating instructions into the agent’s global doc:
- Codex:
~/.codex/AGENTS.md
- Claude:
~/.claude/CLAUDE.md
mcp-context-router install-agent /path/to/repo codex --scope global
Snippet only
Only write .mcp-context-router/agents/*.md without injecting anything.
mcp-context-router install-agent /path/to/repo claude --scope snippet
Plugin install
The package can wire its own plugin and skill surfaces into your local agent home.
Codex
mcp-context-router install-plugin /path/to/mcp-context-router codex
mcp-context-router uninstall-plugin /path/to/mcp-context-router codex
What it creates:
- plugin symlink:
~/.codex/.tmp/plugins/plugins/xan-mcp → repo
- skill symlinks:
~/.codex/skills/plugin--local--xan-mcp--* → repo skills
Claude
mcp-context-router install-plugin /path/to/mcp-context-router claude
mcp-context-router uninstall-plugin /path/to/mcp-context-router claude
What it creates:
- skill symlinks:
~/.claude/skills/plugin--local--xan-mcp--* → repo skills
The skill symlinks make xan-mcp-routing available to Claude persistently across sessions.