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

Offen
#3,269 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
70/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
node.js, typescript
Bereich
backend, performance

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
TypeScript
Sterne
13.8k
Forks
2.5k
Ø Merge
6 T. 23 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus modelcontextprotocol/typescript-sdk

Alle Issues in modelcontextprotocol/typescript-sdk

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.