One placeholder-less resource template makes the whole server unserviceable
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 72/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- php
- Domaine
- backend-api-design
Piste de recherche
Commencez par Builder::addResourceTemplate(), puis lisez ResourceTemplate.php et ReflectedElementLoader.php pour comprendre où l’URI invalide est actuellement rejetée. Suivez Registry::load() et le chemin de chargement différé pour confirmer le moment où l’échec se produit. C’est terminé lorsqu’un modèle sans placeholder est rejeté lors de l’enregistrement plutôt que lors de la première requête, sans empêcher l’enregistrement d’éléments valides.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Reported by Mariano Damian Ferro Villanueva via email, opening it here on their behalf.
Problem
A #[McpResourceTemplate] whose uriTemplate contains no placeholder takes the whole server down, not just that one template.
#[McpResourceTemplate(
uriTemplate: 'data://tags',
name: 'all_tags',
title: 'All Tags',
description: 'All Tags',
mimeType: 'application/json'
)]
public function tag_all(?int $paged = 1): array
{
// ...
}
The handshake still succeeds, and then every request fails, including ones that have nothing to do with resources:
tools/list -> {"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"Error registering manual resource template 'data://tags': Invalid URI template : \"data://tags\" must be a valid URI template with at least one placeholder."}}
tools/call -> {"jsonrpc":"2.0","id":3,"error":{"code":-32602,"message":"Error registering manual resource template 'data://tags': Invalid URI template : \"data://tags\" must be a valid URI template with at least one placeholder."}}
Reproduced on main against Server::builder() with the Streamable HTTP transport, on both the handshake and the 2026-07-28 lifecycle.
Cause
ResourceTemplate::__construct()requires at least one placeholder and throws (src/Schema/ResourceTemplate.php#L59-L61).ReflectedElementLoaderwraps that into aConfigurationException(ReflectedElementLoader.php#L214-L219), which abortsRegistry::load()before any element is registered.Builder::$lazyLoadingdefaults totrue, so that load runs on the first read during request handling.Registry::load()setsloadedonly on success, so every subsequent request retries and fails the same way.
So one misconfigured element is enough to make a server serve nothing, and the client is told -32602 (Invalid params) for what is a server-side configuration error it cannot do anything about.
The original report saw it as a 500 with Cannot modify header information - headers already sent (output started at /vendor/symfony/http-foundation/Response.php:393), which is how it surfaces once the response is already being written. I could not reproduce that part on main, so treat it as a symptom of the surrounding stack rather than part of this issue.
Secondary issue: inconsistent handling
The same mistake behaves differently depending on the registration path:
ReflectedElementLoaderthrowsConfigurationException, a hard failure taking down the registry.Discoverer::processFile()catches\Throwable, logs it and continues, so an attribute-discovered template with the same mistake is silently dropped.
Suggested fix
Validate the URI template in Builder::addResourceTemplate(), where the developer wrote it, instead of at the first read of the registry. PR follows.
Worth considering separately: a ConfigurationException reaching a client as -32602 is misleading (it is caught by catch (\InvalidArgumentException) in Protocol), and a single failing element aborting the whole registry load is a large blast radius for any other configuration mistake.
Line references are against main.
- Langage dominant
- PHP
- Étoiles
- 1.6k
- Forks
- 173
- Merge moyen
- 2 j 49 min
- PR mergées (30 j)
- 23
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de modelcontextprotocol/php-sdk
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStan OuverteServer
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
modelcontextprotocol/php-sdk#468 · 2 commentaires ·
-
needs confirmation needs maintainer action Server
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
modelcontextprotocol/php-sdk#398 · 1 réaction ·
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
modelcontextprotocol/php-sdk#370 ·
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
modelcontextprotocol/php-sdk#510 · 1 commentaire ·
-
bug
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
modelcontextprotocol/php-sdk#504 ·
Toutes les issues de modelcontextprotocol/php-sdk
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
getgrav/grav-plugin-api#45 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
RSS-Bridge/rss-bridge#5098 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
phingofficial/phing#2025 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
silverstripe/developer-docs#911 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100