mcp-use Scalekit MCP Auth
An MCP server demonstrating OAuth 2.1 authentication with Scalekit, enabling per-user identity in MCP tools through JWT verification.
README
<p align="left"> <a href="https://scalekit.com" target="_blank" rel="noopener noreferrer"> <img src="https://cdn.scalekit.cloud/v1/scalekit-logo-dark.svg" height="64" alt="Scalekit"> </a> </p>
mcp-use + Scalekit MCP Auth
An mcp-use MCP server that authenticates with Scalekit OAuth 2.1.
Teammates share one server URL. Each person signs in. Tools see their identity (ctx.auth.user.id), not a shared API key.
This example does not use @scalekit-sdk/node and does not need a Scalekit client id or secret. The resource server verifies JWTs against Scalekit JWKS.
The cookbook-style how-to lives in docs/v2/typescript/server/authentication/providers/scalekit.mdx. This README is the runbook for this repository.
[!IMPORTANT] Use your own Scalekit environment. This repository ships placeholders only. Never commit
.env.
What you get
- Streamable HTTP MCP at
/mcp - 401 +
WWW-Authenticatepointing at RFC 9728 protected-resource metadata - Scalekit as the authorization server (DCR and CIMD)
whoami— authenticated user, scopes, and tokeniss/audgreet— a tool that keys offctx.auth.user.id
How a client signs in
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
Prerequisites
- Node.js 22.22.2 or newer
- A Scalekit account (sign up if you do not have one)
- At least one auth method enabled (Google, GitHub, passwordless, or enterprise SSO)
1. Register an MCP server in Scalekit
Follow the MCP Auth quickstart with these values:
-
Open Scalekit Dashboard → MCP servers → Add MCP server.
-
Give it a name. That name appears on the consent screen.
-
Enable dynamic client registration and Client ID Metadata Document (CIMD). Public clients such as Inspector, Claude, and Cursor need at least one of these; keep both on.
-
Under advanced settings, set Server URL to:
http://localhost:3000/mcpNo trailing slash. When set, Scalekit writes this URL into the access-token
audclaim alongside theres_…id. If you leave it empty,audis onlyres_…— this example still verifies. -
Save. Copy from the server page:
- Environment URL —
https://<your-env>.scalekit.cloud - Resource ID —
res_…
- Environment URL —
[!CAUTION] If you toggle DCR or CIMD later, restart this example. Some MCP clients cache authorization-server metadata.
2. Configure this repo
git clone git@github.com:scalekit-developers/scalekit-mcpuse-example.git
cd scalekit-mcpuse-example
npm install
cp .env.example .env
Edit .env with your values. There are no sample credentials in this repo.
SCALEKIT_ENVIRONMENT_URL=https://your-env.scalekit.cloud
SCALEKIT_RESOURCE_ID=res_xxxxxxxx
MCP_URL=http://localhost:3000/mcp
| Variable | Where it comes from |
|---|---|
SCALEKIT_ENVIRONMENT_URL |
Dashboard → API credentials → Environment URL |
SCALEKIT_RESOURCE_ID |
Dashboard → MCP servers → this server → res_… |
MCP_URL |
Must match Server URL exactly (no trailing slash) |
There is no SCALEKIT_CLIENT_ID or SCALEKIT_CLIENT_SECRET. The resource server only verifies tokens that Scalekit already issued.
3. Run and sign in
npm run dev
| MCP endpoint | http://localhost:3000/mcp |
| Inspector | http://localhost:3000/mcp/inspector |
- Open Inspector.
- Connect to
http://localhost:3000/mcp. The first call returns 401; Inspector starts Scalekit login. - Complete consent in the browser.
- Call
whoami.
You should see a usr_… id, subjectType: "user", scopes such as openid / profile, and:
{
"iss": "https://your-env.scalekit.cloud",
"aud": ["http://localhost:3000/mcp", "res_xxxxxxxx"]
}
iss may also be https://your-env.scalekit.cloud/resources/res_xxxxxxxx. This example accepts both while Scalekit migrates issuer values.
Then call greet. The greeting uses ctx.auth.user.id from the verified token — that is the pattern for scoping tool data per user.
How verification works
oauth: oauthScalekitProvider({
environmentUrl: process.env.SCALEKIT_ENVIRONMENT_URL!,
resourceId: process.env.SCALEKIT_RESOURCE_ID!,
resource: process.env.MCP_URL!,
}),
| Check | Source |
|---|---|
| Signature | JWKS at {environmentUrl}/keys (from live AS metadata — not a guessed path) |
iss |
Environment root or {environmentUrl}/resources/{resourceId} |
aud |
Must include resourceId (res_…) |
| Identity | ctx.auth.user.id is the token sub |
resourceId is the per-server security boundary. A token minted for a different MCP server in the same Scalekit environment must fail.
Authorization belongs next to the tool:
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 is a prototype of a first-class mcp-use/oauth/scalekit adapter. It is not published on npm yet.
Project structure
| Path | Role |
|---|---|
index.ts |
mcp-use server, OAuth wiring, whoami and greet |
oauth/scalekit.ts |
JWT + JWKS provider |
docs/v2/.../scalekit.mdx |
Cookbook: authenticate an mcp-use server with Scalekit |
.env.example |
Placeholders only |
Changing the public URL
If you expose the server (tunnel, deploy, custom host):
- Set Server URL in Scalekit to that origin +
/mcp(no trailing slash). - Set
MCP_URLto the same string. - Restart this process.
The verifier does not change. resourceId stays the audience check.
Troubleshooting
| Symptom | Likely cause |
|---|---|
Server throws on boot about SCALEKIT_* or MCP_URL |
.env is missing or a value is empty |
| Inspector never starts login | DCR/CIMD off, or you did not restart after toggling them |
| Login works, every tool is 401 | Server URL does not match MCP_URL (trailing slash, wrong port, http vs https) |
whoami aud has only res_… |
Server URL was left empty in the dashboard — still valid; this example binds on resourceId |
| Need claim details on a 401 | Set MCP_USE_OAUTH_DEBUG=1 and retry. Logs print iss, aud, sub — never the raw token |
Scalekit also publishes a MCP auth troubleshooting guide.
Security
- Do not put client secrets, API keys, or personal environment URLs in this repository.
.envis gitignored. Commit only.env.example.- This process never calls Scalekit with a client secret. It only verifies bearer tokens.
MCP_USE_OAUTH_DEBUG=1decodes the JWT payload foriss/aud/sub. It does not print the token.
Docs
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。