modelcontextprotocol / modelcontextprotocol/php-sdk

[Server] McpResourceTemplate throws 500 error when uriTemplate variable is undefined

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

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

bug P2 Server
主要言語
PHP
スター
1.6k
フォーク
173
平均マージ
2日 49分
マージ済み PR(30日)
23

説明

Describe the bug

When defining an McpResourceTemplate with a uriTemplate that does not define the variable used by the resource template, the application throws a 500 Internal Server Error.

The error appears to be related to Symfony's response handling:

Warning: Cannot modify header information - headers already sent by (output started at /vendor/symfony/http-foundation/Response.php:393) (500 Internal Server Error)

To Reproduce

Steps to reproduce the behavior:

  1. Define an McpResourceTemplate.
  2. Use a variable in the resource template that is not defined in the uriTemplate.
  3. Execute/request the resource.
  4. The application returns a 500 Internal Server Error.
Example
  #[McpResourceTemplate(
        uriTemplate: 'data://tags',
        name: 'all_tags',
        title: 'All Tags ',
        description: 'All Tags',
        mimeType: 'application/json'
    )]
    public function tag_all( ?int $paged = 1 ) : array|Error {

        //.....

    }

Expected behavior

The application should handle an undefined or missing uriTemplate variable gracefully, ideally by returning a clear validation or configuration error rather than triggering a 500 Internal Server Error caused by headers being sent prematurely.

Logs

Warning: Cannot modify header information - headers already sent by (output started at /vendor/symfony/http-foundation/Response.php:393) (500 Internal Server Error)

Additional context

I encountered this while working with McpResourceTemplate.

I was unable to report the issue through GitHub's usual bug-reporting flow, so I am reporting it here directly.

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

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

はじめの一歩

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

調査の方向性

McpResourceTemplate の処理経路から開始し、テンプレートに表現されていないメソッドパラメーターを指定した data://tags のような uriTemplate を使ってリクエストを再現します。リクエストが Symfony のレスポンス処理に到達するまでを追跡し、早すぎるヘッダーに関する警告が発生する箇所を特定します。完了の条件は、不正なテンプレートが 500 レスポンスではなく、明確なバリデーションエラーまたは設定エラーとして処理されることです。

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

評価

技術スタック
php, symfony
領域
api, backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
55/100

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

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