Bifrost-MCP Gateway

Bifrost-MCP Gateway

Enterprise-grade dynamic MCP proxy that eliminates token bloat by lazy-loading tool schemas based on semantic intent, enabling efficient orchestration of multiple backend tools from a single endpoint.

Category
访问服务器

README

Bifrost-MCP-Gateway

⚡ Bifrost-MCP Gateway

Enterprise-grade Dynamic MCP Proxy — eliminates Token Bloat & Schema Stuffer Fatigue in Agentic AI pipelines by lazy-loading tool schemas on semantic intent.


The Problem

When coding agents like Claude Code, Cursor, or Gemini CLI connect to multiple MCP servers, every single tool schema (names, descriptions, JSON argument definitions) gets dumped into the model's context window on every single turn. Teams running 20+ servers routinely waste 50,000–100,000 tokens per turn just reading tool catalogs before processing the actual query.

Bifrost eliminates this by acting as a semantic proxy between your client and your backend tools.


Architecture

[Claude Code / Gemini CLI]
        │  Single endpoint — only 2 meta-tools registered
        ▼
 ┌─────────────────────┐
 │   Bifrost Gateway   │  ◄── Semantic intent router
 │    (FastAPI 0.115)  │       Lazy-loads schemas on demand
 └──────────┬──────────┘
            │
     /mcp/tools/resolve  ←── intent keyword
            │
   ┌────────┼─────────┬────────────┐
   ▼        ▼         ▼            ▼
[Filesystem] [DB] [GitHub API] [Slack/CI/CD…]

How It Works

Phase What Happens Token Cost
1. Bootstrap Gateway registers 2 meta-tools with the agent ~200 tokens
2. On-Demand Agent fires request_tool_schemas("github") → only GitHub schemas injected ~150 tokens
3. Orchestrate Agent pushes a multi-step Python block via execute_orchestration_script 0 round-trips
Naive approach All 20+ raw schemas dumped every turn ~8,000+ tokens

Typical savings: 70–90% context reduction per turn.


Quickstart

1. Install

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

2. Run

python gateway.py
# Gateway live at http://127.0.0.1:8000
# Dashboard at  http://127.0.0.1:8000/
# API docs at   http://127.0.0.1:8000/docs

3. Connect your MCP client

Point Claude Code or any MCP-compatible agent to:

http://127.0.0.1:8000/mcp/init

The agent receives only 2 meta-tools instead of your full registry.


API Reference

Method Path Description
GET /mcp/init Bootstrap handshake — returns compressed catalog + 2 meta-tools
POST /mcp/tools/resolve Lazy-load full schemas matching an intent keyword
POST /mcp/tools/orchestrate Execute a sandboxed Python script client-side
GET /mcp/registry List all registered tools
POST /mcp/registry/add Register a new tool at runtime
DELETE /mcp/registry/{name} Remove a tool
GET /analytics Live gateway metrics
GET /health Health probe

Example: On-Demand Schema Resolution

curl -X POST http://127.0.0.1:8000/mcp/tools/resolve \
  -H "Content-Type: application/json" \
  -d '{"user_intent": "github pull request"}'

Response:

{
  "intent": "github pull request",
  "matched_tools": [
    {
      "name": "create_github_pull_request",
      "description": "Creates a new pull request...",
      "input_schema": { ... }
    }
  ],
  "match_count": 1,
  "token_audit": {
    "full_registry_tokens": 2100,
    "hydrated_tokens": 180,
    "tokens_saved": 1920,
    "reduction_pct": 91.4
  }
}

Example: Orchestration Script

curl -X POST http://127.0.0.1:8000/mcp/tools/orchestrate \
  -H "Content-Type: application/json" \
  -d '{"script": "import json\nresult={\"status\":\"ok\"}\nprint(json.dumps(result))"}'

Adding Tools to the Registry

Edit config.json and restart, or POST at runtime:

curl -X POST http://127.0.0.1:8000/mcp/registry/add \
  -H "Content-Type: application/json" \
  -d '{
    "name": "search_vector_store",
    "category": "RAG",
    "description": "Semantic search over the enterprise knowledge base.",
    "schema": {
      "type": "object",
      "properties": {
        "query":   {"type": "string"},
        "top_k":   {"type": "integer"}
      },
      "required": ["query"]
    }
  }'

Security Model (OWASP Agentic Top 10 Mitigations)

The orchestration endpoint enforces a multi-layer security filter before executing any script:

Forbidden Pattern Why
rm -rf Filesystem destruction
os.system() Raw shell execution
subprocess.Popen() Arbitrary process spawning
shutil.rmtree() Directory removal
eval() / exec() Dynamic code injection
__import__() Runtime import hijacking
socket. Network exfiltration
ctypes Native memory access
open(..., 'w') Filesystem writes
importlib Module system abuse

Scripts also run with a 15-second hard timeout to prevent agent hang-loops.


Running Tests

pip install pytest httpx
pytest tests/ -v

Project Structure

bifrost-mcp/
├── gateway.py          # Core FastAPI application
├── config.json         # Tool registry (20 enterprise tools)
├── requirements.txt    # Minimal dependencies
├── static/
│   └── index.html      # Live monitoring dashboard
└── tests/
    └── test_gateway.py # Full test suite

Tech Stack

Layer Technology Rationale
Backend Python 3.10+ / FastAPI Async, minimal, zero-overhead
Matching Keyword tokenization No vector DB — instant startup
Orchestration Python subprocess (sandboxed) Zero external runtime
Dashboard Vanilla HTML/CSS/JS Zero build step, instant load
Deployment Single python gateway.py Frictionless, no Docker needed

Roadmap

  • [ ] Semantic vector matching (optional sentence-transformers mode)
  • [ ] Per-client token budgets & rate limiting
  • [ ] Streaming SSE event bus for real-time dashboard
  • [ ] Docker + Kubernetes manifests
  • [ ] OAuth2 / API key authentication layer
  • [ ] Plugin interface for custom tool backends

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选