DefaultJsonSchemaValidator: schema cache grows without bound (no TTL or size limit)

Ouverte
#1,344 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
java
Domaine
backend, performance

Piste de recherche

Read DefaultJsonSchemaValidator.java in both the Jackson 2 and Jackson 3 modules, then inspect the existing cache tests and clearCache() behavior. Compare bounded cache policies such as a size limit or TTL and check how each behaves with repeated unique schemas. Done means cache growth is bounded while schema validation continues to work; the issue does not identify specific test files.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Summary

DefaultJsonSchemaValidator keeps compiled NetworkNT Schema instances in a ConcurrentHashMap forever. There is an explicit TODO to add eviction; nothing purges entries on tool/schema updates or long-running servers.

Affected code

  • mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson2/DefaultJsonSchemaValidator.java
  • mcp-json-jackson3/src/main/java/io/modelcontextprotocol/json/schema/jackson3/DefaultJsonSchemaValidator.java
// TODO: Implement a strategy to purge the cache (TTL, size limit, etc.)
private final ConcurrentHashMap<String, Schema> schemaCache;

clearCache() exists for tests but is not wired into server lifecycle or dynamic tool registration.

Steps to reproduce

  1. Run a server that repeatedly addTool / updates tools with distinct inputSchema / outputSchema maps (or stress-test the validator in a loop with unique schemas).
  2. Monitor heap or call getCacheSize() on a test instance.
  3. Observe cache size monotonically increases; entries are never removed.

Expected behavior

Bounded memory for schema compilation cache, for example:

  • max entries + LRU, and/or
  • TTL, and/or
  • invalidation when tools/schemas are removed or replaced

Actual behavior

Every distinct cache key retains a compiled Schema for the JVM lifetime.

Impact

Long-lived MCP servers with dynamic tool catalogs or many unique schemas may accumulate unbounded native/heap pressure over days or weeks.

Related

  • #1328 — incorrect cache keys (correctness); this issue is resource / lifecycle
  • Dynamic tool APIs: McpAsyncServer#addTool, etc.

Suggested direction

Content-addressed keys (fixing $id/hash issues) plus a bounded cache policy documented if needed.

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

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/java-sdk

Toutes les issues de modelcontextprotocol/java-sdk

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.