[Server] McpResourceTemplate throws 500 error when uriTemplate variable is undefined
还没有人认领这个 Issue。
评估
调研方向
从 McpResourceTemplate 处理路径开始,使用类似 data://tags 的 uriTemplate,并传入一个未在模板中表示的 method 参数来重现请求。跟踪请求如何到达 Symfony 响应处理,并确定过早发送 header 的警告在哪里发生。完成的标准是:错误的模板应以明确的验证或配置错误进行处理,而不是返回 500 响应。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- PHP
- 星标
- 1.6k
- 派生
- 173
- 平均合并
- 2 天 49 分钟
- 30 天内合并 PR
- 23
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/php-sdk 的其他 Issue
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStan 未关闭Server
难度 1/5 1 小时以内 新手友好度 78/100
modelcontextprotocol/php-sdk#468 · 2 条评论 ·
-
needs confirmation needs maintainer action Server
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/php-sdk#398 · 1 个 reaction ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/php-sdk#370 ·
-
enhancement
难度 4/5 3-5 天 新手友好度 55/100
modelcontextprotocol/php-sdk#510 · 1 条评论 ·
-
bug
难度 4/5 3-5 天 新手友好度 45/100
modelcontextprotocol/php-sdk#504 ·
查看 modelcontextprotocol/php-sdk 的全部 Issue
相似的 Issue
-
priority: p3
难度 2/5 1-3 小时 新手友好度 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
难度 2/5 1-3 小时 新手友好度 78/100
nextcloud/fulltextsearch#1011 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 78/100
phpstan/phpstan-doctrine#794 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
Automattic/static-site-importer#1767 ·