Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Allow a RequestEvent listener to reject a request with a JSON-RPC error

オープン
#513 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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?

主要言語
PHP
スター
1.6k
フォーク
173
平均マージ
2日 20時間
マージ済み PR(30日)
14

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/php-sdk のほかの issue

modelcontextprotocol/php-sdk の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。