mcp-use Scalekit MCP Auth
mcp-use + Scalekit MCP Auth
Scalekit OAuth 2.1 で認証する mcp-use MCP サーバーです。
チームメンバーは 1 つのサーバー URL を共有します。各人がサインインします。ツールは共有 API キーではなく、その人の ID(ctx.auth.user.id)を参照します。
この例では @scalekit-sdk/node を使用せず、Scalekit のクライアント ID やシークレットも必要ありません。リソースサーバーは Scalekit JWKS に対して JWT を検証します。
クックブック形式の手順は docs/v2/typescript/server/authentication/providers/scalekit.mdx にあります。この README はこのリポジトリの実行手順書です。
[!IMPORTANT] ご自身の Scalekit 環境を使用してください。このリポジトリにはプレースホルダーのみが含まれています。
.envは絶対にコミットしないでください。
得られるもの
/mcpでの Streamable HTTP MCPRFC 9728 の保護リソースメタデータを指す 401 +
WWW-Authenticate認可サーバーとしての Scalekit(DCR および CIMD)
whoami— 認証済みユーザー、スコープ、トークンのiss/audgreet—ctx.auth.user.idをキーとするツール
Related MCP server: Access Self-Hosted MCP Server
クライアントのサインイン方法
sequenceDiagram
participant Client as MCP client
participant Server as This server
participant SK as Your Scalekit env
Client->>Server: POST /mcp (no token)
Server-->>Client: 401 + WWW-Authenticate
Client->>Server: GET /.well-known/oauth-protected-resource/mcp
Server-->>Client: authorization_servers = Scalekit resource issuer
Client->>SK: Discover AS metadata, register via DCR or CIMD
Client->>SK: User signs in and consents
SK-->>Client: Access token (aud includes res_…)
Client->>Server: POST /mcp Authorization: Bearer …
Server-->>Client: Tool result scoped to ctx.auth.user.id前提条件
Node.js 22.22.2 以降
認証方法を少なくとも 1 つ有効にしていること(Google、GitHub、パスワードレス、またはエンタープライズ SSO)
1. Scalekit で MCP サーバーを登録する
MCP Auth クイックスタートに従い、以下の値を使用します。
Scalekit Dashboard を開き、MCP servers → Add MCP server の順に選択します。
名前を付けます。その名前は同意画面に表示されます。
dynamic client registration と Client ID Metadata Document (CIMD) を有効にします。Inspector、Claude、Cursor などのパブリッククライアントは少なくともいずれか 1 つが必要です。両方オンにしておいてください。
詳細設定で Server URL を次の値に設定します。
http://localhost:3000/mcp末尾にスラッシュを付けないでください。設定すると、Scalekit はこの URL をアクセストークンの
audクレームにres_…ID とともに書き込みます。空のままにすると、audはres_…のみになります。この例はその場合でも検証に成功します。保存します。サーバーページから以下をコピーします。
Environment URL —
https://<your-env>.scalekit.cloudResource ID —
res_…
[!CAUTION] 後で DCR または CIMD を切り替えた場合は、MCP クライアントを接続し直してください。Inspector などのクライアントは認可サーバーのメタデータをキャッシュします。このプロセスはキャッシュしません。
2. このリポジトリを設定する
git clone git@github.com:scalekit-developers/scalekit-mcpuse-example.git
cd scalekit-mcpuse-example
npm install
cp .env.example .env.env をご自身の値で編集してください。このリポジトリにはサンプルの認証情報はありません。
SCALEKIT_ENVIRONMENT_URL=https://your-env.scalekit.cloud
SCALEKIT_RESOURCE_ID=res_xxxxxxxx
MCP_URL=http://localhost:3000/mcp変数 | 取得元 |
| Dashboard → API credentials → Environment URL |
| Dashboard → MCP servers → このサーバー → |
| Server URL と完全に一致させる(末尾スラッシュなし) |
SCALEKIT_CLIENT_ID や SCALEKIT_CLIENT_SECRET はありません。リソースサーバーは、Scalekit がすでに発行したトークンのみを検証します。
3. 実行してサインインする
npm run devMCP endpoint | |
Inspector |
Inspector を開きます。
http://localhost:3000/mcpに接続します。最初の呼び出しは 401 を返します。Inspector が Scalekit ログインを開始します。ブラウザで同意を完了します。
whoamiを呼び出します。
usr_… の ID、subjectType: "user"、openid / profile などのスコープ、および以下が表示されるはずです。
{
"iss": "https://your-env.scalekit.cloud",
"aud": ["http://localhost:3000/mcp", "res_xxxxxxxx"]
}iss が https://your-env.scalekit.cloud/resources/res_xxxxxxxx の場合もあります。この例では、Scalekit が issuer 値を移行している間、両方を受け入れます。
次に greet を呼び出します。挨拶は、検証済みトークンの ctx.auth.user.id を使用します — これは、ツールのデータをユーザーごとにスコープするためのパターンです。
検証の仕組み
oauth: oauthScalekitProvider({
environmentUrl: process.env.SCALEKIT_ENVIRONMENT_URL!,
resourceId: process.env.SCALEKIT_RESOURCE_ID!,
resource: process.env.MCP_URL!,
}),resourceId は JWT の aud(res_…)です。resource は公開されている MCP URL です。mcp-use は resource を RFC 9728 の保護リソースメタデータに配置します。これは 2 つ目のオーディエンスチェックではありません。
チェック | ソース |
署名 |
|
| 環境ルート または |
|
|
ID |
|
resourceId はサーバーごとのセキュリティ境界です。同じ Scalekit 環境内の別の MCP サーバー向けに発行されたトークンは失敗する必要があります。
認可はツールのそばに置くべきです。
async (_args, ctx) => {
// ctx.auth.user.id is this caller — scope your data to it
if (!ctx.auth.scopes.includes("todos:write")) {
return { isError: true, content: [{ type: "text", text: "Missing scope" }] };
}
};oauth/scalekit.ts は、ファーストクラスの mcp-use/oauth/scalekit アダプターのプロトタイプです。まだ npm には公開されていません。
プロジェクト構成
パス | 役割 |
| mcp-use サーバー、OAuth 配線、 |
| JWT + JWKS プロバイダー |
| クックブック: Scalekit で mcp-use サーバーを認証する |
| プレースホルダーのみ |
公開 URL を変更する
サーバーを公開する場合(トンネル、デプロイ、カスタムホスト):
Scalekit の Server URL をそのオリジン +
/mcpに設定します(末尾スラッシュなし)。MCP_URLを同じ文字列に設定します。このプロセスを再起動します。
検証側は変わりません。resourceId がオーディエンスチェックのままです。
トラブルシューティング
症状 | 考えられる原因 |
起動時に |
|
Inspector がログインを開始しない | DCR と CIMD が両方オフ — 少なくとも 1 つを有効にして保存する。すでにオンの場合は、Inspector に接続し直してキャッシュされたメタデータを破棄する |
ログインは成功するがすべてのツールが 401 になる | Server URL が |
| Server URL がダッシュボードで空のまま — それでも有効。この例は |
401 でクレームの詳細が必要 |
|
Scalekit は MCP 認証のトラブルシューティングガイドも公開しています。
セキュリティ
クライアントシークレット、API キー、個人の環境 URL をこのリポジトリに置かないでください。
.envは gitignore されています。.env.exampleのみをコミットしてください。このプロセスはクライアントシークレットを使用して Scalekit を呼び出すことはありません。ベアラートークンの検証のみを行います。
MCP_USE_OAUTH_DEBUG=1はiss/aud/subを確認するため JWT ペイロードをデコードします。トークンを出力することはありません。
ドキュメント
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 Connectors
Self-hosted federated MCP gateway: one OAuth 2.1 MCP server in front of N apps, user-level scopes.
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.
MCP server for Argo RPG Platform — connects AI assistants to campaign data via OAuth2
An authenticated remote MCP server for user-owned devices and one-shot capability invocation.
Related MCP Servers
- 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.26,177MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server protected by Cloudflare Access, validating JWTs to conditionally expose tools based on user identity.2,013MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server demonstrating OAuth 2.0 authentication with Keycard's Security Token Service, providing tools for displaying the Keycard logo and retrieving authenticated user information.171Apache 2.0
- FlicenseNot gradedqualityCmaintenanceA toy MCP server demonstrating OAuth 2.1 scoped authorization with three tools for minion status, listing, and summoning.
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/scalekit-developers/scalekit-mcpuse-example'
If you have feedback or need assistance with the MCP directory API, please join our Discord server