Skip to content

fix(service): expose auth challenge on ServiceError::TransportSend - #1462

Merged
DaleSeo merged 1 commit into
modelcontextprotocol:mainfrom
Steeve-Crypto:fix/service-error-auth-challenge
Nov 17, 2026
Merged

DaleSeo merged 1 commit into
modelcontextprotocol:mainfrom
Steeve-Crypto:fix/service-error-auth-challenge

Conversation

@Steeve-Crypto

Copy link
Copy Markdown
Contributor

A 401 on a request made after a successful initialize, such as call_tool, comes back as ServiceError::TransportSend. Its source() returned None, so the WWW-Authenticate header was only reachable by matching the variant and walking the inner error by hand.

Changes:

  • Mark the TransportSend field as #[source] (not #[from], so no new From impl). The chain below it was already intact, so source() now reaches DynamicTransportError and then AuthRequiredError.
  • Add ServiceError::is_authorization_required(), which delegates to DynamicTransportError::is_authorization_required() for TransportSend.
  • Add ServiceError::auth_challenge() -> Option<&str>, gated on transport-streamable-http-client, mirroring ClientInitializeError::auth_challenge.
  • Add an end to end test: initialize succeeds, then call_tool gets a 401 with a challenge. It checks both the header string from auth_challenge() and the source() chain down to AuthRequiredError. The test fails without the #[source] change.

Behavior note: source() on ServiceError::TransportSend now returns Some(...) instead of None. That is the fix, but callers that inspect the error chain will see it. No existing test asserted source().is_none() for this variant.

ServiceError is #[non_exhaustive], so the new methods are additive and no variants change.

Fixes #1458

A 401 on a request after initialize, such as call_tool, came back as
ServiceError::TransportSend with source() returning None, so the
WWW-Authenticate header could only be reached by matching the variant
and walking the inner error by hand.

Mark the TransportSend field as #[source] so the chain reaches the
AuthRequiredError, and add ServiceError::auth_challenge() and
ServiceError::is_authorization_required() to match ClientInitializeError.

Fixes modelcontextprotocol#1458
@Steeve-Crypto
Steeve-Crypto requested a review from a team as a code owner November 16, 2026 16:38
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T16:41:18.966318Z 69f3bca PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the change exposing authorization challenges after initialization.

No open issues 🎉

What changed in this PR

This PR addresses #1458 by exposing authorization challenges on request failures after initialization, bringing ServiceError in line with the existing initialization-error API.

Changes:

  • Preserves the standard error chain through ServiceError::TransportSend.
  • Adds helpers to retrieve authentication challenges and detect authorization failures.
  • Adds regression tests for a post-initialization 401 and a non-transport error.
File Description
crates/​rmcp/​tests/​test_streamable_http_call_auth_challenge.rs Tests challenge access, error-chain traversal, and non-transport behavior.
crates/​rmcp/​src/​service.rs Exposes the transport error source and adds authorization helpers.
crates/​rmcp/​Cargo.toml Registers the new integration test with its required features.

Review effort: Balanced

@DaleSeo
DaleSeo merged commit eb85aaf into modelcontextprotocol:main Nov 17, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ServiceError::TransportSend hides the 401 challenge that ClientInitializeError::auth_challenge() exposes for the handshake

4 participants