Secure MCP-gRPC

Secure MCP-gRPC

Provides a secure gRPC transport layer for the Model Context Protocol (MCP) with mutual TLS, token-based authentication, and fine-grained authorization. Includes comprehensive telemetry and a real-time visualization dashboard for monitoring AI model interactions and security events.

Category
访问服务器

README

Secure MCP-gRPC

License Python Version Build Status Security Rating Code style: ruff

A secure gRPC transport layer for Model Context Protocol (MCP) with advanced security features, comprehensive telemetry, and real-time visualization.

Developed by Matthew Stanton & Claude AI

🌟 Overview

The Model Context Protocol (MCP) enables AI models to communicate with external tools and data sources. This project adds a secure gRPC transport layer for MCP, providing:

  • Enhanced Security: Zero-trust architecture with mutual TLS, token-based authentication, and fine-grained authorization
  • Comprehensive Telemetry: Detailed insights into model interactions, performance metrics, and security events
  • Visual Traffic Analysis: Real-time visualization of traffic patterns and model communication graphs
  • Enterprise-Grade Features: Rate limiting, audit logging, anomaly detection, and more

📋 Table of Contents

✨ Features

🔒 Security Features

  • Mutual TLS Authentication: Secure client-server identification with certificate validation
  • Token-based Authentication: Support for JWT and OAuth 2.0
  • Fine-grained Authorization: Role-based access control for specific model capabilities
  • Rate Limiting: Protection against DoS attacks with per-client limits
  • Anomaly Detection: Identification of unusual patterns and potential threats
  • Audit Logging: Comprehensive event tracking for compliance requirements
  • Secure Defaults: All security features enabled by default with sensible configurations

📊 Telemetry Capabilities

  • Performance Monitoring: Response times, throughput, and resource utilization tracking
  • Security Event Logging: Authentication attempts, authorization failures, and suspicious activities
  • Usage Analytics: Understanding how models are being used and by whom
  • Health Monitoring: Real-time status of all system components
  • Anonymous Reporting: Privacy-preserving aggregated insights

🔍 Interaction Tracing

  • Request/Response Capture: Full payload logging with configurable sanitization
  • Connection Metadata: Detailed information about clients and sessions
  • Path Traversal: Tracking of multi-model interaction chains
  • Data Lineage: Understanding how data flows between models
  • Timing Analysis: Performance bottleneck identification

📈 Visualization Dashboard

  • Traffic Flow Diagrams: Sankey diagrams showing request patterns
  • Model Interaction Networks: Graph visualization of model communication
  • Security Event Heatmaps: Temporal analysis of security incidents
  • Latency Distribution Charts: Performance profiles across different methods
  • Real-Time Monitoring: Live updates on system status and metrics

🏗️ Architecture

The Secure MCP-gRPC system consists of several core components:

┌───────────────────┐     ┌───────────────────┐     ┌───────────────────┐
│                   │     │                   │     │                   │
│   AI Model with   │     │  Secure MCP-gRPC  │     │   AI Model with   │
│    MCP Client     │◄───►│      Server       │◄───►│    MCP Client     │
│                   │     │                   │     │                   │
└───────────────────┘     └─────────┬─────────┘     └───────────────────┘
                                   │
                                   ▼
                          ┌─────────────────┐
                          │   Interaction   │
                          │     Tracer      │
                          └─────────┬───────┘
                                   │
                                   ▼
┌───────────────────┐     ┌─────────────────┐     ┌───────────────────┐
│                   │     │                 │     │                   │
│     Prometheus    │◄───►│   Telemetry     │◄───►│     Dashboard     │
│                   │     │   Dashboard     │     │                   │
└───────────────────┘     └─────────────────┘     └───────────────────┘

Key Components:

  1. Secure MCP-gRPC Server: Core server that handles authentication, authorization, and request processing
  2. Interaction Tracer: Captures detailed information about model interactions
  3. Telemetry Dashboard: Web-based visualization of traffic patterns and metrics
  4. MCP Clients: AI models that communicate with the server
  5. Prometheus/Grafana: Additional monitoring and alerting tools

📋 Prerequisites

  • Docker and Docker Compose
  • Python 3.9+ (for development)
  • OpenSSL (for certificate generation)
  • Git
  • Pre-commit (optional, for development)

🚀 Quick Start

  1. Clone the repository:

    git clone https://github.com/yourusername/secure-mcp-grpc.git
    cd secure-mcp-grpc
    
  2. Run the setup script:

    ./setup.sh
    
  3. Start the services:

    docker-compose -f docker/docker-compose.yml up -d
    
  4. Access the services:

    • gRPC Server: localhost:50051
    • Dashboard: http://localhost:8050
    • Grafana: http://localhost:3000
    • Prometheus: http://localhost:9090

🐳 Docker Deployment

Production Deployment

  1. Build and start all services:

    docker-compose -f docker/docker-compose.yml up -d
    
  2. View logs:

    docker-compose -f docker/docker-compose.yml logs -f
    
  3. Stop services:

    docker-compose -f docker/docker-compose.yml down
    

Service Details

  • MCP Server: Secure gRPC server with mTLS authentication
  • Dashboard: Real-time visualization of traffic and metrics
  • Prometheus: Metrics collection and storage
  • Grafana: Advanced metrics visualization and alerting

Resource Management

Each service has resource limits and reservations:

  • MCP Server: 1 CPU, 1GB RAM
  • Dashboard: 0.5 CPU, 512MB RAM
  • Prometheus: 0.5 CPU, 1GB RAM
  • Grafana: 0.5 CPU, 512MB RAM

⚙️ Configuration

Environment Variables

Key environment variables for the MCP server:

MCP_SERVER_HOST=0.0.0.0
MCP_SERVER_PORT=50051
MCP_AUTH_TYPE=mtls
MCP_CERT_PATH=/app/certs/server.crt
MCP_KEY_PATH=/app/certs/server.key
MCP_CA_PATH=/app/certs/ca.crt

Configuration Files

  • Server config: config/server.yaml
  • Prometheus config: config/prometheus/prometheus.yml
  • Grafana config: config/grafana/provisioning/

🔒 Security

Certificate Management

  1. Generate certificates:

    ./scripts/generate_certs.sh
    
  2. Update certificates:

    ./scripts/update_certs.sh
    

Security Best Practices

  1. Use strong passwords for Grafana
  2. Keep certificates secure and regularly rotated
  3. Monitor security events in Grafana
  4. Use rate limiting for all clients
  5. Enable audit logging

📊 Monitoring

Metrics

Key metrics available in Prometheus:

  • Request rate
  • Response time
  • Error rates
  • Resource utilization
  • Security events

Dashboards

Pre-configured Grafana dashboards:

  • Traffic Overview
  • Performance Metrics
  • Security Events
  • Resource Usage

👩‍💻 Development

Local Development

  1. Install development dependencies:

    pip install -e ".[dev]"
    
  2. Run tests:

    pytest tests/
    
  3. Run benchmarks:

    pytest tests/benchmarks/
    

Code Style

  • Use Ruff for linting and formatting (replaces Black, isort, and flake8)
  • Use mypy for type checking
  • Follow PEP 8 guidelines
  • Install pre-commit hooks: pre-commit install

Run linting and formatting:

# Format code
ruff format .

# Lint and auto-fix
ruff check --fix .

# Type check
mypy secure_mcp_grpc

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

See CONTRIBUTING.md for detailed guidelines.

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🙏 Acknowledgments

  • Matthew Stanton: Lead architect and security expert
  • Claude AI: Co-creator and documentation contributor
  • Anthropic for their work on Model Context Protocol (MCP)
  • The gRPC team for their excellent communication framework

For more detailed information, please refer to the documentation.

Security issues should be reported according to our security policy.

推荐服务器

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

官方
精选