modelcontextprotocol / modelcontextprotocol/php-sdk

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

Open
#469 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2 Server
Dominant language
PHP
Stars
1.6k
Forks
173
Avg merge
2d 49m
Merged PRs (30d)
23

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the McpResourceTemplate handling path and reproduce the request using a uriTemplate such as data://tags with a method parameter that is not represented in the template. Trace how the request reaches Symfony response handling and identify where the premature header warning occurs. Done means the malformed template is handled with a clear validation or configuration error instead of a 500 response.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.