The server's Node shims load the bundled Ajv build even when a custom jsonSchemaValidator is passed

Abierto
#3,269 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
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript

Línea de trabajo

Start at the server package’s Node shims and the Server construction path that reads jsonSchemaValidator; the issue does not name specific source files or tests. Check how the default validator is loaded when a custom validator is supplied, then run the relevant server tests and the reproduction from the issue. Done means the Ajv chunk stays unloaded with a custom validator and loads when the default validator is needed.

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

Descripción

v1 v2

Package: @modelcontextprotocol/server 2.4.0
Runtime: Node.js 24.22.1

Summary

@modelcontextprotocol/server requires @modelcontextprotocol/server/_shims at load time, and the Node shim requires ajvProvider-*.cjs (297 KB, Ajv and ajv-formats bundled) to export DefaultJsonSchemaValidator. The chunk is loaded on require('@modelcontextprotocol/server'), before any Server exists, and stays loaded when every server is constructed with its own jsonSchemaValidator. Loading it alone costs about 1.2 MB of live heap after a full GC, which matters for servers that start often (serverless, CLIs, many small processes).

Reproduction

// node --expose-gc repro.cjs
const { Server } = require('@modelcontextprotocol/server');
new Server(
  { name: 'repro', version: '1.0.0' },
  { jsonSchemaValidator: { getValidator: () => (value) => ({ valid: true, data: value, errorMessage: undefined }) } },
);
console.log(Object.keys(require.cache).filter((path) => /ajvProvider/.test(path)));

Expected

No Ajv chunk loaded: the default validator is never used.

Actual

[ '…/@modelcontextprotocol/server/dist/ajvProvider-DPYcD0gV.cjs' ]

Suggestion

Load the default validator the first time a server that has no jsonSchemaValidator needs one (a lazy getter in the shim, or constructing it in Server on first use), so the Ajv build is only loaded by servers that use it.

Lenguaje dominante
TypeScript
Estrellas
13.8k
Forks
2.5k
Merge medio
6 d 23 h
PR fusionados (30 d)
2

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/typescript-sdk

Todos los issues de modelcontextprotocol/typescript-sdk

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.