MCP Gateway
MCP Gateway
ClaudeとMCPサーバーの間に配置する遅延読み込みプロキシです。起動時にすべてのサーバーを読み込む(何百ものツールスキーマをコンテキストにダンプし、トークンを浪費する)代わりに、ゲートウェイは4つの軽量なツールのみを公開します。バックエンドサーバーは、実際に必要になったときにのみ起動します。
以前: 10個のMCPサーバー = すべての会話に200以上のツールスキーマが読み込まれ、数千トークンが無駄になる。
以後: ゲートウェイ配下に10個のMCPサーバー = 4つのツールスキーマのみが読み込まれる。各サーバーはオンデマンドで起動する。
問題点
Claude Codeに追加するすべてのMCPサーバーは、そのすべてのツールを事前に登録します。一般的なサーバーには10〜30個のツールがあり、それぞれに完全なJSONスキーマが含まれています。10個のサーバーがあれば、質問をする前に100〜300個のツール定義がコンテキストウィンドウを消費してしまいます。
ほとんどの会話では1〜2個のサーバーしか使用されません。残りは不要な重荷となります。
Related MCP server: MCP Gateway
仕組み
ゲートウェイはClaudeに対して4つのツールを公開します。
ツール | 機能 |
| 利用可能なサーバーとそのステータスを表示する |
| サーバーに接続し、そのツールを検出する |
| 接続されたサーバー上のツールを呼び出す |
| サーバーを再接続する(コードの変更を反映する) |
Claudeがサーバーを必要とすると、gateway_load_serverを呼び出します。ゲートウェイはサブプロセスを開始し、MCPハンドシェイクを行い、接続をキャッシュします。その後の呼び出しでは、実行中のプロセスが再利用されます。
使用されないサーバーは起動しません。トークンは無駄になりません。
クイックスタート
git clone https://github.com/raiansar/mcp-gateway.git
cd mcp-gateway
./install.shconfig.jsonを編集してサーバーを追加し、Claude Codeにゲートウェイを追加します。
claude mcp add gateway -- /path/to/mcp-gateway/run.sh以上です。すべてのサーバーが単一のゲートウェイの背後に配置されました。
設定
config.jsonは、サーバー名と接続詳細をマッピングしたシンプルなファイルです。ゲートウェイはstdio(ローカルプロセス)とHTTP(リモートサーバー)の両方のトランスポートをサポートしています。
Stdioサーバー (ローカル)
{
"servers": {
"my-server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "some-mcp-server@latest"],
"env": {
"API_KEY": "your-key"
},
"timeout": 30,
"description": "What this server does"
}
}
}HTTPサーバー (リモート)
{
"servers": {
"remote-server": {
"type": "http",
"url": "https://mcp.example.com/mcp",
"headers": {
"Authorization": "Bearer your-token"
},
"timeout": 60,
"description": "Remote MCP server"
}
}
}Pythonサーバー (uv)
{
"servers": {
"my-python-server": {
"type": "stdio",
"command": "uv",
"args": ["run", "--directory", "/path/to/server", "server-name"],
"env": {},
"timeout": 120,
"description": "Python server managed by uv"
}
}
}設定フィールド
フィールド | 必須 | デフォルト | 説明 |
| いいえ |
| トランスポート: |
| はい (stdio) | - | サーバーを実行するコマンド |
| いいえ |
| コマンド引数 |
| いいえ |
| 環境変数 |
| はい (http) | - | サーバーURL |
| いいえ |
| HTTPヘッダー (認証トークンなど) |
| いいえ | 30/60 | リクエストタイムアウト(秒単位、stdioは30、httpは60) |
| いいえ | - |
|
既存のMCPサーバーの移行
すでにClaude CodeにMCPサーバーを設定している場合は、それらをゲートウェイに移行してください。
以前 (~/.claude.json または Claude Desktop設定内):
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx" }
},
"tavily": {
"command": "npx",
"args": ["-y", "tavily-mcp@latest"],
"env": { "TAVILY_API_KEY": "tvly-xxx" }
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user"],
"env": {}
}
}
}以後 (config.json内):
{
"servers": {
"github": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx" },
"description": "GitHub - repos, issues, PRs, code search"
},
"tavily": {
"type": "stdio",
"command": "npx",
"args": ["-y", "tavily-mcp@latest"],
"env": { "TAVILY_API_KEY": "tvly-xxx" },
"description": "Tavily AI search"
},
"filesystem": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user"],
"env": {},
"description": "File system access"
}
}
}その後、個別のサーバーをClaudeから削除し、ゲートウェイのみを追加します。
claude mcp remove github -s user
claude mcp remove tavily -s user
claude mcp remove filesystem -s user
claude mcp add gateway -- /path/to/mcp-gateway/run.sh使用方法
設定が完了すると、Claudeは自動的にゲートウェイを使用します。一般的なやり取りは以下の通りです。
Claudeが
gateway_list_serversを呼び出し、利用可能なサーバーを確認するClaudeがGitHubを必要とするときに
gateway_load_server("github")を呼び出すClaudeが
gateway_call_tool("github", "search_repositories", '{"query": "mcp"}')を呼び出してツールを使用するGitHubサーバーは同じセッション内の後続の呼び出しのために実行され続ける
設定内の description フィールドは、Claudeが特定のタスクに対してどのサーバーを読み込むべきかを判断するのに役立つため、適切な説明を記述してください。
RTKとの違い
RTKは、シェルコマンドの出力(git、ls、テストランナーなど)を圧縮してトークン消費を60〜90%削減するCLIプロキシです。
MCP Gatewayは異なる問題を解決します。すべてのツールを事前に登録するのではなく、必要に応じてサーバーを遅延読み込みすることで、MCPツールスキーマの肥大化を防ぎます。
MCP Gateway | RTK | |
問題 | アイドル状態のMCPサーバーからのツールスキーマがコンテキストを浪費する | 冗長なCLI出力がコンテキストを浪費する |
方法 | サーバーを遅延読み込みし、4つのプロキシツールを公開する | コンテキストに到達する前にコマンド出力を圧縮する |
タイミング | 起動時 / ツール登録時 | 実行時 / コマンド実行時 |
範囲 | MCPサーバー管理 | シェルコマンド (git, npm, cargoなど) |
これらは補完的な関係にあります。最大限のトークン節約のために両方を使用してください。
要件
Python 3.10+
mcpパッケージ (install.shでインストール)
ライセンス
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Zero-setup MCP gateway securely connecting AI to your tools with authentication and workflows
Gateway between LLM agents and world data through eight tools and a bundled endpoint catalog.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceActs as a proxy for multiple MCP servers, reducing context window usage from 15,000+ tokens to ~500 tokens by dynamically loading servers on-demand and exposing only 3 tools instead of all tool definitions.5GPL 3.0
- FlicenseAqualityCmaintenanceAggregates multiple MCP servers into a single gateway with unified top-level tools, reducing LLM context usage and enabling IDE compatibility by consolidating many tools into fewer interface functions.417-
- AlicenseNot gradedqualityCmaintenanceAggregates multiple Model Context Protocol servers into a single gateway to provide unified search, description, and execution of tools. It reduces context limit issues by dynamically fetching specific tool schemas only when needed rather than loading all available tools at once.6 npm23MIT
- AlicenseNot gradedqualityAmaintenanceAggregates tools from multiple upstream MCP servers and exposes them through 4 meta-tools, enabling LLMs to discover and use hundreds of tools without loading all schemas upfront.2Apache 2.0