Skip to content

Expose client errors to call #345

@howardjohn

Description

@howardjohn

Is your feature request related to a problem? Please describe.
When we connect to a MCP server, we may get a 401 with a www-authenticate header. For example:

$ curl https://mcp.linear.app/mcp -I -X POST
HTTP/2 401
date: Wed, 30 Jul 2025 14:21:02 GMT
content-type: application/json
content-length: 79
www-authenticate: Bearer realm="OAuth", error="invalid_token", error_description="Missing or invalid access token"
server: cloudflare
cf-ray: 96758008190efa52-SJC
alt-svc: h3=":443"; ma=86400

However, its not possible to act on this from an MCP client using the SDK.

We will get a rmcp::transport::worker worker quit with fatal: Client error: received status code 401 Unauthorized, when send initialize request error, but the original error is lost (at

.map_err(WorkerQuitReason::fatal_context("send initialize request"))?
it converts it to a string). This means even with a custom StreamableHttpClient, we cannot return any state in our errors up to our code, so we cannot process the 401/www-authenticate.

The same issue occurs at another part of the code in serve_client_with_ct where we lose context and only get connection closed: initialize response

There may additional be problems that the initialize is in a spawn

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions