Allow a RequestEvent listener to reject a request with a JSON-RPC error
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 65/100
- Type d'issue
- Fonctionnalité
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- php
- Domaine
- backend-api-design
Piste de recherche
Look at the RequestEvent class and its listener handling in the SDK. The change involves modifying handleRequest() in the protocol handling code to check for an error set on the event. Examine how ErrorEvent's setError() works as a model. Test by creating a listener that sets an error and verifying the correct JSON-RPC error is sent.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
A RequestEvent listener can change the request with setRequest(), but it has no way to reject it. ErrorEvent already has setError(). RequestEvent has nothing like it.
We ran into this in Drupal's mcp_server_oauth module. It checks per-tool OAuth scopes in a RequestEvent listener. To refuse a call, the listener throws, and until 0.8 that exception escaped processInput() so Drupal could turn it into a 401 or 403. That was never a documented contract. It stopped working when #412 added a guard around each message. The guard is correct, and we're not asking to remove it. Now every thrown refusal becomes -32603:
{"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"Internal server error."}}
It's also logged as "Uncaught exception while handling message".
Proposal
Let a listener set an Error on RequestEvent. If one is set, handleRequest() sends it and skips the handler:
$event = $this->dispatchEvent(new RequestEvent($request, $session));
if (null !== $error = $event->getError()) {
$this->sendResponse($transport, $error, $session);
return;
}
$request = $event->getRequest();
This covers checks that need the parsed request, such as per-tool policy, where AuthorizationMiddleware can't help because it only sees the token.
Resource reads have a related gap. ReadResourceHandler turns any exception into Error while reading resource. It already rethrows MissingRequiredClientCapabilityException, so a documented exception type that's rethrown the same way would let a resource refuse access with a proper error.
Open question
A JSON-RPC error doesn't give the HTTP transport a status code. For per-tool scopes, the MCP authorization spec expects a 403 with WWW-Authenticate: Bearer error="insufficient_scope". Is that in scope for the SDK, or should hosts check scopes in HTTP middleware before the message reaches Protocol?
- Langage dominant
- PHP
- Étoiles
- 1.6k
- Forks
- 173
- Merge moyen
- 2 j 20 h
- PR mergées (30 j)
- 14
Préparer son environnement
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/php-sdk
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStanOuverteServer
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
modelcontextprotocol/php-sdk#468 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
needs confirmation needs maintainer action Server
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
modelcontextprotocol/php-sdk#398 · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
modelcontextprotocol/php-sdk#370 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
modelcontextprotocol/php-sdk#510 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
modelcontextprotocol/php-sdk#504 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de modelcontextprotocol/php-sdk
Issues similaires
-
Update the one-click "GTM4WP" Delay JS exclusion so that it also works with a custom data layer nameOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
Les mainteneurs répondent en général sous 1 jour
-
[Feature]: Remove Kanboard Discourse forum link from README.md and CONTRIBUTING.md, or moderate itOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
bug Localization
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
solana-foundation/pay-kit#341 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
cline/cline#14560 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour