modelcontextprotocol / modelcontextprotocol/php-sdk
[Server] McpResourceTemplate throws 500 error when uriTemplate variable is undefined
Nessuno ha ancora preso questa issue.
- Lingua principale
- PHP
- Stelle
- 1.6k
- Fork
- 173
- Merge medio
- 2g 49m
- PR unite (30g)
- 23
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Parti dal percorso di gestione di McpResourceTemplate e riproduci la richiesta usando un uriTemplate come data://tags con un parametro del metodo che non è rappresentato nel template. Segui il percorso della richiesta fino alla gestione delle risposte di Symfony e identifica dove si verifica l’avviso relativo all’header prematuro. Il lavoro è completato quando il template malformato viene gestito con un errore chiaro di validazione o configurazione invece di una risposta 500.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- php, symfony
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 55/100