此仓库是从 MCP Python SDK 的 simple-auth 示例中分叉出来的。
与原始示例不同,该示例使用自托管的授权服务器,而这个版本使用 Auth0 作为授权服务器。
audience/resource 使用。http://localhost:8042/)。# 在端口 8042 上启动资源服务器,并连接到 Auth0 授权服务器
# 用你的 Auth0 域名替换 https://xxxxxxxxx.us.auth0.com/
uv run mcp-simple-auth0-rs --port=8042 --auth-server=https://xxxxxxxxx.us.auth0.com/ --transport=streamable-http
// 将 MCP 服务器添加到你的 `claude_desktop_config.json`
// Auth0 要求在 /authorize GET 请求中包含 `audience` 参数以返回 JWT 而不是 JWE。
// 参见:https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens#control-access-token-audience
// 我们使用 `pnpm dlx` 来运行修改版 `mcp-remote` 的特定 git 提交,
// 其中包括 `audience` 查询参数以确保返回 JWT。
// 或者你可以克隆仓库
// `git clone https://github.com/CefBoud/mcp-remote.git && cd mcp--remote && npm i && npm run build && npm link`
// 然后使用 `mcp-remote` 命令而不使用 pnpm。
"auth0-mcp": {
"command": "pnpm",
"args": [
"dlx",
"github:CefBoud/mcp-remote#8226c8b08cf281b782ccc0967f4664ec087f7269",
"http://localhost:8042/mcp",
"--resource",
"http://localhost:8042/"
]
}
注意:Auth0 要求在
/authorizeGET 请求中包含audience参数以发出 JWT 而不是 JWE。 上述mcp-remote版本包含了这种行为。
当你启动 Claude Desktop 时,会打开一个浏览器标签页提示进行授权:

授权后,你会被重定向到由 mcp-remote 启动的 localhost 服务器来兑换授权码以换取令牌:

你可以通过以下命令检查保存的令牌和挑战:
ls -lat ~/.mcp-auth/*/
客户端 → 资源服务器:
curl http://localhost:8042/.well-known/oauth-protected-resource
{
"resource": "http://localhost:8042/",
"authorization_servers": [
"https://xxxxxxxxx.us.auth0.com/"
],
"scopes_supported": [],
"bearer_methods_supported": [
"header"
]
}
客户端 → 授权服务器:
curl https://xxxxxxxxx.us.auth0.com/.well-known/oauth-authorization-server
{
"issuer": "https://xxxxxxxxx.us.auth0.com/",
"authorization_endpoint": "https://xxxxxxxxx.us.auth0.com/authorize",
"token_endpoint": "https://xxxxxxxxx.us.auth0.com/oauth/token",
"device_authorization_endpoint": "https://xxxxxxxxx.us.auth0.com/oauth/device/code",
"userinfo_endpoint": "https://xxxxxxxxx.us.auth0.com/userinfo",
"mfa_challenge_endpoint": "https://xxxxxxxxx.us.auth0.com/mfa/challenge",
"jwks_uri": "https://xxxxxxxxx.us.auth0.com/.well-known/jwks.json",
"registration_endpoint": "https://xxxxxxxxx.us.auth0.com/oidc/register",
"revocation_endpoint": "https://xxxxxxxxx.us.auth0.com/oauth/revoke"
// ...
}
客户端根据 RFC 7591 动态注册应用,然后继续执行常规的 OAuth 流程。