mcp-oauth-dcr
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-oauth-dcrrun the OAuth demo with Inspector"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-oauth-dcr
ローカル MCP サーバを OAuth(DCR)で保護するハンズオン用リポジトリです。
認可サーバ (AS):
node-oidc-provider@http://localhost:4000MCP サーバ (RS):
@modelcontextprotocol/sdk@http://localhost:3000/mcp
デモのセットアップ
1. 依存関係のインストール
npm ci2. サーバを起動(ターミナルを 2 つ使う)
# ターミナル 1: 認可サーバ
npm run auth
# ターミナル 2: MCP サーバ
npm run mcp起動確認:
サービス | URL |
認可サーバ | |
MCP サーバ | |
保護リソースメタデータ (PRM) | http://localhost:3000/.well-known/oauth-protected-resource/mcp |
3. 自動検証(任意)
両方起動した状態で:
npx tsx src/verify.ts401 → メタデータ発見 → DCR → トークン検証 → 接続確立 が成功すれば、サーバ側は問題ありません。
4. MCP Inspector で手動デモ
npx @modelcontextprotocol/inspectorターミナルに表示される トークン付き URL(例: http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=...)をブラウザで開きます。
Inspector の設定:
項目 | 値 |
Transport Type | Streamable HTTP |
URL |
|
Connection Type | Via Proxy(Direct は CORS で失敗しやすい) |
Connect を押すと OAuth フローが始まります。
最初に 401(
Missing Authorization header)が出る → 正常DCR でクライアント登録
ブラウザで
http://localhost:4000のログイン画面が開くSign-in → 任意のユーザー名・パスワード(例:
test/password)Continue(同意)
Inspector に戻り、接続完了
whoami/addツールを呼び出せる
5. よくあるトラブル
invalid_client / client is invalid
認可サーバ(npm run auth)を再起動すると、DCR で登録したクライアント情報は メモリ上から消えます。Inspector の sessionStorage には古い client_id が残っていると、このエラーになります。
対処:
Inspector で Connect をやり直す(新規 DCR)
直らなければブラウザの DevTools → Application → Session Storage →
localhost:6274をクリアしてから再接続
Continue 後に Failed to fetch
トークン交換(POST /token)の CORS 問題です。最新の auth-server.ts では clientBasedCORS を設定済みです。npm run auth が最新コードで動いているか確認してください。
Direct 接続で Failed to fetch
Connection Type は Via Proxy を使ってください。
Related MCP server: MCP Auth
jwks.json について
誰が: 認可サーバ(src/auth-server.ts)
いつ: npm run auth の初回起動時(リポジトリ直下に jwks.json が無い場合)
処理の流れ:
loadOrCreateJwks()がjwks.jsonの有無を確認無ければ
joseで RS256 の鍵ペアを生成し、jwks.jsonに書き込むあれば 既存ファイルを読み込んで使う(再起動しても
kidが変わらない)
用途:
AS が JWT アクセストークンに署名する 秘密鍵(ファイル内に含まれる)
AS が
http://localhost:4000/jwksで公開する 公開鍵MCP サーバ(RS)がその JWKS を取りに行き、Bearer トークンの署名を検証する
verify.ts も同じ jwks.json を読んで、デモ用にトークンを自前署名します(本番フローでは AS が /token で発行します)。
.gitignore に入っているので Git にはコミットしません。削除して npm run auth し直すと新しい鍵が生成されます(その間に発行済みトークンは検証できなくなります)。
構成
src/
├── config.ts 共有設定(ポート、issuer、resource URL)
├── auth-server.ts 認可サーバ :4000
├── mcp-server.ts MCP サーバ(リソースサーバ) :3000
└── verify.ts 自動検証スクリプト
jwks.json AS 署名鍵(初回起動時に自動生成・gitignore)スクリプト
コマンド | 説明 |
| 認可サーバ起動 |
| MCP サーバ起動 |
| TypeScript 型チェック |
| OAuth フロー自動検証 |
ライセンス
This server cannot be deployed
Maintenance
Related MCP Connectors
- StytchOAuthdev.stytch.mcp
The Stytch MCP server is a reference implementation that demonstrates remote MCP server authentication and authorization using Stytch Connected Apps. It provides OAuth 2.1-compliant authorization (including PKCE), Dynamic Client Registration, and validates Stytch-issued access tokens to enable AI agents to securely interact with external services through permissioned access, supporting scopes like openid, email, profile, and manage:project_data.
Self-hosted federated MCP gateway: one OAuth 2.1 MCP server in front of N apps, user-level scopes.
MCP server for verifying EUDI/Talao wallet data via OIDC4VP (pull) for AI agents.
MCP server for secureFlows: token-free URL builders and integration-linting tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA self-hostable OAuth 2.0 server designed for the Model-Context-Protocol (MCP) that enables you to secure your MCP applications with a robust implementation you control.1,843 npm112ISC
- AlicenseNot gradedqualityDmaintenanceA remote MCP server implementation that demonstrates authentication and authorization capabilities using OAuth 2.1. This is a workshop project for learning how to build secure MCP servers with user authentication.18,182 npmMIT
- FlicenseNot gradedqualityDmaintenanceA proof-of-concept MCP server implementing OAuth 2.1 authorization with CIMD client registration and PKCE, demonstrating protected resource access and step-up authentication.-
- FlicenseNot gradedqualityDmaintenanceA simple MCP server with OAuth 2.0 authentication for testing OAuth support in mcp-cli.-