MCPx网关
具有智能命名空间路由的企业MCP网关路由器。
在终端用户和一组解耦的MCP服务器之间提供会话感知路由,每个服务器代表一个不同的工具和功能名称空间。专为企业规模(最多20000个用户,约15000个并发用户)、多租户、与Microsoft Entra ID集成的细粒度RBAC以及通过Azure容器应用程序或AKS上的KEDA自动扩展而构建。
建筑
┌─────────────────────────────────────────────────────┐
│ API Gateway │
│ (Azure APIM / Front Door) │
│ OAuth2/OIDC Token Validation │
└────────────────────┬────────────────────────────────┘
│
┌────────────────────▼────────────────────────────────┐
│ MCPx Gateway Router │
│ ┌──────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ Namespace │ │ Routing │ │ Agentic │ │
│ │ Registry │ │ Intelligence │ │ Orchestration │ │
│ │(Cosmos DB)│ │ (2-Phase) │ │ Engine │ │
│ └──────────┘ └──────────────┘ └──────────────────┘ │
│ ┌──────────┐ ┌──────────────┐ ┌──────────────────┐ │
│ │ Session │ │ RBAC │ │ LLM Provider │ │
│ │ Manager │ │ Enforcer │ │ Abstraction │ │
│ │ (Redis) │ │ │ │ (Azure OpenAI) │ │
│ └──────────┘ └──────────────┘ └──────────────────┘ │
└────────────────────┬────────────────────────────────┘
│ JSON-RPC 2.0
┌────────────┼────────────┐
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐
│MCP Srv A│ │MCP Srv B│ │MCP Srv N│
│(Finance)│ │(DevOps) │ │ (...) │
└─────────┘ └─────────┘ └─────────┘主要特点
- 两相路由:基于嵌入的命名空间解析+LLM工具选择
- 代理编排:计划执行多命名空间查询的重新组装
- 会话管理:Redis支持的具有MCP服务器关联性的会话
- 基于角色的访问控制:默认情况下拒绝,在命名空间和工具级别基于Entra ID组的策略
- 多租户:共享基础设施,按租户逻辑隔离
- 开放式WebUI兼容:自动生成用于REST集成的OpenAPI规范
- 可观察对象:OpenTetry跟踪、结构化审计日志记录、自定义指标
- LLM提供者抽象:可插拔提供程序(Azure OpenAI MVP,可扩展)
快速开始
先决条件
- Python 3.11+
- Redis(用于会话管理)
- Azure Cosmos DB(用于命名空间注册表)
- Azure OpenAI(用于路由智能和LLM)
发展
# Install with dev dependencies
pip install -e ".[dev]"
# Copy and configure environment
cp .env.example .env
# Run tests
pytest
# Start the development server
uvicorn mcpx_gateway.main:app --reload
# Or use Docker Compose
docker compose upAPI终点
| 端点 | 方法 | 描述 |
|---|---|---|
/health | GET | 活体检测 |
/ready | GET | 准备状态探测 |
/api/v1/chat | POST | 处理用户查询 |
/api/v1/chat/stream | POST | SSE流式处理 |
/api/v1/tools/{ns}/{tool} | POST | 直接工具调用(Open WebUI) |
/api/v1/openapi.json | GET | 聚合OpenAPI规范 |
/api/v1/namespaces/{ns}/openapi.json | GET | 每个命名空间OpenAPI规范 |
/admin/v1/namespaces | POST/GET | 命名空间管理 |
/admin/v1/namespaces/{id}/manifest | PUT/GET | 工具清单管理 |
/admin/v1/namespaces/{id}/sync | POST | 从MCP服务器同步清单 |
/admin/v1/policies | POST/GET | RBAC策略管理 |
项目结构
src/mcpx_gateway/
├── main.py # FastAPI app entrypoint
├── config.py # Configuration management
├── models/ # Pydantic data models
│ ├── namespace.py # Namespace metadata (Section 3.1)
│ ├── tool.py # Tool manifest (Section 3.2)
│ ├── session.py # Session state (Section 5)
│ ├── rbac.py # RBAC policies (Section 6)
│ ├── routing.py # Routing decisions (Section 4)
│ └── tenant.py # Multi-tenancy (Section 9)
├── registry/ # Cosmos DB backed registry
├── routing/ # Two-phase routing intelligence
│ ├── embedding.py # Vector similarity search
│ ├── namespace_resolver.py # Phase 1: Namespace resolution
│ └── tool_selector.py # Phase 2: Tool selection
├── orchestration/ # Agentic orchestration engine
│ ├── planner.py # Execution plan generation
│ ├── executor.py # Plan execution with retries
│ └── engine.py # Central orchestration coordinator
├── session/ # Redis session management
├── security/ # Auth and RBAC enforcement
├── transport/ # JSON-RPC, SSE, OpenAPI bridge
├── llm/ # LLM provider abstraction
├── observability/ # Tracing, metrics, audit
├── api/ # User-facing API routes
└── admin/ # Admin portal API routes
infrastructure/
├── keda/ # KEDA autoscaling configs
├── kubernetes/ # K8s deployment manifests
└── bicep/ # Azure IaC (Bicep)基础设施
使用提供的二头肌模板部署到Azure:
az deployment group create \
--resource-group mcpx-rg \
--template-file infrastructure/bicep/main.bicep \
--parameters environment=prod或者部署到Kubernetes:
kubectl apply -f infrastructure/kubernetes/
kubectl apply -f infrastructure/keda/许可证
麻省理工学院
