perf(mcp): reuse input schemas without losing caller guidance (#1162)

This commit is contained in:
Ysopwnable
2026-10-09 11:38:07 +08:00
committed by GitHub
parent 4fb2f3e6ed
commit e1afbc1914
6 changed files with 599 additions and 158 deletions
+22 -3
View File
@@ -103,25 +103,44 @@ function expectKnownAuthorityHints(tools: readonly ToolSchemas[]): void {
function expectRecursivePropertyDescriptions(
schema: unknown,
path: string,
root: unknown = schema,
active: ReadonlySet<string> = new Set(),
): void {
if (!isRecord(schema)) return;
if (typeof schema.$ref === "string" && !active.has(schema.$ref))
expectRecursivePropertyDescriptions(
resolveReference(root, schema.$ref),
`${path}.${schema.$ref}`,
root,
new Set([...active, schema.$ref]),
);
if (isRecord(schema.properties)) {
for (const [property, child] of Object.entries(schema.properties)) {
expect(child, `${path}.${property}`).toMatchObject({
description: expect.any(String),
});
expectRecursivePropertyDescriptions(child, `${path}.${property}`);
expectRecursivePropertyDescriptions(
child,
`${path}.${property}`,
root,
active,
);
}
}
for (const key of ["items", "additionalProperties"])
if (schema[key] !== undefined)
expectRecursivePropertyDescriptions(schema[key], path);
expectRecursivePropertyDescriptions(schema[key], path, root, active);
for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
const children = schema[key];
if (Array.isArray(children))
children.forEach((child: unknown, index: number) =>
expectRecursivePropertyDescriptions(child, `${path}.${key}[${index}]`),
expectRecursivePropertyDescriptions(
child,
`${path}.${key}[${index}]`,
root,
active,
),
);
}
}