Repository navigation
Description
Discovery.secure_url? (and so ProtectedResourceMetadata, the Authenticator challenge, IntrospectionVerifier and JwtVerifier) accepts http://localhost as loopback but refuses http://<name>.localhost. RFC 6761 §6.3 reserves every name under localhost. for loopback, and browsers treat *.localhost as a secure context.
This blocks a common development setup: a multi-tenant server that serves one MCP resource per subdomain (http://acme.localhost:3000/mcp) cannot build its Protected Resource Metadata or its 401 challenge in development and test.
Reproduction (mcp 1.9.0, Ruby 4.0)
# frozen_string_literal: true
# Minimal reproduction: the MCP Ruby SDK treats `localhost` as loopback but not
# `<sub>.localhost`, although RFC 6761 §6.3 reserves every name under `localhost`
# for loopback. A multi-tenant server developed on `http://<tenant>.localhost` cannot
# build its Protected Resource Metadata or its 401 challenge.
#
# Run: ruby repro.rb
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "mcp", "1.9.0"
gem "base64" # mcp 1.9.0 requires it without declaring it (separate issue)
end
require "mcp"
def try(label)
yield
puts "OK #{label}"
rescue ArgumentError => e
puts "RAISES #{label}: #{e.message}"
end
discovery = MCP::Client::OAuth::Discovery
%w[http://localhost/mcp http://127.0.0.1/mcp http://acme.localhost/mcp http://acme.localhost:3000/mcp].each do |url|
puts "secure_url?(#{url}) => #{discovery.secure_url?(url)}"
end
try("PRM for http://localhost:3000/mcp") do
MCP::Server::OAuth::ProtectedResourceMetadata.new(
resource: "http://localhost:3000/mcp", authorization_servers: ["http://localhost:3000"]
)
end
try("PRM for http://acme.localhost:3000/mcp") do
MCP::Server::OAuth::ProtectedResourceMetadata.new(
resource: "http://acme.localhost:3000/mcp", authorization_servers: ["http://acme.localhost:3000"]
)
endOutput:
secure_url?(http://localhost/mcp) => true
secure_url?(http://127.0.0.1/mcp) => true
secure_url?(http://acme.localhost/mcp) => false
secure_url?(http://acme.localhost:3000/mcp) => false
OK PRM for http://localhost:3000/mcp
RAISES PRM for http://acme.localhost:3000/mcp: resource must use https (http is allowed only on loopback): "http://acme.localhost:3000/mcp"
Expected
loopback_host? (in lib/mcp/client/oauth/discovery.rb) returns true for a host that ends in .localhost, as it does for localhost, so http://acme.localhost:3000/mcp is accepted like http://localhost:3000/mcp.
Possible fix
return true if normalized == "localhost" || normalized.end_with?(".localhost")If resolving *.localhost to loopback is not guaranteed on every platform, an opt-in (for example a configuration flag) would also unblock this setup.
Side note
On Ruby 3.4+, require "mcp" raises LoadError: cannot load such file -- base64: lib/mcp/client/oauth/{flow,pkce,jwt_client_assertion}.rb require base64, which is no longer a default gem, and the gemspec doesn't declare it. The reproduction adds gem "base64" for that reason. Happy to open a separate issue if you prefer.
Activity
Stop requiring `base64` in the OAuth client
koic commentedon Nov 13, 2026
Thanks for the report and the reproduction.
One possible approach is to accept
http://<name>.localhostfor theresourceandauthorization_serversfields ofProtectedResourceMetadata. The server only publishes and compares these two values, so the metadata and the 401 challenge forhttp://acme.localhost:3000/mcpcould then be built.secure_url?itself would not change. For a URL the SDK connects to over plain HTTP, RFC 6761 only says resolvers SHOULD answer.localhostnames with a loopback address, and the Secure Contexts specification (Section 5.2) notes that resolvers often send them to the network; a browser can trust*.localhostbecause it pins the name to loopback itself, while the SDK hands the name to the system resolver. So these would stay limited tolocalhostand loopback addresses:jwks_uriofJWTVerifierandintrospection_endpointofIntrospectionVerifierMCP::Client::HTTPcontacts withoauth:A server reached as
acme.localhostwould also need that name in the transport'sallowed_hosts:.Would that be enough for your setup, or does it depend on one of the parts that stay strict?
In the meantime,
https://acme.localhost:3000/mcpwith a local certificate passes the current checks. Thebase64side note is fixed in 1.10.0.tmaier commentedon Nov 13, 2026
Thanks, yes, that would be enough for us. We use the SDK only as the resource server:
ProtectedResourceMetadataand theAuthenticatorchallenge forhttp://<tenant>.localhost:<port>/mcp, with the issuer on the same host. Our token verifier is DB-backed (opaque Doorkeeper tokens, AS and RS in one process), so it never fetches a JWKS or introspection URL, and we don't useMCP::Client::HTTPwithoauth:. Keepingsecure_url?strict for those makes sense: they open real connections, and.localhostisn't guaranteed to stay local outside a browser. We already pass<tenant>.localhostinallowed_hosts:.Accept names under `localhost` for the URLs Protected Resource Metada…