modelcontextprotocol / modelcontextprotocol/php-sdk

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

Abierto
#469 2 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug P2 Server
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:

  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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.