Routes & well-known endpoints
RFC 8414 / RFC 9728 metadata endpoints and Dynamic Client Registration façade.
auth_routes
mcpauthkit.auth_routes — generic MCP OAuth metadata endpoints.
Provides the well-known OAuth protected-resource and authorization-server discovery documents required by the MCP OAuth spec, plus a Dynamic Client Registration (DCR) façade that returns a pre-registered public client ID.
Works with any standard OIDC provider (Keycloak, Okta, Entra ID, Duende, …).
Usage
from mcpauthkit.auth_routes import oauth_meta_router
app.include_router(oauth_meta_router(
server_base_url="http://localhost:8005",
issuer_url="http://localhost:8889/realms/mcp-quickstart",
client_id="mcp-quickstart-vscode",
))
Call include_router before app.mount("/", ...).
oauth_meta_router
oauth_meta_router(
*,
server_base_url: str,
issuer_url: str,
client_id: str,
extra_authorize_params: dict[str, str] | None = None,
) -> APIRouter
Return an APIRouter with well-known OAuth metadata routes and a DCR
façade. Mount it on the app with app.include_router(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_base_url
|
str
|
Full URL of this MCP server, e.g. |
required |
issuer_url
|
str
|
Base URL of the OIDC issuer,
e.g. |
required |
client_id
|
str
|
Pre-registered public client ID returned by the DCR façade. |
required |
extra_authorize_params
|
dict[str, str] | None
|
Optional extra query parameters appended to the
Use this for provider-specific routing parameters that fall outside
the standard OAuth 2.0 / OIDC spec. For example, Okta's
Default: |
None
|
Source code in mcpauthkit/auth_routes.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
Provider-specific routing hints
Some OIDC providers accept extra query parameters on the authorization endpoint
that route users to a specific Identity Provider without showing the provider's
own login page. Pass them via extra_authorize_params — they are appended to
the authorization_endpoint URL returned in
/.well-known/oauth-authorization-server, which MCP clients use verbatim.
Okta — routing to an external Identity Provider
Okta's idp parameter bypasses the Okta login page and sends users directly to
a configured external IdP (Microsoft Entra, Google Workspace, a SAML IdP, …).
The value is the IdP ID shown in the Okta Admin Console under
Security → Identity Providers.
app.include_router(oauth_meta_router(
server_base_url=settings.server_base_url,
issuer_url="https://your-org.okta.com/oauth2/default",
client_id=settings.okta_client_id,
extra_authorize_params={"idp": "0oaz2r21a8RBmZyOL0h7"},
))
The resulting authorization_endpoint in the well-known document will be:
https://your-org.okta.com/oauth2/default/v1/authorize?idp=0oaz2r21a8RBmZyOL0h7
MCP clients (VS Code Copilot, MCP Inspector, …) read this URL and include the
idp hint when redirecting the user, so they are sent straight to the external
IdP without ever seeing the Okta login screen.