使用说明
MCP Proxy
MCP Proxy is a multi-service MCP (Model Context Protocol) aggregation proxy with OAuth authentication, token management, and advanced routing capabilities.
Features
- Multi-service aggregation: Route requests to multiple MCP backends through a single proxy
- OAuth integration: Secure OAuth flows for services like GitLab, Jira, etc.
- Token management: Server-side token storage and injection
- SSE and HTTP support: Handle both Server-Sent Events and HTTP-based MCP backends
- User dashboard: Web interface for managing services and viewing audit logs
- Admin dashboard: Administrative interface for service configuration
- Audit logging: Comprehensive logging of all API calls
- Monitoring: Prometheus metrics for observability
Quick Start with Docker Compose
The easiest way to get started is using Docker Compose, which will set up OpenWebUI, GitLab, GitLab MCP Server, and MCP Proxy together:
# Copy the example environment file
cp .env.example .env
# Start all services
docker compose up -d
# Wait for services to be ready (especially GitLab takes 5-10 minutes)
docker compose ps
See setup-guide-ja.md for detailed setup instructions in Japanese.
Installation
pip install -r requirements.txt
Development
pip install -r requirements-dev.txt
Running the Server
uvicorn mcp_proxy.main:app --host 0.0.0.0 --port 8000
Or with hot reload for development:
uvicorn mcp_proxy.main:app --reload
Configuration
Create a .env file in the project root with the following settings:
# Application
APP_NAME=MCP Proxy
DEBUG=false
# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/mcp_proxy
# Redis
REDIS_URL=redis://localhost:6379/0
# Security
SECRET_KEY=your-secret-key-here
ENCRYPTION_KEY=your-encryption-key-here
# OAuth
OAUTH_STATE_EXPIRE_SECONDS=600
OAUTH_CALLBACK_BASE_URL=https://proxy.example.com # Base URL for OAuth callbacks (required for production)
# Server
HOST=0.0.0.0
PORT=8000
API Documentation
Once the server is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Main Endpoints
Public Endpoints
GET /health- Health checkGET /metrics- Prometheus metrics
Admin Endpoints (requires admin role)
GET /admin- Admin dashboardGET /admin/services- List all servicesPOST /admin/services- Create a new servicePUT /admin/services/{id}- Update a serviceDELETE /admin/services/{id}- Delete a serviceGET /admin/users- List all usersGET /admin/audit- View audit logs
User Endpoints (requires authentication)
GET /user/dashboard- User dashboardGET /user/services- List available servicesPUT /user/services/{service}/toggle- Enable/disable a servicePUT /user/services/{service}/config- Configure service API keysGET /user/tokens- List authentication tokensGET /user/audit- View personal audit logs
OAuth Endpoints
GET /oauth/{service}/login- Initiate OAuth flowGET /oauth/{service}/callback- OAuth callback handler
MCP Proxy Endpoints (requires authentication)
GET /mcp/{service}- SSE endpoint for MCP connectionsPOST /mcp/{service}- HTTP endpoint for MCP requestsGET /mcp/{service}/openapi- Get OpenAPI spec from backend
Authentication Flow
- User initiates OAuth flow via
/oauth/{service}/login - User is redirected to OAuth provider (e.g., GitLab)
- After authentication, provider redirects to
/oauth/{service}/callback - Proxy exchanges authorization code for access token
- Proxy issues a server token (JWT) to the user
- User uses server token for all subsequent API calls
Service Configuration
Services can be configured via the Admin API:
{
"name": "gitlab",
"display_name": "GitLab",
"backend_url": "http://gitlab-mcp:8001",
"backend_type": "sse",
"oauth_enabled": true,
"oauth_provider_url": "https://gitlab.com",
"oauth_client_id": "your-client-id",
"oauth_client_secret": "your-client-secret",
"oauth_scopes": ["api", "read_user"],
"allowed_users": ["user@example.com"],
"rate_limit_per_min": 60
}
Running Tests
pytest
For coverage report:
pytest --cov=mcp_proxy --cov-report=html
Documentation
See the following specification documents:
mcp_proxy_full_spec.md- Complete feature specificationmcp_proxy_test_spec.md- Comprehensive test specification
Architecture
[User Browser]
└→ OpenWebUI (MCP Client)
├ register MCP: https://proxy.example.com/mcp/gitlab
├ register MCP: https://proxy.example.com/mcp/jira
└ uses tools...
↕ (SSE or HTTP)
[ M C P P R O X Y ] (single ingress)
- /mcp/{service} (SSE/HTTP)
- /oauth/{service}/login
- /oauth/{service}/callback
- /admin/*
- /user/*
- /health, /metrics
├ route → internal GitLab-MCP (sse/http)
└ route → external 3rd-party MCP
Security Features
- JWT-based authentication with database verification
- Encrypted storage of OAuth tokens and API keys
- Service-level ACL (allowed users/groups)
- Comprehensive audit logging
- Rate limiting per service
- Token expiration and refresh
License
TBD