Skip to content

AuthKitProvider advertises the AuthKit domain with a trailing slash in authorization_servers, so OAuth clients reject the issuer #5447

Closed

Description

@paddynatte

Environment

  • fastmcp 4.0.10 (latest on PyPI; main at 0ac49dee has the same line), mcp 2.2.0, pydantic 2.13.5, Python 3.13
  • AuthKitProvider with authkit_domain="https://<our-env>.authkit.app", which has no trailing slash, served over Streamable HTTP
  • Clients: fastmcp.Client(url, auth="oauth") and the mcp Python SDK's OAuthClientProvider

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

  1. fastmcp/server/auth/providers/workos.py (around line 388 in 4.0.10) passes authorization_servers=[AnyHttpUrl(self.authkit_domain)].
  2. A plain pydantic AnyHttpUrl turns an empty path into /: str(AnyHttpUrl("https://example.authkit.app")) is "https://example.authkit.app/". The mcp ProtectedResourceMetadata model would keep a plain string as written (url_preserve_empty_path=True), but it receives a URL object that already has the slash.
  3. The mcp client checks the issuer exactly (validate_metadata_issuer in mcp/client/auth/utils.py, called from oauth2.py). RFC 8414 §3.3, RFC 9728 §2 and the MCP authorization spec's discovery section all require the metadata issuer to 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

  1. added
    auth
    bug
    on Oct 4, 2026
  2. mikamikasuki commented on Oct 4, 2026

    @mikamikasuki
    Contributor

    I reproduced the issuer mismatch on current main. I’ll submit a focused fix with regression coverage shortly.

  3. added a commit that references this issue on Oct 5, 2026
    443a6c9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions