Repository navigation
Description
Bug description
When a DCR upstream is configured with dcrConfig.discoveryUrl
(https://host.example.com/.well-known/oauth-authorization-server), ToolHive derives the expected
issuer as https://host.example.com and compares it byte for byte with the issuer in the fetched
metadata. An authorization server that publishes "issuer": "https://host.example.com/" is rejected:
issuer mismatch (RFC 8414 §3.3): expected "https://host.example.com", got "https://host.example.com/"
Registration then fails and the upstream is unusable. Servers built on FastMCP's OAuth proxy publish
exactly this form for any root-URL deployment (see "Additional context").
Steps to reproduce
- Run an MCP server that is its own OAuth authorization server through FastMCP's proxy at a root
URL. For example mcp-atlassian 0.24.8 withATLASSIAN_OAUTH_PROXY_ENABLE=true,
PUBLIC_BASE_URL=https://host.example.com, plus the required dummyJIRA_URL,
ATLASSIAN_OAUTH_CLIENT_ID,ATLASSIAN_OAUTH_CLIENT_SECRETand
ATLASSIAN_OAUTH_REDIRECT_URIvalues. The discovery routes make no upstream calls. curl -s https://host.example.com/.well-known/oauth-authorization-serverreturns
"issuer":"https://host.example.com/".- Configure an OAuth2 upstream with DCR and
discoveryUrl: https://host.example.com/.well-known/oauth-authorization-server. - Resolve the registration. It fails with the error above.
PUBLIC_BASE_URL makes no difference at a root URL:
PUBLIC_BASE_URL |
published issuer |
|---|---|
https://host.example.com |
https://host.example.com/ |
https://host.example.com/ |
https://host.example.com/ |
https://host.example.com/mcp-atlassian |
https://host.example.com/mcp-atlassian |
Expected behavior
The two forms identify the same issuer. Per RFC 3986 §6.2.3, an http(s) URI with an empty path
normalizes to a path of /. Registration should succeed.
Actual behavior
fetchDiscoveryDocument requires exact string equality, so registration fails. The expected issuer
is derived from the discovery URL and cannot be overridden. registrationEndpoint avoids discovery
but needs explicit endpoints and leaves the token endpoint auth method to default selection.
Environment
- ToolHive: v0.68.0. The same comparison is on
mainat a4dc984 (pkg/oauthproto/discovery.go:318). - Server: mcp-atlassian 0.24.8, FastMCP 3.4.11, MCP Python SDK 1.30.0. FastMCP 4.2.5 behaves the same.
Additional context
Where the trailing slash comes from on the server side:
- mcp-atlassian passes
PUBLIC_BASE_URLthrough unmodified and sets noissuer_url:
servers/main.pyL1167, L1200 - FastMCP builds
AnyHttpUrl(base_url)(L366) and defaults the issuer to it (L1098):
auth.py - The MCP SDK publishes that object as
issuer(L171) while stripping the slash withrstrip("/")
for the endpoints it builds (L158, L159, L191):
routes.py
ToolHive side:
deriveExpectedIssuerFromDiscoveryURL
(L1330) already normalizes a stray / on the discovery URL so the expected issuer stays slash-free.
The document's own issuer gets no equivalent treatment.
Related: #5390 (path-insertion discovery) and #1957 (issuer mismatch).
Proposed change
Compare issuers with a helper that treats an empty path and / as equal, and nothing else:
// Sketch, not compiled.
// issuersEqual reports whether expected and got are the same issuer under RFC 8414 §3.3,
// treating an empty path and "/" as equivalent (RFC 3986 §6.2.3).
func issuersEqual(expected, got string) bool {
if expected == got {
return true
}
e, errE := url.Parse(expected)
g, errG := url.Parse(got)
if errE != nil || errG != nil {
return false
}
rootOnly := func(u *url.URL) bool { return u.Path == "" || u.Path == "/" }
return rootOnly(e) && rootOnly(g) &&
e.Scheme == g.Scheme && e.Host == g.Host &&
e.RawQuery == "" && g.RawQuery == "" && e.Fragment == "" && g.Fragment == ""
}The check stays as strict as before where it protects against mix-up attacks. Scheme, host and port
must still match exactly, and a path issuer keeps byte-exact equality, including a trailing slash.
Tests: exact match, slash on either side, a different host, a different scheme, a different port,
a path issuer with and without a trailing slash (both must still mismatch), and query or fragment
present.
An alternative is a dcrConfig field to pin the expected issuer. It has a larger surface and leaves
the default experience broken for FastMCP-based servers.
Activity
media-ctrl commentedon Nov 25, 2026
The normalisation you want already exists one function away.
deriveExpectedIssuerFromDiscoveryURLcollapses a stray "/" to an empty path in the insert branch, and its own comment says the reason is that "https://host/" would otherwise fail the section 3.3 byte-equality check. The metadata side never gets that treatment:fetchDiscoveryDocumentcomparesmetadata.IssuertoexpectedIssuerwith !=, and the append branch derives the bare origin.So the mismatch is asymmetric by construction. Your expected value is normalised to https://host, the server publishes the form your own comment calls spurious, and the comparison is byte equality.
Fix: compare normalised forms on both sides, mapping an empty path to "/" and lowercasing scheme and host, never touching a non-empty path. RFC 3986 section 6.2.3 is explicit that an empty path should be normalised to "/", so this is not relaxing 3.3, it is applying it to two spellings of one identifier.
Do not strip a trailing slash from a non-empty path: /a and /a/ are not equivalent under 6.2.3, and treating them as equal would create the mix-up this check prevents.