DefaultJsonSchemaValidator: caching by $id alone can validate tool input against another tool's schema
Les mainteneurs répondent en général sous 1 jour
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
- java, json
- Domaine
- backend-api-design, security
Piste de recherche
Read generateCacheKey() in mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson2/DefaultJsonSchemaValidator.java and its Jackson 3 counterpart. First inspect how each validator builds and uses its cache key, then reproduce the issue with two schemas sharing $id but having different properties or required fields. Done means both modules distinguish different schema documents and validation behaves correctly for each; the issue does not name test files.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
DefaultJsonSchemaValidator uses the optional JSON Schema $id field as the sole cache key when present. Unlike the hashCode() collision case (#1328), two different schema documents that share the same $id URI will share one compiled Schema instance. Tool B's tools/call arguments may then be validated against Tool A's schema.
Affected code
mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson2/DefaultJsonSchemaValidator.java—generateCacheKey()mcp-json-jackson3/src/main/java/io/modelcontextprotocol/json/schema/jackson3/DefaultJsonSchemaValidator.java—generateCacheKey()
When $id is present, the cache key is String.valueOf(schema.get("$id")) with no hash of the schema body.
Steps to reproduce
- Register two tools on an MCP server (or unit-test the validator directly) with identical
$idbut differentproperties/requiredininputSchema. - Call
validate(toolB.inputSchema(), argumentsValidForBButInvalidForA). - Observe validation outcome depends on which schema was compiled and cached first.
Expected behavior
Cache keys must uniquely identify the full schema document (content-based hash, canonical JSON, or composite key $id + content hash). Different documents must never share a compiled schema even if $id matches.
Actual behavior
First registered/compiled schema wins for that $id; later tools with the same $id may get wrong validation.
Impact
Incorrect accept/reject of tool arguments; security-relevant when validation is used as a gate before handler execution.
Related
- #1328 —
hashCode()fallback cache key collision (orthogonal but same component)
Environment
- Modules:
mcp-json-jackson2,mcp-json-jackson3 - Logic present on current
main/ 2.2.x line
- Langage dominant
- Java
- Étoiles
- 3.8k
- Forks
- 1.1k
- Merge moyen
- 1 j 3 h
- PR mergées (30 j)
- 38
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire 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/java-sdk
-
Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON stringPeut-être pris @starryeye l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
modelcontextprotocol/java-sdk#1352 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was calledOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
modelcontextprotocol/java-sdk#1346 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
modelcontextprotocol/java-sdk#1345 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Tool result _meta is lost when the server automatically adds text content for structured outputOuvertearea/server legacy P3
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
modelcontextprotocol/java-sdk#1330 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Client request handlers that complete empty send no JSON-RPC responsePeut-être pris @1fanwang l’a pris il y a 83 jours. Ouvertearea/client bug P2
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
modelcontextprotocol/java-sdk#1124 · 6 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de modelcontextprotocol/java-sdk
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
crash
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
-
account bug course exam iris lecture
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour