mcp-auth-poc

mcp-auth-poc

A minimal MCP server with token-based authentication and SSE transport, providing greeting and echo tools for testing authentication patterns in remote MCP servers.

Category
访问服务器

README

MCP Authentication & Security Proof of Concept

Purpose: Test and validate authentication patterns for remote MCP servers before integrating into the main e2b2 learning platform.

🎯 Project Context

This PoC is part of the e2b2 intelligent learning platform project. The main platform uses MCP (Model Context Protocol) tools to deliver personalized coding education through Claude Desktop.

Why This PoC Exists:

  • Validate token-based authentication for remote MCP servers
  • Test development workflow with security enabled
  • Understand Replit deployment process
  • Provide a reference implementation for the main project
  • Ensure authentication doesn't impede rapid development

Connection to Main Project:

  • Main project location: ../v3/
  • Main project uses 8 core MCP tools (see ../v3/docs/)
  • This PoC validates the authentication layer that will wrap those tools
  • Learnings from this PoC will be applied to the production architecture

📋 What This PoC Does

A minimal MCP server with:

  • 2 simple tools (greeting generator and message echo)
  • Token-based authentication (optional, can be disabled for development)
  • SSE transport for remote connections
  • User context injection (simulates student identification)
  • Well-documented code (serves as example for main implementation)

🏗️ Architecture Overview

┌─────────────────┐
│  Claude Desktop │ (or OpenAI client)
└────────┬────────┘
         │ HTTP + Bearer Token
         ▼
┌─────────────────┐
│  Auth Middleware│ ◄── Validates token, extracts user
└────────┬────────┘
         │ Adds user context
         ▼
┌─────────────────┐
│   MCP Server    │ ◄── Tools receive authenticated user
└─────────────────┘
         │
         ▼
┌─────────────────┐
│  Tool Handlers  │ ◄── get_greeting, echo_message
└─────────────────┘

Key Design Decisions:

  • Token-based auth (not OAuth) for simplicity in PoC
  • Environment variable toggle for auth (easy local dev)
  • User context passed to all tools (pattern for main project)
  • Minimal dependencies (FastMCP, Uvicorn, python-dotenv)

📚 Documentation Structure

docs/
├── 01_CONTEXT.md              # Why this PoC exists, relationship to main project
├── 02_AUTHENTICATION.md       # Authentication architecture and decisions
├── 03_LOCAL_DEVELOPMENT.md    # Local setup and testing
├── 04_REPLIT_DEPLOYMENT.md    # Deploying to Replit
├── 05_CLIENT_SETUP.md         # Connecting Claude Desktop / OpenAI
└── 06_LESSONS_LEARNED.md      # Findings to apply to main project

🚀 Quick Start

Prerequisites

  • Python 3.10+
  • pip or uv package manager
  • Claude Desktop (or OpenAI compatible client)

Local Development (No Auth)

# 1. Navigate to project
cd /path/to/v3_3_auth_and_sec

# 2. Install dependencies
pip install -r requirements.txt

# 3. Run server
python server.py

Server runs at http://localhost:8000

Local Development (With Auth)

# 1. Create environment file
cp .env.example .env

# 2. Edit .env and set AUTH_ENABLED=true

# 3. Run server
python server.py

Testing the Tools

Option 1: Claude Desktop (see docs/05_CLIENT_SETUP.md)

{
  "mcpServers": {
    "auth-poc": {
      "command": "python",
      "args": ["/absolute/path/to/server.py"]
    }
  }
}

Option 2: MCP Inspector

npx @modelcontextprotocol/inspector python server.py

Option 3: Direct HTTP (with auth)

curl http://localhost:8000/tools \
  -H "Authorization: Bearer tok_test1_abc123"

📁 Project Structure

v3_3_auth_and_sec/
├── README.md                 # This file - project overview
├── requirements.txt          # Python dependencies
├── .env.example              # Example configuration
├── .env                      # Your local config (git-ignored)
├── .gitignore                # Ignore patterns
│
├── server.py                 # Main MCP server (well-documented)
├── auth_middleware.py        # Authentication logic (well-documented)
├── tools.py                  # Tool implementations (well-documented)
│
└── docs/                     # Comprehensive documentation
    ├── 01_CONTEXT.md
    ├── 02_AUTHENTICATION.md
    ├── 03_LOCAL_DEVELOPMENT.md
    ├── 04_REPLIT_DEPLOYMENT.md
    ├── 05_CLIENT_SETUP.md
    └── 06_LESSONS_LEARNED.md

🔑 Authentication Flow

sequenceDiagram
    participant Client as Claude Desktop
    participant Middleware as Auth Middleware
    participant Server as MCP Server
    participant Tool as Tool Handler

    Client->>Middleware: Request + Bearer Token
    Middleware->>Middleware: Validate Token
    Middleware->>Middleware: Extract User Info
    Middleware->>Server: Request + User Context
    Server->>Tool: Execute with User
    Tool-->>Client: Response with User Data

🧪 Testing Checklist

  • [ ] Local server runs without auth
  • [ ] Local server runs with auth enabled
  • [ ] Claude Desktop connects locally (no auth)
  • [ ] Claude Desktop connects locally (with auth)
  • [ ] Deploy to Replit successfully
  • [ ] Claude Desktop connects to Replit (with auth)
  • [ ] Multiple users can connect with different tokens
  • [ ] Invalid tokens are rejected with clear errors

📖 Key Files to Understand

  1. server.py - Entry point, shows how FastMCP + auth middleware integrate
  2. auth_middleware.py - Core authentication logic, user extraction
  3. tools.py - Example tools that use user context
  4. docs/02_AUTHENTICATION.md - Deep dive on authentication architecture

🎓 Learning Objectives

After working through this PoC, you should understand:

  • ✅ How to add authentication to FastMCP servers
  • ✅ How to toggle auth for development vs production
  • ✅ How to inject user context into MCP tool handlers
  • ✅ How to deploy authenticated MCP servers to Replit
  • ✅ How to connect remote authenticated servers to Claude Desktop
  • ✅ Patterns to apply to the main e2b2 platform

🔄 Next Steps After PoC

  1. Validate locally - Ensure auth works as expected
  2. Deploy to Replit - Test remote authentication
  3. Document learnings - Update docs/06_LESSONS_LEARNED.md
  4. Apply to main project - Integrate patterns into ../v3/

🤝 Development Notes

Code Style:

  • Comprehensive docstrings on all functions
  • Inline comments for complex logic
  • Type hints for clarity
  • Clear variable names

This code is intentionally over-documented to serve as a reference for the main project implementation.

🔗 Related Documentation

  • Main Project: ../v3/README.md
  • MCP Specification: https://modelcontextprotocol.io
  • FastMCP Docs: https://github.com/jlowin/fastmcp
  • Replit Docs: https://docs.replit.com

📞 Questions?

If you encounter issues:

  1. Check the relevant doc in docs/
  2. Review code comments in the .py files
  3. Consult docs/06_LESSONS_LEARNED.md for known issues
  4. Refer back to the main project's architecture docs

Project Status: PoC Phase Last Updated: 2025-10-11 Main Project: e2b2 Learning Platform (../v3/)

推荐服务器

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

官方
精选