claude-ia-mcp-tools-auth
OAuth 인증을 포함한 MCP 도구
API 클라이언트, 비즈니스 로직 계층, 보안이 적용된 MCP 도구를 결합하여 OAuth 인증으로 MCP(Model Context Protocol) 서버를 구축하는 방법을 보여 주는 Python 예제입니다.
기능
OAuth 인증 흐름: 브라우저에서 클릭 한 번으로 세션 토큰을 인증합니다.
계층형 아키텍처: API 클라이언트 → 비즈니스 로직 → MCP 도구
보안 도구 액세스: 보호된 도구를 호출하려면 유효한 인증 토큰이 필요합니다.
간단한 HTTP 서버: localhost:5000에서 실행되는 Flask 기반 인증 서버
토큰 관리: 24시간 유효한 세션 토큰과 영속화 지원
Related MCP server: OAuth MCP Server
아키텍처
src/example/
├── api/
│ ├── api_client.py # HTTP API client (JSONPlaceholder)
│ └── http_server.py # Local HTTP server
├── auth/
│ └── manager.py # OAuth token & state management
├── business/
│ └── service.py # Business logic layer
├── http/
│ └── auth_server.py # Flask OAuth auth server
├── mcp/
│ └── server.py # MCP server with auth
└── main.py설치
python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate
pip install -r requirements.txt빠른 시작
1. 인증 서버 시작
python -m src.example.http.auth_server이렇게 하면 OAuth 흐름을 갖춘 Flask 서버가 http://localhost:5000에서 시작됩니다.
홈페이지를 방문합니다.
"Click to Authenticate"를 클릭합니다.
콜백 페이지에서 세션 토큰을 받습니다.
토큰을 복사하여 보관합니다.
2. MCP 서버 시작
다른 터미널에서:
python -m src.example.mcp.server3. MCP 도구 사용
이제 MCP 서버는 인증이 필요합니다. 먼저 인증 URL을 가져오세요.
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | python -m src.example.mcp.server그런 다음 토큰으로 인증하고 도구를 사용하세요.
echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_user","arguments":{"user_id":1},"auth_token":"YOUR_SESSION_TOKEN"},"id":1}' | python -m src.example.mcp.server인증 흐름
인증 URL 가져오기:
get_auth_url도구를 호출합니다(인증 불필요).{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_auth_url","arguments":{}},"id":1}브라우저에서 클릭: 사용자가 반환된 인증 URL을 클릭합니다.
http://localhost:5000/auth/callback?state=...페이지가 열립니다.브라우저에 세션 토큰과 함께 성공 페이지가 표시됩니다.
토큰은 24시간 동안 유효합니다.
토큰 사용: 모든 도구 호출에
auth_token을 포함합니다.{"params":{"name":"get_user","arguments":{"user_id":1},"auth_token":"YOUR_TOKEN"}}
사용 가능한 도구
공개(인증 불필요)
get_auth_url- OAuth 인증 URL 가져오기
보호됨(인증 필요)
get_user- ID로 사용자 조회list_users- 모든 사용자 조회create_user- 새 사용자 생성update_user- 사용자 이름/이메일 수정delete_user- 사용자 삭제
구성
환경 변수를 설정하세요.
export PORT=5000 # Auth server port
export FLASK_SECRET_KEY=your-secret-key # Flask secret (change in production!)테스트
pytest로 테스트를 실행하세요.
pytest -v
pytest --cov=src # With coverage
pytest tests/test_auth.py # Auth tests only셸 스크립트 실행
sh test-auth-flow.sh
========================================
MCP Auth Server - Complete Flow Test
========================================
Base URL: https://claude-ia-mcp-tools-auth-staging.up.railway.app
Step 1: Start Auth Flow
GET /auth/start
Status: 401
Auth URL: https://claude-ia-mcp-tools-auth-staging.up.railway.app/auth/callback?state=Xukdt6MwHba0n0UfkOX3lAAanm7MJhSyzomyCJCxj1M
State Token: Xukdt6MwHba0n0UfkOX3lAAanm7MJhSyzomyCJCx...
Step 2: Complete Auth Callback
GET /auth/callback?state=Xukdt6MwHba0n0UfkOX3lAAanm7MJhSyzomyCJCxj1M
Status: 200
Session Token: 7Y6SaanfrLmiOXoE2kUvTbdEfawIMSJyGDaNFPf1...
Step 3: Verify Token with Auth Status
GET /auth/status -H 'Authorization: Bearer 7Y6SaanfrLmiOXoE2kUvTbdEfawIMSJyGDaNFPf1-Bg'
Response:
{"authenticated":true,"user_id":"user_1b25e4982c9904b8"}
========================================
TEST RESULTS
========================================
State Token: Xukdt6MwHba0n0UfkOX3lAAanm7MJhSyzomyCJCxj1M
Session Token: 7Y6SaanfrLmiOXoE2kUvTbdEfawIMSJyGDaNFPf1-Bg
Authenticated: true
User ID: user_1b25e4982c9904b8
========================================
Step 4: Test Invalid Token
GET /auth/status -H 'Authorization: Bearer invalid_token_123'
Response: {"authenticated":false,"user_id":null}
SUCCESS: Complete auth flow working correctly!
You can now use this token for MCP:
Authorization: Bearer 7Y6SaanfrLmiOXoE2kUvTbdEfawIMSJyGDaNFPf1-Bg
배포
프로덕션 환경에서는 다음을 업데이트하세요.
FLASK_SECRET_KEY - 강력한 임의 키 사용
OAuth 공급자 - 실제 OAuth(Google, GitHub 등)로 교체
토큰 저장소 -
.auth_tokens.json대신 데이터베이스 사용HTTPS - 인증 엔드포인트에 SSL/TLS 활성화
아키텍처 참고 사항
이 예제는 다음을 보여줍니다.
관심사 분리: API 클라이언트, 비즈니스 로직, MCP 계층이 독립적으로 구성됩니다.
계층형 설계: 컴포넌트 테스트와 교체가 쉽습니다.
인증 통합: 인증 토큰은 헤더가 아닌 파라미터를 통해 전달됩니다.
오류 처리: 인증 실패 시 적절한 오류 응답을 제공합니다.
API 클라이언트는 데모 API로 https://jsonplaceholder.typicode.com을 사용합니다.
MCP/비즈니스 인터페이스를 변경하지 않고 자체 API 구현으로 교체할 수 있습니다.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA complete OAuth 2.1 server implementation for FastMCP with PKCE support, enabling secure authentication and authorization flows. Provides authorization code exchange, token management, and refresh capabilities for building authenticated MCP applications.
- FlicenseNot gradedqualityDmaintenanceAn MCP server for OAuth 2.0 authentication supporting Device Code and Client Credentials flows, enabling secure token management for MCP applications.
- FlicenseNot gradedqualityDmaintenanceA simple MCP server with OAuth 2.0 authentication for testing OAuth support in mcp-cli.
- FlicenseNot gradedqualityCmaintenanceThis MCP server requires user authentication via Auth0 and then enables calling protected APIs (e.g., a Todos API) on behalf of the user.
Related MCP Connectors
Self-hosted federated MCP gateway: one OAuth 2.1 MCP server in front of N apps, user-level scopes.
MCP server for Argo RPG Platform — connects AI assistants to campaign data via OAuth2
Streamable HTTP MCP server for Google Calendar and Sheets with OAuth login.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/vicboma1/claude-ia-mcp-tools-auth'
If you have feedback or need assistance with the MCP directory API, please join our Discord server