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

Abierto
#1,344 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Java
Estrellas
3.8k
Forks
1.1k
Merge medio
1 d 3 h
PR fusionados (30 d)
38

Preparar el entorno

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.

Más de modelcontextprotocol/java-sdk

Todos los issues de modelcontextprotocol/java-sdk

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.