Repository navigation
Description
Environment
fastmcp4.0.10 (latest on PyPI;mainat0ac49deehas the same line),mcp2.2.0,pydantic2.13.5, Python 3.13AuthKitProviderwithauthkit_domain="https://<our-env>.authkit.app", which has no trailing slash, served over Streamable HTTP- Clients:
fastmcp.Client(url, auth="oauth")and themcpPython SDK'sOAuthClientProvider
A caveat first: we may well be holding this wrong. If there is a supported way to make AuthKitProvider advertise the domain exactly, a pointer would be very welcome, and we will close this ourselves. Thanks for FastMCP; AuthKitProvider saved us a lot of code.
What happens
The protected-resource metadata lists the AuthKit domain with a trailing slash:
GET /.well-known/oauth-protected-resource/mcp
{"resource": "https://mcp.example.com/mcp", "authorization_servers": ["https://<our-env>.authkit.app/"], ...}
AuthKit's own metadata (/.well-known/oauth-authorization-server) says "issuer": "https://<our-env>.authkit.app", with no slash. So the OAuth client in the mcp SDK, and fastmcp.Client(auth="oauth") on top of it, refuses to sign in:
RuntimeError: Client failed to connect: Authorization server metadata issuer mismatch: https://<our-env>.authkit.app != https://<our-env>.authkit.app/
Why, as far as we can tell
fastmcp/server/auth/providers/workos.py(around line 388 in 4.0.10) passesauthorization_servers=[AnyHttpUrl(self.authkit_domain)].- A plain pydantic
AnyHttpUrlturns an empty path into/:str(AnyHttpUrl("https://example.authkit.app"))is"https://example.authkit.app/". ThemcpProtectedResourceMetadatamodel would keep a plain string as written (url_preserve_empty_path=True), but it receives a URL object that already has the slash. - The
mcpclient checks the issuer exactly (validate_metadata_issuerinmcp/client/auth/utils.py, called fromoauth2.py). RFC 8414 §3.3, RFC 9728 §2 and the MCP authorization spec's discovery section all require the metadataissuerto be identical to the issuer identifier, with no slash normalisation.
Minimal repro (no WorkOS account needed)
from pydantic import AnyHttpUrl
from starlette.testclient import TestClient
from fastmcp import FastMCP
from fastmcp.server.auth.providers.workos import AuthKitProvider
print(str(AnyHttpUrl("https://example.authkit.app"))) # https://example.authkit.app/
auth = AuthKitProvider(authkit_domain="https://example.authkit.app", base_url="https://mcp.example.com")
print([str(u) for u in auth.authorization_servers]) # ['https://example.authkit.app/']
with TestClient(FastMCP("x", auth=auth).http_app(path="/mcp")) as c:
print(c.get("/.well-known/oauth-protected-resource/mcp").json()["authorization_servers"])
# ['https://example.authkit.app/'] (AuthKit's issuer has no slash)Output on our machine (2026-10-04): the three lines above, each with the trailing slash.
Expected
authorization_servers holds the AuthKit domain exactly as configured (https://<env>.authkit.app), so it matches AuthKit's issuer and OAuth clients can sign in. The smallest fix is to pass the string through, authorization_servers=[self.authkit_domain], since mcp's metadata model keeps it as written.
Meanwhile
We override the attribute after constructing the provider, so FastMCP keeps the verifier, the audience binding and the metadata forwarding. A plain string is enough, because mcp's ProtectedResourceMetadata sets url_preserve_empty_path=True and keeps it as written:
auth = AuthKitProvider(authkit_domain=domain, base_url=base_url)
auth.authorization_servers = [auth.authkit_domain] # type: ignore[list-item]Clients that send a static bearer and skip OAuth discovery are not affected. We're happy to open a PR or test a fix.
Activity
mikamikasuki commentedon Oct 4, 2026
I reproduced the issuer mismatch on current main. I’ll submit a focused fix with regression coverage shortly.
fix(auth): preserve AuthKit issuer identity (PrefectHQ#5452)