On-demand tool discovery for all your MCPs and per-subagent MCP controls to preserve context window.
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
A Model Context Protocol (MCP) gateway that aggregates multiple MCP servers and provides policy-based access control for agents and subagents. Solves Claude Code's MCP context window waste by enabling on-demand tool discovery instead of loading all tool definitions upfront.
list_servers toolget_server_tools, execute_tool, middleware, metrics, hot reload, OAuth supportCurrent Version: M1-Core Complete (with OAuth)
When multiple MCP servers are configured in development environments (Claude Code, Cursor, VS Code), all tool definitions from all servers load into every agent's and subagent's context window at startup:
The Agent MCP Gateway acts as a single MCP server that proxies to multiple downstream MCP servers based on configurable per-agent rules:

The gateway sits between agents and downstream MCP servers, exposing only 3 lightweight tools. When an agent needs specific functionality, it discovers available servers and tools through the gateway, which filters visibility based on policy rules - agents only see servers and tools they have access to. This reduces each agent's context window to only relevant tools, while the gateway handles proxying authorized requests to downstream servers.
View detailed diagram with examples β (includes downstream servers, tools, and gateway rules examples)
get_*, *_user)get_gateway_status (debug mode only)This generates two template files ready to customize:
mcp.json - Your downstream MCP servers (Brave, Postgres, etc.)mcp-gateway-rules.json - Per-agent access policies (who can use which servers/tools)For local development: See Development section.
After running uvx agent-mcp-gateway --init (see Installation), edit the generated template files:
See Configuration section for detailed examples and Configuration File Discovery for alternative file locations.
Claude Code CLI:
Manual configuration:
Note: The env variables are optional if using default config locations. See Environment Variables Reference for all options.
The gateway's tool descriptions are self-documenting, but for proper access control you should configure how your agents identify themselves. Choose the approach that fits your use case:
For different agents with different permissions, configure each agent to pass its identity.
Add this to your agent's system prompt (e.g., CLAUDE.md, .claude/agents/agent-name.md):
Replace YOUR_AGENT_NAME with your agent's identifier (e.g., "researcher", "backend", "admin").
Examples: See .claude/agents/researcher.md and .claude/agents/mcp-developer.md for complete configuration examples.
For simpler setups where all agents should have the same permissions, or when using MCP clients without system prompt configuration (e.g., Claude Desktop), configure a default agent using either method:
Option A: Environment Variable
Note: The agent specified (e.g., "developer") must exist in your .mcp-gateway-rules.json file with appropriate permissions.
Option B: "default" Agent in Rules
Note: Allowing all servers ("servers": ["*"]) without specifying tool restrictions grants access to all tools on all servers.
With either approach, agents can omit agent_id in tool calls - the gateway uses your configured default agent automatically.
The gateway searches for configuration files in this order:
GATEWAY_MCP_CONFIG environment variable (if set).mcp.json in current directory~/.config/agent-mcp-gateway/.mcp.json (home directory)./config/.mcp.json (fallback)GATEWAY_RULES environment variable (if set).mcp-gateway-rules.json in current directory~/.config/agent-mcp-gateway/.mcp-gateway-rules.json (home directory)./config/.mcp-gateway-rules.json (fallback)Tip: Use agent-mcp-gateway --init to create the home directory configs on first run.
The gateway requires two configuration files:
File: mcp.json (searched in multiple locations)
Defines the downstream MCP servers the gateway will proxy to. Uses the standard MCP config format compatible with Claude Code and other coding agents:
No reviews yet β be the first to share how this listing worked for you.
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/agent-mcp-gateway)<a href="https://allmcps.com/mcp/agent-mcp-gateway"><img src="https://allmcps.com/api/badge/agent-mcp-gateway?style=directory" alt="Agent MCP Gateway on AllMCPs" /></a>