Repository navigation
feat: add auth0-ai-mcp package - #171
kishore7snehil wants to merge 7 commits into
Conversation
| VerifyAccessTokenError: If the token is invalid, or is bound to a DPoP key or a client certificate (it has a `cnf` claim) and so cannot be used as a Bearer token. | ||
| AuthServerUnavailableError: If the OIDC discovery document or JWKS cannot be reached. | ||
| """ | ||
| claims = await self._api.verify_access_token(access_token=access_token) |
There was a problem hiding this comment.
This call doesn't pass request_url or request_headers, so a domains resolver on a prebuilt multi-domain api_client receives None for both. Separately, if the resolver fails, the middleware answers 503 with Retry-After rather than 401.
Is that intentional? In particular:
- Is a request-aware resolver meant to be supported in this release?
- Is 503 the expected response when the resolver fails, including for an unrecognized issuer?
There was a problem hiding this comment.
A request-aware domains resolver isn't supported in this release. A static multi-domain list works, create_mcp_client has no resolver option, and a resolver on a prebuilt api_client receives None for the URL and headers. The 503 only happens when the resolver itself fails (it raises or returns an invalid list). A token from an unrecognized issuer is a 401, because core raises VerifyAccessTokenError for it. We can add request context later if a real use case comes up.
- A bearer value with whitespace inside gets a 401 invalid_token without calling Auth0. - 401 and 503 responses carry Cache-Control: no-store. - An exchanged token with no usable expiry and one already expired now raise separate messages. - scopes_supported must be a list of single-value strings, otherwise ConfigurationError is raised at startup. - The mcp import fallback only applies when mcp is not installed, so a renamed class fails loudly.
📋 Changes
Adds
auth0-ai-mcp, a library that secures Model Context Protocol (MCP) servers with Auth0. It is built onauth0-api-pythonand ships no MCP framework of its own, so each framework gets a thin adapter around it. Guides and a runnable example follow in separate PRs.✨ Features
Principal.Auth0AsgiMiddlewarewraps any ASGI app. It answers401for a missing, malformed or invalid token and503when Auth0 cannot be reached, before the MCP handler runs. A bearer value with whitespace inside is rejected without calling Auth0. The401challenge carriesscopewhenscopes_supportedis set, and401and503responses sendCache-Control: no-store. It also serves protected resource metadata.scopes_supportedmust be a list of single-value strings, otherwiseConfigurationErroris raised at startup.require_scopesandwith_required_scopesgate tools on the caller's scopes.token_storefor caching through the core SDK.create_mcp_client.test.ymlruns the tests andruffon Python 3.10 to 3.14, anddependabot.ymlgets a pip entry for the package.🔧 API Changes
New public API exported from
auth0_ai_mcp, withAuth0AsgiMiddlewareimported fromauth0_ai_mcp.middleware. Nothing existing changes.📖 Documentation
Adds a short
README.mdandCONTRIBUTING.md. The guides and examples are added in follow-up PRs.🧪 Testing
The package has 273 unit tests that stub the core client, so they need no Auth0 tenant.
pytest,ruff check .andpoetry buildpass locally.auth0-api-pythonis pinned to a commit SHA until the release that includes the token caching, malformed-token andclient_infochanges is published. This PR stays a draft until the pin is replaced with a released version.Contributor Checklist