Skip to main content
Glama
baoduy

drunk-mcp-proxy

by baoduy

drunk-mcp-proxy

A dynamic proxy server for Model Context Protocol (MCP) built with Python and FastMCP. This service allows you to proxy and manage multiple MCP backend servers through a single unified interface.

Features

  • πŸš€ Dynamic Proxy Management: Add and manage MCP servers on the fly

  • πŸ“ Static Configuration: Define default servers in config.json

  • πŸ’Ύ Persistent Storage: Dynamic proxies are saved to proxies.json

  • 🐳 Docker Support: Fully containerized with Docker and Docker Compose

  • πŸ”Œ Multiple Transports: Support for HTTP and SSE transports

  • πŸ› οΈ Built-in Tools: List, add, and manage proxy servers via MCP tools

Quick Start

  1. Clone the repository:

git clone https://github.com/baoduy/drunk-mcp-proxy.git cd drunk-mcp-proxy
  1. Edit config.json to add your default MCP servers:

{ "mcpServers": { "default": { "url": "https://example.com/mcp", "transport": "http" } } }
  1. Create the data directory for persistent storage:

mkdir -p data
  1. Start the service:

docker-compose up -d
  1. View logs:

docker-compose logs -f

Using Docker

  1. Create the data directory for persistent storage:

mkdir -p data
  1. Build the image:

docker build -t drunk-mcp-proxy .
  1. Run the container:

docker run -d \ -p 8000:8000 \ -v $(pwd)/config.json:/app/config.json:ro \ -v $(pwd)/data:/app/data \ --name mcp-proxy \ drunk-mcp-proxy

Local Development

  1. Create a virtual environment:

python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
  1. Install dependencies:

pip install -r requirements.txt
  1. Run the server:

python main.py

Configuration

Static Configuration (config.json)

Define your default MCP servers in config.json:

{ "mcpServers": { "server1": { "url": "https://api.example.com/mcp", "transport": "http" }, "server2": { "url": "https://another-server.com/mcp", "transport": "http" } } }

Dynamic Proxies

Dynamic proxies are added at runtime using the add_proxy tool and stored in proxies.json. These persist across restarts.

Available Tools

The proxy server exposes the following MCP tools:

add_proxy

Add a new MCP proxy server dynamically.

Parameters:

  • name (string): Name identifier for the proxy

  • url (string): URL of the MCP server to proxy

  • transport (string, optional): Transport protocol (default: "http")

Example:

add_proxy(name="my-server", url="https://my-server.com/mcp", transport="http")

list_proxies

List all configured MCP proxy servers (both static and dynamic).

Returns: List of all configured proxies with their URLs and transport types.

get_server_info

Get information about this MCP proxy server.

Returns: Server version, features, and usage information.

Environment Variables

  • MCP_CONFIG_FILE: Path to the static configuration file (default: config.json)

  • MCP_PROXIES_FILE: Path to the dynamic proxies file (default: proxies.json)

Project Structure

drunk-mcp-proxy/ β”œβ”€β”€ main.py # Main application code β”œβ”€β”€ config.json # Static server configuration β”œβ”€β”€ requirements.txt # Python dependencies β”œβ”€β”€ Dockerfile # Docker image definition β”œβ”€β”€ docker-compose.yml # Docker Compose configuration β”œβ”€β”€ .gitignore # Git ignore rules └── README.md # This file

Development

Testing Locally

  1. Install dependencies:

pip install -r requirements.txt
  1. Run the server:

python main.py
  1. The server will start and display mounted proxies:

================================================== Starting MCP Proxy Server ================================================== Mounting static servers from config.json: βœ“ Mounted 'default' at https://example.com/mcp ================================================== MCP Proxy Server is ready! ==================================================

Requirements

  • Python 3.11+

  • FastMCP 2.0.0+

Troubleshooting

Port Already in Use

If port 8000 is already in use, modify docker-compose.yml to use a different port:

ports: - "8080:8000" # Use port 8080 instead

Proxy Configuration Not Loading

  1. Check that config.json exists and has valid JSON syntax

  2. Verify file permissions allow reading

  3. Check Docker volume mounts in docker-compose.yml

Container Fails to Start

  1. Check logs: docker-compose logs mcp-proxy

  2. Verify network connectivity to backend MCP servers

  3. Ensure config file is properly mounted

Examples

Multiple Server Configuration

{ "mcpServers": { "weather": { "url": "https://weather-api.example.com/mcp", "transport": "http" }, "database": { "url": "https://db-api.example.com/mcp", "transport": "http" }, "analytics": { "url": "https://analytics.example.com/mcp", "transport": "http" } } }

Using with MCP Clients

Connect to this proxy server as you would any MCP server. The proxy will route requests to the configured backend servers and aggregate their responses.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ MCP Client β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ v β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ drunk-mcp- β”‚ β”‚ proxy β”‚ β”‚ (This Server) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” v v v β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚Backend β”‚ β”‚Backend β”‚ β”‚Backend β”‚ β”‚MCP β”‚ β”‚MCP β”‚ β”‚MCP β”‚ β”‚Server 1 β”‚ β”‚Server 2 β”‚ β”‚Server N β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

License

MIT License - See LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues, questions, or contributions, please visit the GitHub repository

-
security - not tested
A
license - permissive license
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/baoduy/drunk-mcp-proxy'

If you have feedback or need assistance with the MCP directory API, please join our Discord server