Cover image
Try Now
2025-04-14

用于外部身份验证和授权的MCP网关

3 years

Works with Finder

0

Github Watches

0

Github Forks

0

Github Stars

MCPAuth

MCPAuth: Gateway Authentication for Secure Enterprise MCP Integrations

License Release Go Version CI Status

🔐 MCPAuth: Gateway Authentication for Secure Enterprise MCP Integrations

McpAuth is the authentication and authorization component of the MCP Gateway Proof of Concept (PoC) described in the paper:

Simplified and Secure MCP Gateways for Enterprise AI Integration
Ivo Brett, CISSP, B.Eng, MSc
View Paper (2025)

This repository is part of a broader initiative to enable secure, scalable, and compliant enterprise integration with the Model Context Protocol (MCP). It provides an extensible OAuth2.1-based authentication gateway that offloads identity, authorization, and policy management from backend MCP servers—ensuring conformance with the 2025-03-26 MCP Specification.

---

🔍 Purpose

McpAuth is designed to:

  • Decouple security logic from MCP servers
  • Centralize identity management using OAuth 2.1 & OIDC
  • Support dynamic client registration
  • Enforce fine-grained token scopes and policy controls
  • Act as a composable module in enterprise-grade Zero Trust architectures

📚 Background

This implementation is part of a larger PoC that validates:

  • A reference MCP Gateway architecture for secure deployments
  • Threat model mapping aligned with frameworks such as MAESTRO and Narajala & Habler
  • Real-world compatibility with tools like Cloudflare Tunnels, WireGuard, Traefik, and CrowdSec

The full proof of concept includes:

  • Two isolated MCP servers (local and cloud-based)
  • Secure tunneling via WireGuard and Pangolin
  • Centralized intrusion detection and observability
  • Seamless integration with Anthropic's MCP Inspector

✨ Features

  • 🔐 OAuth2 authentication with PKCE via Traefik forwardAuth
  • ⚡ Seamless integration with MCP Gateway SSE endpoints
  • ✅ Email whitelisting for controlled access
  • 🐳 Docker-ready, easy to deploy
  • 🧪 Includes a Python-based test server

🚀 Quick Start

📦 Prerequisites

  • Go 1.21+
  • Traefik v2.x+
  • An OAuth provider (e.g., Google, GitHub)

🛠️ Installation

git clone https://github.com/oidebrett/mcpauth
cd mcpauth
go mod tidy

🔧 Configuration

Use flags or environment variables:

Variable Default Description
PORT 11000 Port for the auth server
PROTECTED_PATH /sse Protected endpoint path
OAUTH_DOMAIN (none) OAuth issuer domain
CLIENT_ID (none) OAuth client ID
CLIENT_SECRET (none) OAuth client secret
ALLOWED_EMAILS (none) Comma-separated list of allowed emails
LOG_LEVEL 1 0=debug, 1=info, 2=minimal
go run cmd/main.go -port=11000 -oauthDomain=your-domain.com

🐳 Docker Deployment

Basic Docker Compose

services:
  mcpauth:
    build: .
    environment:
      - PORT=11000
      - CLIENT_ID=${CLIENT_ID}
      - CLIENT_SECRET=${CLIENT_SECRET}
    ports:
      - "11000:11000"

🔐 Traefik Integration

ForwardAuth Middleware

http:
  middlewares:
    mcp-auth:
      forwardAuth:
        address: "http://mcpauth:11000/sse"
        authResponseHeaders:
          - "X-Forwarded-User"

Attach to a Router

labels:
  - "traefik.http.routers.myapp.middlewares=mcp-auth@file"

🧪 Testing

Run Included Test Server

cd test_mcp_server
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python mcp-server-sse.py

With curl

curl -i http://localhost:11000/health
curl -i http://localhost:11000/sse

🧱 Middleware Chain (Traefik)

Apply middlewares in this order:

  1. mcp-cors-headers
  2. redirect-regex
  3. mcp-auth

Example dynamic config:

http:
  middlewares:
    mcp-cors-headers:
      headers:
        accessControlAllowCredentials: true
        accessControlAllowHeaders:
          - Authorization
          - Content-Type
          - mcp-protocol-version
        accessControlAllowMethods:
          - GET
          - POST
          - OPTIONS
        accessControlAllowOriginList:
          - "*"
        accessControlMaxAge: 86400
        addVaryHeader: true

    redirect-regex:
      redirectRegex:
        regex: "^https://([a-z0-9-]+)\\.yourdomain\\.com/\\.well-known/oauth-authorization-server"
        replacement: "https://oauth.yourdomain.com/.well-known/oauth-authorization-server"
        permanent: true

    mcp-auth:
      forwardAuth:
        address: "http://mcpauth:11000/sse"
        authResponseHeaders:
          - X-Forwarded-User

🧠 Middleware Manager Support

This project supports middleware-manager.

Example templates.yml:

middlewares:
  - id: mcp-auth
    name: MCP Authentication
    type: forwardAuth
    config:
      address: "http://mcpauth:11000/sse"
      authResponseHeaders:
        - "X-Forwarded-User"

  - id: mcp-cors-headers
    name: MCP CORS Headers
    type: headers
    config:
      accessControlAllowMethods:
        - GET
        - POST
        - OPTIONS
      accessControlAllowOriginList:
        - "*"
      accessControlAllowHeaders:
        - Authorization
        - Content-Type
        - mcp-protocol-version
      accessControlMaxAge: 86400
      accessControlAllowCredentials: true
      addVaryHeader: true

  - id: redirect-regex
    name: Regex Redirect
    type: redirectregex
    config:
      regex: "^https://([a-z0-9-]+)\\.yourdomain\\.com/\\.well-known/oauth-authorization-server"
      replacement: "https://oauth.yourdomain.com/.well-known/oauth-authorization-server"
      permanent: true

📜 License

Licensed under the GNU General Public License v3.0.


相关推荐

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • rulego
  • ⛓️Rulego是一种轻巧,高性能,嵌入式,下一代组件编排规则引擎框架。

  • sigoden
  • 使用普通的bash/javascript/python函数轻松创建LLM工具和代理。

  • hkr04
  • 轻巧的C ++ MCP(模型上下文协议)SDK

  • RockChinQ
  • 😎简单易用、🧩丰富生态 -大模型原生即时通信机器人平台| 适配QQ / 微信(企业微信、个人微信) /飞书 /钉钉 / discord / telegram / slack等平台| 支持chatgpt,deepseek,dify,claude,基于LLM的即时消息机器人平台,支持Discord,Telegram,微信,Lark,Dingtalk,QQ,Slack

  • dmayboroda
  • 带有可配置容器的本地对话抹布

  • modelscope
  • 开始以更轻松的方式开始构建具有LLM授权的多代理应用程序。

  • paulwing
  • 使用MCP服务创建的测试存储库

    Reviews

    2.8 (6)
    Avatar
    user_q236EbmN
    2025-04-23

    As a dedicated user of the MCP app ecosystem, I can confidently say that mcpauth by oidebrett is an essential tool for anyone looking to streamline their communication and authentication processes. Its robust features and seamless integration have significantly improved my workflow, making it a must-have for any professional. Highly recommended!

    Avatar
    user_QXnbYVIQ
    2025-04-23

    As a devoted MCP user, I absolutely love mcpauth by oidebrett! This product seamlessly integrates with my existing applications, making authentication processes a breeze. The user-friendly interface and detailed documentation make setup quick and easy. Highly recommend it!

    Avatar
    user_UNZcdaRR
    2025-04-23

    As a dedicated user of MCP applications, I must say that mcpauth by oidebrett is an indispensable tool. Its seamless integration and ease of use make authentication processes a breeze. If you're looking for reliability and efficiency, this is definitely the go-to solution. Highly recommended!

    Avatar
    user_hobfibX4
    2025-04-23

    I've been using mcpauth by oidebrett, and it's truly a fantastic tool! The authentication process is seamless and reliable, making security management much easier. The documentation is clear, and the support from the community is top-notch. Highly recommend for anyone looking for a robust authentication solution.

    Avatar
    user_cyIjD7xm
    2025-04-23

    As a loyal user of MCP applications, I must say mcpauth, authored by oidebrett, has been a game-changer. The seamless integration and user-friendly interface make authentication easy and secure. The comprehensive documentation and stellar support enhance the overall experience. Highly recommend!

    Avatar
    user_jbTLKtvu
    2025-04-23

    As a dedicated user of MCP applications, mcpauth is an exceptional tool created by oidebrett. Its seamless integration and user-friendly interface make authentication processes smooth and efficient. I highly recommend mcpauth to anyone in need of a reliable authentication solution. Its consistent performance and robust features have greatly enhanced my workflow.