Skip to main content

Secure MCP gateway with auditing and access control

Project description

Watchgate

Version Python License

A simple, focused proxy for Model Context Protocol (MCP) communications with basic auditing and tool filtering.

Watchgate sits between your MCP client and server to give you visibility and basic control over what your AI agents are doing. This initial release focuses on the core proxy functionality with basic tool filtering and auditing.

How it works: Your MCP client connects to Watchgate as if it were any other MCP server, while Watchgate forwards requests to your actual MCP server with filtering and auditing.

๐ŸŽฏ Is This For You?

Watchgate is useful if you're dealing with any of these:

  • "I need to protect sensitive data in transit" - Block and log personally identifiable information, security tokens, and malicious prompts flowing between your LLM/MCP client and server
  • "I need to control tool access" - Built-in allowlist/blocklist for tool execution, plus plugin support for advanced security policies
  • "I need audit logs" - Plain text logs out of the box, or build custom formats and destinations via plugins
  • "I need to tweak messages" en-route between my MCP client and server

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.11 or higher
  • An existing MCP server to proxy

Installation

# Install from PyPI (recommended)
uv add watchgate

# Or install from source
git clone https://github.com/watchgate/watchgate.git
cd watchgate
uv sync

Basic Usage

  1. Create a configuration file:
# Option 1: Start with the full example (recommended for new users)
cp watchgate.example.yaml watchgate.yaml

# Option 2: Start with minimal configuration (for experienced users)
cp watchgate.minimal.yaml watchgate.yaml
  1. Edit watchgate.yaml to match your MCP server setup:
# Minimal example - edit the command to start your MCP server
proxy:
  transport: stdio
  upstream:
    command: "python -m your_mcp_server"  # <- Change this
  timeouts:
    connection_timeout: 30
    request_timeout: 60
  1. Start Watchgate:
watchgate --config watchgate.yaml
  1. Connect your MCP client to Watchgate instead of directly to your MCP server.

Usage Examples

# Basic usage with default config
watchgate --config watchgate.yaml

# Enable verbose logging
watchgate --config watchgate.yaml --verbose

# Show version
watchgate --version

# Show help
watchgate --help

๐Ÿ”ง Features

Core Capabilities (v0.1.0)

  • โœ… Foundation Components - Protocol, transport, and config systems (90% test coverage)

  • โœ… YAML Configuration - Simple configuration file support with plugin parameters

  • โœ… Plugin System Architecture - Plugin interfaces, manager, and discovery

  • โœ… Tool Allowlist Plugin - Tool allowlist/blocklist with comprehensive validation

  • โœ… Default Auditing Plugin - File-based logging with rotation and error handling

  • โœ… MCP Gateway Server - Complete request/response pipeline with plugin integration

  • โœ… Stdio Transport - Full stdio communication with subprocess management

  • โœ… Concurrent Request Handling - High-performance parallel processing of multiple MCP requests

Performance

Watchgate handles concurrent requests efficiently with significant performance improvements:

  • Concurrent Processing: Up to 100 simultaneous requests by default
  • Performance Gains: 5-250x faster than sequential processing for concurrent workloads
  • Resource Management: Automatic cleanup and configurable request limits
  • High Throughput: Optimized for production environments with multiple clients

Additional Features

The plugin architecture supports extensibility for additional transport protocols, advanced security policies, and enterprise features as needed.

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ MCP Client  โ”‚โ”€โ”€โ”€โ–ถโ”‚ Watchgate  โ”‚โ”€โ”€โ”€โ–ถโ”‚ MCP Server  โ”‚
โ”‚             โ”‚    โ”‚ (filter,    โ”‚    โ”‚             โ”‚
โ”‚             โ”‚    โ”‚  log)       โ”‚    โ”‚             โ”‚
โ”‚             โ”‚โ—€โ”€โ”€โ”€โ”‚             โ”‚โ—€โ”€โ”€โ”€โ”‚             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚
                          โ–ผ
                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚ Text Logs   โ”‚
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“– Configuration

Configuration File Structure

# Plugin-based configuration
proxy:
  transport: stdio
  upstream:
    command: "python -m my_mcp_server"
  timeouts:
    connection_timeout: 30
    request_timeout: 120

# Plugin configuration (policy-based)
plugins:
  security:
    - policy: "tool_allowlist"
      enabled: true
      config:
        mode: "allowlist"  # allowlist, blocklist, or allow_all
        tools:
          - "read_file"
          - "write_file"
        priority: 50  # Optional: execution order (lower = higher priority)
  
  auditing:
    - policy: "file_auditing"
      enabled: true
      config:
        file: "watchgate.log"
        format: "simple"

๐Ÿ“Š Basic Auditing

Watchgate provides simple text file auditing:

YYYY-MM-DD HH:MM:SS,mmm INFO [watchgate.proxy] MCP Request: tools/list from client
YYYY-MM-DD HH:MM:SS,mmm INFO [watchgate.policy] Tool allowed: file_read (allowlist match)
YYYY-MM-DD HH:MM:SS,mmm INFO [watchgate.proxy] MCP Response: success (42 tools)
YYYY-MM-DD HH:MM:SS,mmm WARN [watchgate.policy] Tool blocked: system_exec (blocklist match)

๐Ÿ”’ Simple Security Features

Plugin-Based Architecture

Watchgate uses a modern plugin-based architecture for flexibility and extensibility:

  • Plugin Discovery: Automatic discovery of available plugins by policy name
  • Execution Sequencing: Configurable plugin execution order with priority and dependency support
  • Request/Response Filtering: Plugins can modify requests and responses in addition to allowing/blocking requests

Built-in Security Plugins

Tool Access Control Plugin

  • Dual Protection: Filters both tools/call requests and tools/list responses
  • Multiple Modes: Allowlist, blocklist, and allow_all modes
  • Consistent Policy: Same security rules apply to tool execution and tool discovery
  • Detailed Auditing: Comprehensive logging of all filtering decisions

Example audit log:

Tool access control filtered tools/list response: original=5 tools, filtered=2 tools, 
removed=['delete_file', 'execute_command'], allowed=['read_file', 'write_file'], 
mode=allowlist, request_id=123

Basic Policy Engine

Watchgate includes a simple policy engine for basic access control:

  • Tool Allowlists - Only specified tools are permitted
  • Tool Blocklists - Specified tools are always denied
  • Pass-through Mode - If no policy configured, all tools allowed
  • Sequential Processing - Plugins execute in configurable order

๐Ÿ”ง Development

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=watchgate --cov-report=term

# Run specific test categories
pytest tests/unit/          # Unit tests
pytest tests/integration/   # Integration tests
pytest tests/performance/   # Performance tests

Development Setup

# Clone and setup development environment
git clone https://github.com/watchgate/watchgate.git
cd watchgate

# Ensure Python 3.11+ is available
python --version  # Should show 3.11.x or higher

# Install in development mode
pip install -e .

# Or use uv for faster development setup
uv sync --dev

# Install pre-commit hooks
pre-commit install

# Run linting
black watchgate/
ruff watchgate/
mypy watchgate/

Project Structure

watchgate/
โ”œโ”€โ”€ watchgate/           # Main package
โ”‚   โ”œโ”€โ”€ proxy/           # Core proxy implementation โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ server.py    # Main MCP gateway server
โ”‚   โ”‚   โ””โ”€โ”€ stdio_server.py # Stdio server management
โ”‚   โ”œโ”€โ”€ plugins/         # Plugin architecture โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ security/    # Security plugins โœ…
โ”‚   โ”‚   โ””โ”€โ”€ auditing/    # Auditing plugins โœ…
โ”‚   โ”œโ”€โ”€ protocol/        # MCP protocol layer โœ…
โ”‚   โ”œโ”€โ”€ transport/       # Transport protocols โœ…
โ”‚   โ””โ”€โ”€ config/          # Configuration system โœ…
โ”œโ”€โ”€ tests/               # Test suite (285+ tests)
โ”‚   โ”œโ”€โ”€ unit/           # Unit tests โœ…
โ”‚   โ”œโ”€โ”€ integration/    # Integration tests โœ…
โ”‚   โ””โ”€โ”€ performance/    # Performance tests
โ”œโ”€โ”€ docs/                # Documentation
โ””โ”€โ”€ examples/            # Usage examples

๐Ÿ“ˆ Performance

Current Capabilities

  • Basic Functionality: MCP gateway works correctly
  • Startup: <5 seconds to get running
  • Memory: Reasonable resource usage for development
  • Latency: Minimal proxy overhead

๐Ÿ› ๏ธ Supported MCP Methods

Core Methods

  • โœ… initialize - Protocol initialization
  • โœ… tools/list - List available tools
  • โœ… tools/call - Execute tools (with policy filtering)
  • โœ… resources/list - List resources
  • โœ… resources/read - Read resource content
  • ๐Ÿ”„ prompts/list - List prompts
  • ๐Ÿ”„ prompts/get - Get prompt content
  • ๐Ÿ”„ notifications - Server notifications
  • ๐Ÿ”„ Custom methods and extensions

๐Ÿ”ง Transport Protocols

Standard I/O (stdio)

Current transport supported:

server:
  command: "python -m your_server"

The plugin architecture supports extensibility for additional transport protocols as needed.

๐Ÿšง Development Status

Current Version: v0.1.0

Implementation Progress

โœ… Foundation Components - COMPLETED

  • โœ… Protocol Layer - Message types, validation, error handling (90% test coverage)
  • โœ… Transport Layer - Stdio transport with subprocess management (90% test coverage)
  • โœ… Configuration System - YAML loading and validation (90% test coverage)

โœ… Plugin System Architecture - COMPLETED

  • โœ… Plugin Interfaces - Abstract base classes for security and auditing plugins (14 tests, 85% coverage)
  • โœ… Plugin Manager - Dynamic loading, orchestration, and error isolation (30 tests, 97% coverage)
  • โœ… Plugin Discovery - Automatic plugin detection and configuration system

โœ… Plugin Implementation - COMPLETED

  • โœ… Default Security Plugin - Tool allowlist/blocklist implementation with comprehensive validation
  • โœ… Default Auditing Plugin - File-based logging with rotation and error handling
  • โœ… Core Proxy Server - Plugin-integrated message forwarding with stdio server support
  • โœ… Configuration Extension - YAML-based plugin configuration with path-based discovery

Current Test Status

# Run all tests
uv run pytest --no-header -v

# Current results: 285 passed, 1 skipped
# Test Coverage: 90%+ across all components

Environment Notes

Python Version: Requires Python 3.11+ (aligned with .python-version and pyproject.toml)

  • All asyncio compatibility issues resolved for Python 3.11+

๐Ÿ“š Documentation

๐Ÿค Contributing

We welcome contributions! Please see our contributing guidelines for details.

Development Process

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for your changes
  4. Ensure all tests pass with uv run pytest
  5. Submit a pull request

Reporting Issues

Please use the GitHub Issues tracker to report bugs or request features.

๐Ÿ“„ License

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

๐Ÿ“ž Support & Documentation


Watchgate v0.1.0 - An MCP server proxy for monitoring and controlling AI tool usage

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

watchgate-0.1.0.tar.gz (902.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

watchgate-0.1.0-py3-none-any.whl (195.2 kB view details)

Uploaded Python 3

File details

Details for the file watchgate-0.1.0.tar.gz.

File metadata

  • Download URL: watchgate-0.1.0.tar.gz
  • Upload date:
  • Size: 902.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for watchgate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14e10b55ebac808d7830a566ef212f878221c75f397d8d51057d993c8ea5a180
MD5 f64eafb7e6cbe5adbe9f70276f766b7a
BLAKE2b-256 3963d31a8821dceaf1510f5d21fe713901a0fad859e1f487153ba7fee616b4e9

See more details on using hashes here.

File details

Details for the file watchgate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: watchgate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 195.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for watchgate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30f284be89eb7ad0df613e02479c0411982a7458c5172ae6499b45173018ba0b
MD5 80a29915d6b559c42bd248a41e0c62a8
BLAKE2b-256 ce9a8f62ec352cc403fbe8f42af0743b0a0ab7c88edfd34fe90bed471c89e18f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page