modelcontextprotocol / modelcontextprotocol/php-sdk
[Server] McpResourceTemplate throws 500 error when uriTemplate variable is undefined
まだ誰も着手していません。
- 主要言語
- 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:
- Define an
McpResourceTemplate. - Use a variable in the resource template that is not defined in the
uriTemplate. - Execute/request the resource.
- 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
McpResourceTemplate の処理経路から開始し、テンプレートに表現されていないメソッドパラメーターを指定した data://tags のような uriTemplate を使ってリクエストを再現します。リクエストが Symfony のレスポンス処理に到達するまでを追跡し、早すぎるヘッダーに関する警告が発生する箇所を特定します。完了の条件は、不正なテンプレートが 500 レスポンスではなく、明確なバリデーションエラーまたは設定エラーとして処理されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php, symfony
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100