modelcontextprotocol / modelcontextprotocol/php-sdk
[Server] McpResourceTemplate throws 500 error when uriTemplate variable is undefined
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- PHP
- Estrellas
- 1.6k
- Forks
- 173
- Merge medio
- 2 d 49 min
- PR fusionados (30 d)
- 23
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en la ruta de manejo de McpResourceTemplate y reproduce la solicitud usando un uriTemplate como data://tags con un parámetro de método que no está representado en la plantilla. Sigue cómo la solicitud llega al manejo de respuestas de Symfony e identifica dónde se produce la advertencia de encabezado prematuro. El trabajo está terminado cuando la plantilla malformada se maneja con un error claro de validación o configuración en lugar de una respuesta 500.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- php, symfony
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 55/100