modelcontextprotocol / modelcontextprotocol/php-sdk
[Server] McpResourceTemplate throws 500 error when uriTemplate variable is undefined
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- PHP
- Sterne
- 1.6k
- Forks
- 173
- Ø Merge
- 2 T. 49 Min.
- Gemergte PRs (30 T.)
- 23
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne beim McpResourceTemplate-Verarbeitungspfad und reproduziere die Anfrage mit einem uriTemplate wie data://tags und einem Methodenparameter, der im Template nicht dargestellt wird. Verfolge, wie die Anfrage die Symfony-Response-Verarbeitung erreicht, und identifiziere, wo die Warnung wegen vorzeitiger Header auftritt. Als erledigt gilt die Aufgabe, wenn das fehlerhafte Template mit einem eindeutigen Validierungs- oder Konfigurationsfehler statt mit einer 500-Antwort behandelt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- php, symfony
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100