Streamable HTTP client: a 401 or 403 with a JSON-RPC error body and no WWW-Authenticate loses its HTTP status
Les mainteneurs répondent en général sous 3 jours
Une pull request liée a déjà été fusionnée.
- #1341 par @aton-of-data — fusionnée
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 68/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- rust
- Domaine
- authentication, backend
Piste de recherche
Lis crates/rmcp/src/transport/common/reqwest/streamable_http_client.rs, en particulier la branche de réponse non réussie autour des lignes 276–306 et les vérifications antérieures des statuts 401/403. Compare son traitement avec legacy_discover_response et le chemin d’erreur en texte brut. Le travail est terminé lorsqu’une réponse 401 ou 403 contenant un corps d’erreur JSON-RPC préserve le statut HTTP pour les appelants ; exécute les tests pertinents du client HTTP Streamable.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
When a Streamable HTTP server answers a POST with 401 Unauthorized (or 403 Forbidden) without a WWW-Authenticate header and with a JSON-RPC error body, the reqwest client returns Ok(StreamableHttpPostResponse::Json(..)). The caller then gets an ordinary JSON-RPC error, ClientInitializeError::JsonRpcError during initialize or ServiceError::McpError after it, and cannot tell that the server rejected the credentials.
Where
The non-success branch parses the body with parse_json_rpc_error before it looks at the status:
AuthRequired and InsufficientScope come only from the checks above it, which require WWW-Authenticate. The same 401 with a plain-text body becomes UnexpectedServerResponse("HTTP 401 Unauthorized: …"), so the status survives on that path but not on the JSON one.
Reproduce
rmcp 3.5.1 (main has the same code). The server answers initialize with:
HTTP/1.1 401 Unauthorized
Content-Type: application/json
{"jsonrpc":"2.0","id":0,"error":{"code":-32001,"message":"Unauthorized"}}
serve_client over StreamableHttpClientTransport::with_client(reqwest::Client, config) fails with ClientInitializeError::JsonRpcError (code -32001, message "Unauthorized"). Nothing in the error says HTTP 401.
Why it matters
A client that sends a static token through custom_headers wants to tell the user that the token was rejected. An OAuth client wants to start or refresh authorization. Both need the status. The MCP authorization spec asks servers that implement authorization to send WWW-Authenticate with a 401, but a server that only takes a static token is not bound by that and may answer with a JSON-RPC error body instead.
Possible fixes
- Handle 401 and 403 before the JSON-RPC branch, as
legacy_discover_responsealready does ("Keep authentication failures and server errors on their original paths"). For example, returnAuthRequiredorInsufficientScopefor every 401 or 403, with the challenge optional, or returnUnexpectedServerResponse("HTTP 401 …")as the plain-text path does. - Or keep the JSON-RPC error and carry the HTTP status with it.
- Langage dominant
- Rust
- Étoiles
- 4.1k
- Forks
- 680
- Merge moyen
- 3 j 20 h
- PR mergées (30 j)
- 32
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de modelcontextprotocol/rust-sdk
-
auth: refresh_token() requests offline_access that was never granted, so refreshes fail with invalid_scopePeut-être pris @jstar0 l’a pris il y a 20 jours. Ouvertebug P1 ready for work T-security T-transport
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
modelcontextprotocol/rust-sdk#1330 ·
Les mainteneurs répondent en général sous 3 jours
-
Enterprise-managed auth: ID-JAG `resource` claim should be optionalPeut-être pris @gocamille l’a pris aujourd’hui. Ouvertebug P1 ready for work T-security T-transport
modelcontextprotocol/rust-sdk#1404 · 2 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 3 jours
-
Auto discovery timeout rejects a late probe response during legacy initializationPeut-être pris @gocamille l’a pris il y a 1 jour. Ouvertebug P1 ready for work T-service
modelcontextprotocol/rust-sdk#1400 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 3 jours
-
URL mode elicitation requires elicitationId, which the 2026-07-28 schema removedPeut-être pris @gocamille l’a pris il y a 2 jours. Ouvertebug P1 ready for work T-model
modelcontextprotocol/rust-sdk#1399 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 3 jours
-
stdio transport: a request over the maximum line length gets no answerPeut-être pris @gocamille l’a pris il y a 2 jours. Ouvertebug P1 ready for work T-transport
modelcontextprotocol/rust-sdk#1395 · 1 commentaire · 1 personne assignée ·
Les mainteneurs répondent en général sous 3 jours
Toutes les issues de modelcontextprotocol/rust-sdk
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
swc-project/swc-next#1165 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 73/100
Alive24/shea-symphony#574 ·
-
bug tests Windows
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
[ko] Translate /team into KoreanOuvertedocumentation good first issue help wanted
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
dev-five-git/devup-ui#879 ·
Les mainteneurs répondent en général sous 11 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
farion1231/cc-switch#9038 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour