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

Ouverte
#3,269 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é
3/5
Temps estimé
1-2 jours
Accessibilité débutants
70/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
node.js, typescript
Domaine
backend, performance

Piste de recherche

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.

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

Description

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.

Langage dominant
TypeScript
Étoiles
13.8k
Forks
2.5k
Merge moyen
6 j 23 h
PR mergées (30 j)
2

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

Toutes les issues de modelcontextprotocol/typescript-sdk

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

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