claude-ia-mcp-tools-auth
OAuth認証付きMCPツール
OAuth認証を備えたMCP(Model Context Protocol)サーバーの構築方法を示すPythonの例です。APIクライアント、ビジネスロジック層、保護されたMCPツールを組み合わせています。
特徴
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でユーザーを1件取得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