fix(mcp): present discover_tools input through the selected profile (#10592)

* test(mcp): check advertised schemas against a portable dialect in every profile

* fix(mcp): re-emit advertised patterns in a portable regex grammar

* fix(mcp): present discover_tools input through the selected profile

The hot-cold catalog registered discover_tools directly with the SDK, so
the default compact input profile still advertised its canonical schema,
including page-size defaults clients apply on their own (#5322). Route
every listed input schema, transport discovery included, through one
server-owned presentation, and pass the selected presentation to the
deferred server, which serves recorded tool schemas but not discovery.

* fix(mcp): validate advertised dialect by selected profile

* fix(mcp): preserve schema widening through references

* fix(mcp): refuse zero-padded repeat bounds and record host-specific path patterns

* fix(mcp): keep references valid when presentation widens their targets

* fix(mcp): relax references into negations and conditionals presentation may remove

* fix(mcp): keep astral literals and dynamic references widening in every mode

* fix(mcp): omit astral literals and relax untracked references when presentation widens

* fix(mcp): read reference pointers by schema position, not segment spelling

* fix(mcp): protect references into collapsing boolean unions and keep referencing branches out of the collapse

* fix(mcp): omit patterns whose classes name astral characters

* fix(mcp): decide union collapse and pointer protection from canonical branches

* docs(mcp): document non-u astral matching and pin BMP agreement across V8 modes

* test(mcp): expect the advertised base64 schema to omit the unbounded pad-bit probe

* fix(mcp): protect references into unevaluated keywords lost evaluation removes

* fix(mcp): emit stack-safe classes with non-ASCII members and protect draft-07 reference siblings

* fix(mcp): protect references into literal siblings of relaxed draft-07 references

* fix(mcp): keep the Evidence union on described borrowed inputs (#10597)

* fix(mcp): keep the Evidence union on described borrowed inputs

borrowEvidenceInput installed its advertised projection on one schema
instance. A call site's .describe() rebuilds the schema from its
definition, so match_native_functions advertised left and right as
unconstrained values in every input profile. Install the projection in
the borrowed parser's constructor so derived schemas keep it, for both
borrowed inputs and borrowed arrays.

* test(mcp): select the borrowed Evidence contract from its family

* docs(mcp): admit baseline growth only for restored contract declarations
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 18:08:12 +08:00
1 parent 57f75bb723
commit babfc87ec0
10 files changed
+173 -52

No files matched your search

+1 -1
View File
@@ -156,7 +156,7 @@ const fixture = async (
);
});
},
options.maximumInputElements,
{ maximumInputElements: options.maximumInputElements },
);
const client = new Client(
{ name: "deferred-fixture-client", version: "1" },
+10 -4
View File
@@ -7,6 +7,7 @@ import type {
} from "@modelcontextprotocol/server";
import type { PromptCompletionSource } from "./promptCompletion.js";
import type { RecordedMcpCatalog } from "../recordedMcpCatalog.js";
import type { CompactInputSchemaPresentation } from "../contracts/compactInputSchema.js";
import type { ToolResultDelivery } from "./ToolResultDelivery.js";
import {
EvidenceMcpServerCore,
@@ -60,20 +61,25 @@ export class DeferredEvidenceMcpServer extends EvidenceMcpServerCore {
private readonly initialize: (
server: DeferredEvidenceMcpServer,
) => Promise<void>,
maximumInputElements?: number,
options: {
readonly maximumInputElements?: number | undefined;
// Recorded tools carry their presented schemas. The selected presentation
// still applies to transport discovery, which is not recorded.
readonly compactPresentation?: CompactInputSchemaPresentation | undefined;
} = {},
) {
super(
catalog.info,
{
capabilities: catalog.capabilities,
instructions: catalog.instructions,
...(maximumInputElements === undefined
...(options.maximumInputElements === undefined
? {}
: { maxToolInputElements: maximumInputElements }),
: { maxToolInputElements: options.maximumInputElements }),
},
undefined,
delivery,
undefined,
options.compactPresentation,
// `main.ts` only defers the exact full advertisement catalog.
"full",
catalog.identity,
+28 -19
View File
@@ -346,11 +346,19 @@ export class EvidenceMcpServerCore extends RequestTrackingMcpServer {
this.progressiveCatalog = catalog;
const { name, ...config } = DISCOVER_TOOLS;
// Transport discovery has no target or analysis lifecycle. Domain tools
// continue through registerTool and their original named handlers.
super.registerTool(name, config, (input, context) => {
context.mcpReq.signal.throwIfAborted();
return catalog.discover(input);
});
// continue through registerTool and their original named handlers. Its
// advertisement still follows the selected input presentation.
super.registerTool(
name,
{
...config,
inputSchema: this.presentInputSchema(config.inputSchema),
},
(input, context) => {
context.mcpReq.signal.throwIfAborted();
return catalog.discover(input);
},
);
}
override sendToolListChanged(): void {
@@ -448,20 +456,7 @@ export class EvidenceMcpServerCore extends RequestTrackingMcpServer {
): RegisteredTool {
if (canReferenceInlineEvidence(config.inputSchema))
this.registerEvidenceReferenceAlternative(name);
const budget = this.compactPresentation?.budgetBytes;
const inputSchema =
budget !== undefined &&
config !== undefined &&
hasAdvertisedInputJsonSchema(config.inputSchema)
? transformAdvertisedInputJsonSchema(
config.inputSchema as Parameters<
typeof transformAdvertisedInputJsonSchema
>[0],
(projected) =>
presentAdvertisedInputSchema(projected, { budgetBytes: budget }),
)
: undefined;
const presentedSchema = inputSchema ?? config.inputSchema;
const presentedSchema = this.presentInputSchema(config.inputSchema);
const registeredConfig =
presentedSchema === undefined
? config
@@ -514,6 +509,20 @@ export class EvidenceMcpServerCore extends RequestTrackingMcpServer {
return registered;
}
/**
* The input schema this server advertises for one registration: the
* selected compact presentation, or the registered schema unchanged. Every
* listed tool, including transport discovery, takes this one path.
*/
private presentInputSchema<Schema>(schema: Schema): Schema {
const budget = this.compactPresentation?.budgetBytes;
if (budget === undefined || !hasAdvertisedInputJsonSchema(schema))
return schema;
return transformAdvertisedInputJsonSchema(schema, (projected) =>
presentAdvertisedInputSchema(projected, { budgetBytes: budget }),
);
}
/** Whether this process advertises one named operation. */
advertisesTool(_name: string): boolean {
return true;