360XView/mcp-auth-poc
If you are the rightful owner of mcp-auth-poc and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a comprehensive overview of a Model Context Protocol (MCP) server designed to test and validate authentication patterns for remote MCP servers, specifically for the e2b2 intelligent learning platform.
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
server.py
- Entry point, shows how FastMCP + auth middleware integrateauth_middleware.py
- Core authentication logic, user extractiontools.py
- Example tools that use user contextdocs/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
- Validate locally - Ensure auth works as expected
- Deploy to Replit - Test remote authentication
- Document learnings - Update
docs/06_LESSONS_LEARNED.md
- 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:
- Check the relevant doc in
docs/
- Review code comments in the
.py
files - Consult
docs/06_LESSONS_LEARNED.md
for known issues - Refer back to the main project's architecture docs
Project Status: PoC Phase
Last Updated: 2025-10-11
Main Project: e2b2 Learning Platform (../v3/
)