fix(mcp): remove arbitrary schema byte gate

This commit is contained in:
morluto committed 2026-07-16 20:09:14 +08:00
1 parent f7aa19154d
commit fd08025dcd
9 files changed
+26 -654

No files matched your search

-69
View File
@@ -1,69 +0,0 @@
import { Buffer } from "node:buffer";
import { dirname, join } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { ensureGeneratedFile } from "./lib/generated-file.mjs";
const arguments_ = new Set(process.argv.slice(2));
for (const argument of arguments_)
if (argument !== "--check")
throw new Error(`Unknown MCP schema report option: ${argument}`);
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const cachebuster = `?${String(Date.now())}`;
const { TOOL_CONTRACTS } = await import(
`${pathToFileURL(join(root, "dist/contracts/toolContracts.js")).href}${cachebuster}`
);
const { toolRegistrationOptions } = await import(
`${pathToFileURL(join(root, "dist/server/toolRegistrationOptions.js")).href}${cachebuster}`
);
const bytes = (value) => Buffer.byteLength(JSON.stringify(value), "utf8");
const tools = TOOL_CONTRACTS.map((contract) => {
const registration = toolRegistrationOptions(contract);
const inputSchema = registration.inputSchema["~standard"].jsonSchema.input();
const outputSchema =
registration.outputSchema["~standard"].jsonSchema.output();
const wire = {
name: contract.name,
title: registration.title,
description: registration.description,
inputSchema,
outputSchema,
annotations: registration.annotations,
};
return {
name: contract.name,
bytes: bytes(wire),
input_schema_bytes: bytes(inputSchema),
output_schema_bytes: bytes(outputSchema),
wire,
};
}).sort((left, right) => left.name.localeCompare(right.name));
const maximumToolBytes = 64 * 1024;
const maximumListBytes = 512 * 1024;
const listBytes = bytes({ tools: tools.map(({ wire }) => wire) });
const oversized = tools.filter((tool) => tool.bytes > maximumToolBytes);
if (oversized.length > 0 || listBytes > maximumListBytes)
throw new Error(
`MCP schema budget exceeded: tools/list=${String(listBytes)}, oversized=${oversized.map(({ name, bytes: size }) => `${name}:${String(size)}`).join(",")}`,
);
const report = {
generated_from: "@modelcontextprotocol/server 2.0.0-beta.4 wire registration",
tool_count: tools.length,
tools_list_bytes: listBytes,
budgets: {
tools_list_bytes: maximumListBytes,
per_tool_bytes: maximumToolBytes,
},
tools: tools.map(({ wire: _wire, ...tool }) => tool),
};
await ensureGeneratedFile({
path: join(root, "docs/mcp-schema-report.json"),
source: `${JSON.stringify(report, null, 2)}\n`,
check: arguments_.has("--check"),
generateCommand: "npm run docs:generate",
});
-28
View File
@@ -8,8 +8,6 @@ const README_PATHS = [
"README_ko.md",
"README_ar.md",
];
const familyLabel = (id) => (id === "electron" ? "Electron" : id);
const tableCounts = (content, path, expectedCounts) => {
const lines = content.split(/\r?\n/u);
for (const [index, line] of lines.entries()) {
@@ -50,37 +48,11 @@ export const documentationFactIssues = async (root, catalog) => {
}
}
const inventory = catalog.tools.families
.map(({ id, count }) => `${String(count)} ${familyLabel(id)}`)
.join(", ")
.replace(/, ([^,]+)$/u, ", and $1");
const plusInventory = catalog.tools.families
.map(({ id, count }) => `${String(count)} ${familyLabel(id)}`)
.join(" + ");
const agents = await readFile(join(root, "AGENTS.md"), "utf8");
requireText(issues, "AGENTS.md", agents, inventory);
requireText(
issues,
"AGENTS.md",
agents,
`(${String(catalog.tools.total)} total)`,
);
requireText(
issues,
"AGENTS.md",
agents,
`${String(catalog.tools.total)}-tool target-free MCP server`,
);
requireText(issues, "AGENTS.md", agents, "docs/product-catalog.json");
const templatePath = ".github/pull_request_template.md";
const template = await readFile(join(root, templatePath), "utf8");
requireText(
issues,
templatePath,
template,
`current inventory is ${String(catalog.tools.total)} tools (${plusInventory})`,
);
requireText(issues, templatePath, template, "docs/product-catalog.json");
const english = await readFile(join(root, "README.md"), "utf8");