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

未关闭
#3,269 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
13.8k
派生
2.5k
平均合并
6 天 23 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/typescript-sdk 的其他 Issue

查看 modelcontextprotocol/typescript-sdk 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。