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

未关闭
#469 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
php, symfony
领域
api, backend

调研方向

从 McpResourceTemplate 处理路径开始,使用类似 data://tags 的 uriTemplate,并传入一个未在模板中表示的 method 参数来重现请求。跟踪请求如何到达 Symfony 响应处理,并确定过早发送 header 的警告在哪里发生。完成的标准是:错误的模板应以明确的验证或配置错误进行处理,而不是返回 500 响应。

由索引模型根据 Issue 内容生成。

描述

bug P2 Server

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.

主要语言
PHP
星标
1.6k
派生
173
平均合并
2 天 49 分钟
30 天内合并 PR
23

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/php-sdk 的其他 Issue

查看 modelcontextprotocol/php-sdk 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。