Skip to content

Commit 8e41474

Browse files
authored
Merge pull request #395 from koic/rfc8414_well_known_suffix
Pin RFC 8414 Default Well-Known Suffix per SEP-2351
2 parents 8c21648 + 2a26ad2 commit 8e41474

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

lib/mcp/client/oauth/discovery.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,17 @@ def protected_resource_metadata_urls(server_url:, resource_metadata_url: nil)
9090
end
9191

9292
# Returns the candidate Authorization Server metadata URLs to probe, in priority order.
93-
# https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#authorization-server-metadata-discovery
93+
#
94+
# Per SEP-2351, MCP uses the default `oauth-authorization-server` well-known URI suffix
95+
# registered by RFC 8414 Section 7.3 and defines no application-specific suffix of its own.
96+
# The OAuth candidates below therefore use only that default suffix
97+
# (plus the `openid-configuration` suffix from OpenID Connect Discovery),
98+
# both in the RFC 8414 Section 3.1 path-inserted form for issuers with a path component
99+
# and in the root form for issuers without one.
100+
#
101+
# - https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#authorization-server-metadata-discovery
102+
# - https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2351
103+
# - https://www.rfc-editor.org/rfc/rfc8414#section-3.1
94104
def authorization_server_metadata_urls(issuer_url)
95105
uri = URI.parse(issuer_url)
96106
path = uri.path == "/" ? "" : uri.path.to_s

test/mcp/client/oauth/discovery_test.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,43 @@ def test_authorization_server_metadata_urls_for_path_issuer
121121
assert_includes(urls, "https://auth.example.com/tenant1/.well-known/openid-configuration")
122122
end
123123

124+
# Per SEP-2351, MCP explicitly uses the RFC 8414 default `oauth-authorization-server` well-known URI suffix
125+
# and defines no application-specific suffix. The first probed candidate for a root issuer must be exactly
126+
# that default suffix.
127+
def test_authorization_server_metadata_urls_probe_rfc8414_default_suffix_first
128+
urls = Discovery.authorization_server_metadata_urls("https://auth.example.com")
129+
130+
assert_equal("https://auth.example.com/.well-known/oauth-authorization-server", urls.first)
131+
end
132+
133+
def test_authorization_server_metadata_urls_use_only_registered_well_known_suffixes
134+
root_urls = Discovery.authorization_server_metadata_urls("https://auth.example.com")
135+
path_urls = Discovery.authorization_server_metadata_urls("https://auth.example.com/tenant1")
136+
137+
(root_urls + path_urls).each do |url|
138+
suffix = url[%r{/\.well-known/([^/]+)}, 1]
139+
140+
assert_includes(
141+
["oauth-authorization-server", "openid-configuration"], suffix, "unexpected well-known suffix in #{url}"
142+
)
143+
end
144+
end
145+
146+
def test_authorization_server_metadata_urls_put_path_inserted_oauth_candidate_first_for_path_issuer
147+
urls = Discovery.authorization_server_metadata_urls("https://auth.example.com/tenant1")
148+
149+
assert_equal("https://auth.example.com/.well-known/oauth-authorization-server/tenant1", urls.first)
150+
end
151+
152+
def test_authorization_server_metadata_urls_treat_trailing_slash_issuer_as_root
153+
urls = Discovery.authorization_server_metadata_urls("https://auth.example.com/")
154+
155+
assert_equal(
156+
["https://auth.example.com/.well-known/oauth-authorization-server", "https://auth.example.com/.well-known/openid-configuration"],
157+
urls,
158+
)
159+
end
160+
124161
def test_canonicalize_url_normalizes_scheme_host_port_and_path
125162
assert_equal(
126163
"https://srv.example.com/mcp",

0 commit comments

Comments
 (0)