Skip to main content

Universal Authentication Gateway for MCP (Model Context Protocol) Servers

Project description

AuthMCP Gateway

Secure authentication proxy for Model Context Protocol (MCP) servers

PyPI version License: MIT Python 3.11+ Docker MCP

AuthMCP Gateway provides centralized authentication, authorization, and monitoring for MCP servers. It acts as a secure proxy between clients and your MCP backends, adding JWT-based authentication, rate limiting, real-time monitoring, and comprehensive security logging.

๐Ÿ“‹ Table of Contents


โœจ Features

๐Ÿ” Authentication & Authorization

  • OAuth 2.0 + JWT - Industry-standard authentication flow
  • User Management - Multi-user support with role-based access
  • Backend Token Management - Secure storage and auto-refresh of MCP server credentials
  • Rate Limiting - Per-user request throttling with configurable limits

๐Ÿ“Š Real-Time Monitoring

  • Live MCP Activity Monitor - Real-time request feed with auto-refresh
  • Performance Metrics - Response times, success rates, requests/minute
  • Security Event Logging - Unauthorized access attempts, rate limiting, suspicious activity
  • Health Checking - Automatic health checks for all connected MCP servers

๐ŸŽ›๏ธ Admin Dashboard

  • User Management - Create, edit, and manage users
  • MCP Server Configuration - Add and configure backend MCP servers
  • Token Management - Monitor token health and manual refresh
  • Security Events - View and filter security events
  • API Testing - Built-in MCP testing interface

๐Ÿ›ก๏ธ Security

  • JWT token-based authentication with refresh tokens
  • Secure credential storage with encrypted database support
  • CORS protection and request validation
  • Security event logging and monitoring
  • File-based logging - JSON logs for auth & MCP requests with rotation; security events remain in SQLite for audit/queries
  • Built-in security testing guide

๐Ÿ“š Documentation

๐Ÿ“š Complete Documentation - Full documentation index

Quick Links:

๐Ÿ“ธ Screenshots

๐Ÿ–ฅ๏ธ Dashboard - Real-time Overview

Dashboard

Live statistics, server health monitoring, top tools usage, and recent activity feed

๐Ÿ”ง MCP Servers - Connection Management

MCP Servers

Manage backend MCP server connections with status monitoring and health checks

๐Ÿ“Š MCP Activity Monitor - Real-time Request Tracking

MCP Activity

Monitor live MCP requests with detailed metrics, top tools ranking, and request feed

๐Ÿ›ก๏ธ Security Events - Threat Detection

Security Events

Track security events, rate limiting, suspicious payloads, and unauthorized access attempts

๐Ÿ”’ MCP Security Audit - Vulnerability Scanner

MCP Security Audit

Test any MCP server for security vulnerabilities with comprehensive automated checks


๐Ÿš€ Quick Start

Option 1: PyPI Package (Recommended)

1. Install:

pip install authmcp-gateway

2. First Run:

authmcp-gateway start
# โœ“ Auto-creates .env with JWT_SECRET_KEY
# โœ“ Auto-creates data/ directory
# โœ“ Initializes database

3. Access Setup Wizard: Open http://localhost:8000/ in your browser to create admin user.

4. Optional - Customize Configuration:

# Edit auto-generated .env or download full example
curl -o .env https://raw.githubusercontent.com/loglux/authmcp-gateway/main/.env.example.pypi

# Common settings to customize in .env:
# PORT=9000                          # Change server port
# PASSWORD_REQUIRE_SPECIAL=false     # Relax password requirements
# LOG_LEVEL=DEBUG                    # More detailed logs

# Restart to apply changes
authmcp-gateway start

Available Commands:

authmcp-gateway start                    # Start server (default: 0.0.0.0:8000)
authmcp-gateway start --port 9000        # Start on custom port
authmcp-gateway start --host 127.0.0.1   # Bind to localhost only
authmcp-gateway start --env-file custom.env  # Use custom config file

authmcp-gateway init-db                  # Initialize database
authmcp-gateway create-admin             # Create admin user via CLI
authmcp-gateway version                  # Show version
authmcp-gateway --help                   # Show all options

Option 2: Docker Compose

  1. Clone and configure:

    git clone https://github.com/loglux/authmcp-gateway.git
    cd authmcp-gateway
    cp .env.example .env
    # Edit .env with your settings
    
  2. Start the gateway:

    docker-compose up -d
    
  3. Access admin panel:

โš™๏ธ Configuration

Environment Variables

# Gateway Settings
GATEWAY_PORT=9105              # Host port mapping for Docker (container listens on 8000)
JWT_SECRET_KEY=your-secret-key # JWT signing key (auto-generated if not set)
AUTH_REQUIRED=true             # Enable authentication (default: true)

# Admin Settings
ADMIN_USERNAME=admin           # Initial admin username
ADMIN_PASSWORD=secure-password # Initial admin password

Adding MCP Servers

Via Admin Panel:

  1. Navigate to MCP Servers โ†’ Add Server
  2. Enter server details:

Via API:

curl -X POST http://localhost:9105/admin/api/mcp-servers \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "GitHub MCP",
    "url": "http://github-mcp:8000/mcp",
    "backend_token": "optional-token"
  }'

๐Ÿ’ก Usage

For End Users

  1. Login to get access token:

    curl -X POST http://localhost:9105/auth/login \
      -H "Content-Type: application/json" \
      -d '{"username":"your-username","password":"your-password"}'
    
  2. Use token to access MCP endpoints:

    curl -X POST http://localhost:9105/mcp \
      -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
    

For Administrators

Admin Panel Features:

  • Dashboard - Overview of users, servers, and activity
  • MCP Activity - Real-time monitoring of all MCP requests
  • Security Events - View unauthorized access attempts and suspicious activity
  • User Management - Create and manage user accounts
  • Token Management - Monitor and refresh backend tokens

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Client    โ”‚
โ”‚  (Claude,   โ”‚
โ”‚   etc.)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚ JWT Auth
       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   AuthMCP Gateway           โ”‚
โ”‚                             โ”‚
โ”‚  โ€ข Authentication           โ”‚
โ”‚  โ€ข Rate Limiting            โ”‚
โ”‚  โ€ข Security Logging         โ”‚
โ”‚  โ€ข Request Routing          โ”‚
โ”‚  โ€ข Health Monitoring        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚
       โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
       โ–ผ          โ–ผ          โ–ผ          โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚GitHub   โ”‚ โ”‚  RAG   โ”‚ โ”‚ Home   โ”‚ โ”‚Custom  โ”‚
  โ”‚MCP      โ”‚ โ”‚  MCP   โ”‚ โ”‚Assistantโ”‚ โ”‚ MCP    โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”Œ API Endpoints

Public Endpoints

  • POST /auth/login - User login
  • POST /auth/register - User registration (if enabled)
  • POST /auth/refresh - Refresh access token
  • POST /oauth/register - OAuth dynamic client registration (if enabled)
  • GET /.well-known/oauth-authorization-server - OAuth discovery

Protected Endpoints

  • POST /mcp - Aggregated MCP endpoint (all servers)
  • POST /mcp/{server_name} - Specific MCP server endpoint
  • GET /mcp - Streamable MCP endpoint (SSE/stream clients)
  • GET /auth/me - Current user info
  • POST /auth/logout - Logout

Admin Endpoints

  • GET /admin - Admin dashboard
  • GET /admin/mcp-activity - Real-time MCP monitoring
  • GET /admin/security-logs - Security events
  • GET /admin/users - User management
  • GET /admin/mcp-servers - MCP server configuration
  • Plus full REST API for management

๐Ÿค– Codex OAuth (DCR) Login (Manual Callback)

Codex uses OAuth Authorization Code + PKCE and Dynamic Client Registration (DCR). When running in a terminal without an auto-launching browser, you must manually open the authorization URL and then call the localhost callback URL yourself to finish the login.

See the wiki page: Codex-Registration for a full CLI transcript.

Steps:

  1. Add the MCP server in Codex:
codex mcp add rag --url https://your-domain.com/mcp/your-backend
  1. Codex prints an Authorize URL. Open it in your browser.
  2. Complete the login (admin/user credentials).
  3. After successful login you will be redirected to a http://127.0.0.1:<port>/callback?... URL. Copy that full URL and call it from another terminal:
curl "http://127.0.0.1:<port>/callback?code=...&state=..."

You should see: Authentication complete. You may close this window.

Once completed, Codex shows the MCP server as logged in.

Calling RAG Tools From Codex (Example)

In Codex chat, you can invoke tools directly, for example:

  • mcp__rag__list_knowledge_bases
  • mcp__rag__rag_query

Or ask Codex to list tools: show rag tools.

๐Ÿ” Security

Testing Security

See docs/SECURITY_TESTING.md for:

  • Manual security tests
  • Automated testing script
  • Production deployment checklist
  • Security best practices

Security Features

  • โœ… JWT-based authentication with refresh tokens
  • โœ… Rate limiting per user
  • โœ… Security event logging
  • โœ… MCP request tracking with suspicious activity detection
  • โœ… Health monitoring for backend servers
  • โœ… CORS protection
  • โœ… Secure credential storage

๐Ÿ› ๏ธ Development

Local Development

# Clone repository
git clone https://github.com/loglux/authmcp-gateway.git
cd authmcp-gateway

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install dependencies
pip install -e .

# Run gateway
authmcp-gateway

Running Tests

pytest tests/

Project Structure

authmcp-gateway/
โ”œโ”€โ”€ src/authmcp_gateway/
โ”‚   โ”œโ”€โ”€ admin/           # Admin panel routes and logic
โ”‚   โ”œโ”€โ”€ auth/            # Authentication & authorization
โ”‚   โ”œโ”€โ”€ mcp/             # MCP proxy and handlers
โ”‚   โ”œโ”€โ”€ security/        # Security logging and monitoring
โ”‚   โ”œโ”€โ”€ middleware.py    # Request middleware
โ”‚   โ””โ”€โ”€ app.py           # Main application
โ”œโ”€โ”€ templates/           # Jinja2 templates (admin UI)
โ”œโ”€โ”€ docs/                # Documentation
โ”œโ”€โ”€ tests/               # Test suite
โ””โ”€โ”€ docker-compose.yml   # Docker deployment

๐Ÿ“Š Monitoring

Real-Time Dashboard

Access /admin/mcp-activity for:

  • Live request feed (updates every 3 seconds)
  • Requests per minute
  • Average response times
  • Success rates
  • Top tools usage
  • Per-server statistics

Logs

View logs in real-time:

docker logs -f authmcp-gateway

๐Ÿ”ง Troubleshooting

Cannot access admin panel:

  • Ensure you've completed the setup wizard at /setup
  • Check that cookies are enabled
  • Verify JWT_SECRET_KEY is set correctly

MCP server shows as offline:

  • Check server URL is correct and reachable
  • Verify backend token if required
  • View error details in MCP Servers page

401 Unauthorized errors:

  • Token may have expired - use refresh token
  • Verify Authorization header format: Bearer YOUR_TOKEN
  • Check user has permission for the MCP server

For more help, see docs/SECURITY_TESTING.md.

License

MIT License - see LICENSE file for details.

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

authmcp_gateway-1.0.20.tar.gz (141.1 kB view details)

Uploaded Source

Built Distribution

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

authmcp_gateway-1.0.20-py3-none-any.whl (157.5 kB view details)

Uploaded Python 3

File details

Details for the file authmcp_gateway-1.0.20.tar.gz.

File metadata

  • Download URL: authmcp_gateway-1.0.20.tar.gz
  • Upload date:
  • Size: 141.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for authmcp_gateway-1.0.20.tar.gz
Algorithm Hash digest
SHA256 65947debd0f33a2c51cb25b7a9ee3410878cddfdeca3c0529861de2a7513ce33
MD5 3c63ffaf2fc5fab167857b3a28956777
BLAKE2b-256 e118b8b39a944757921a4e741bb7998066acc75afd64705606468f308beff655

See more details on using hashes here.

File details

Details for the file authmcp_gateway-1.0.20-py3-none-any.whl.

File metadata

File hashes

Hashes for authmcp_gateway-1.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 bd266cf4dafea6f93d5ca4d4da2cae2b21345186baab49d9793e9ba1f1f6027f
MD5 d0f44b80175b29c796d4446d1a26b51a
BLAKE2b-256 6d774d97474b74ccf9d2c69dccd274f357a907a8d75b0651dd9e8f2deca96297

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