ruby-sdk/docs
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Koichi ITO 5081cc5626 Surface unreachable Protected Resource Metadata instead of falling back to legacy discovery
## Motivation and Context

`Flow#locate_authorization_server` treated every failure to fetch Protected Resource Metadata as "the server publishes none"
and took the legacy 2025-03-26 path, where the MCP server's origin becomes the authorization base URL.
A request that never reached the server, or a `5xx` or `429`, says nothing about what the server publishes,
so a transient failure moved the flow to a different authorization server, discarded client information
and tokens bound to the real one on the way, and surfaced as an unrelated error, such as a failed registration at the origin,
rather than as the fetch failure itself. The comment claimed both reference SDKs behave that way, which is not so:
outside browsers the TypeScript SDK propagates network errors from discovery, and the Python SDK propagates them
and refuses the legacy path after a `5xx` or `429` from any candidate.

Discovery now keeps trying candidate URLs until one serves a JSON object and classifies the outcome once they are exhausted.
Like the Python SDK, it remembers a `5xx` or `429` from any candidate before deciding on the legacy path;
moving on to the next candidate after a network error is what the loop already did. `MetadataNotPublishedError`
(a `4xx` other than `429`, or a body that is not a JSON object) is the only failure that selects the legacy path;
`MetadataUnreachableError` (a network error, or a `5xx` or `429`, from any candidate) is raised instead.
Both subclass `AuthorizationError`, so callers rescuing that class keep working, and `MCP::Client::HTTP` still falls back from
a failed refresh to the full flow, which repeats discovery and raises the same way unless the server has recovered.
A body over the response cap is refused outright with a plain `AuthorizationError`, as it already was on the modern path.
The message lists every candidate's failure, with the URL stripped of userinfo, query and fragment and cut to a fixed length,
but otherwise spelled as requested, and with transport and parser messages bounded, as token endpoint diagnostics already are.
The default legacy endpoints for an origin whose own metadata document is absent are unchanged.

## How Has This Been Tested?

New tests in `test/mcp/client/oauth/flow_test.rb` and `test/mcp/client/oauth/discovery_test.rb`. Against the library
before this change, discovery in the scenarios these tests set up took the legacy path instead of raising.

## Breaking Changes

When no Protected Resource Metadata candidate serves a JSON object, a request that failed to reach the server,
or returned a `5xx` or `429`, now raises instead of attempting the legacy 2025-03-26 discovery at the MCP server's origin,
and a Protected Resource Metadata body over the response cap is refused instead of triggering that fallback.
2026-09-19 00:18:09 +09:00
..
_client Surface unreachable Protected Resource Metadata instead of falling back to legacy discovery 2026-09-19 00:18:09 +09:00
_extensions [Doc] Align the Docs Page Names With the MCP Specification 2026-08-22 18:07:38 +09:00
_includes [Doc] Replace the theme attribution in the nav footer 2026-08-24 16:45:55 +09:00
_preview Add a rake docs:preview task serving the docs site locally 2026-08-25 12:36:54 +09:00
_sass Move the Documentation From README.md to the Documentation Site 2026-08-21 13:24:04 +09:00
_server [Doc] State the Listen Stream Delivery Semantics 2026-09-13 17:10:12 +09:00
assets Move the Documentation From README.md to the Documentation Site 2026-08-21 13:24:04 +09:00
latest Add API documentation with GitHub Pages deployment 2025-11-21 12:21:38 -06:00
_config.yml Move the Documentation From README.md to the Documentation Site 2026-08-21 13:24:04 +09:00
CNAME [Doc] Add CNAME file to preserve custom domain across deployments 2026-03-30 13:27:58 +09:00
examples.md Move the Documentation From README.md to the Documentation Site 2026-08-21 13:24:04 +09:00
favicon.svg Move the Documentation From README.md to the Documentation Site 2026-08-21 13:24:04 +09:00
Gemfile Add a rake docs:preview task serving the docs site locally 2026-08-25 12:36:54 +09:00
index.md [Doc] Align the Docs Page Names With the MCP Specification 2026-08-22 18:07:38 +09:00
installation.md [Doc] Explain when the HTTP client needs event_stream_parser 2026-09-06 03:22:32 +09:00
protocol-versions.md [Doc] Align the Docs Page Names With the MCP Specification 2026-08-22 18:07:38 +09:00