perf(mcp)!: compact repeated session discovery facts (#1988)
Group repeated session tool availability and provider capability facts, preserve complete named contracts and ordered limitations, and remove duplicate catalog descriptors. Update consumers and migration guidance. Validated by all 31 CI jobs, focused source checks, and actual Claude Code/Linux Hopper/native Windows Ghidra small-target workflows on the current integration tree. Refs #723. BREAKING CHANGE: binary_session no longer includes server_identity.catalog.tools; tool_availability and provider capabilities use grouped facts documented in docs/mcp-contracts.md. Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
@@ -5,9 +5,14 @@ import type {
|
||||
} from "./OptionalObservationProviders.js";
|
||||
|
||||
import {
|
||||
providerCapability,
|
||||
expandProviderCapabilities,
|
||||
providerCapabilitySet,
|
||||
toolAvailabilityInventory,
|
||||
TOOL_ANNOTATION_NAMES,
|
||||
TOOL_EFFECT_NAMES,
|
||||
type ClientFeatureAvailability,
|
||||
type ProviderCapability,
|
||||
type ToolAvailabilityInventory,
|
||||
type ToolAvailability,
|
||||
type ToolAvailabilityMode,
|
||||
type ToolUnavailabilityReason,
|
||||
@@ -26,7 +31,9 @@ const statusSchema = z.object({
|
||||
open: z.boolean(),
|
||||
kind: z.enum(["executable", "database", "archive", "artifact"]).optional(),
|
||||
format: z.string().optional(),
|
||||
capabilities: z.array(providerCapability),
|
||||
capabilities: z
|
||||
.array(providerCapabilitySet)
|
||||
.transform(expandProviderCapabilities),
|
||||
});
|
||||
|
||||
type ToolAvailabilityReason = "available" | ToolUnavailabilityReason;
|
||||
@@ -214,6 +221,60 @@ export const buildCapabilityInventory = (
|
||||
}).sort((left, right) => compareUnicodeCodePoints(left.name, right.name));
|
||||
};
|
||||
|
||||
type ClientRequirements = ToolAvailability["client_requirements"];
|
||||
type MutableAvailabilityGroup = Omit<
|
||||
ToolAvailabilityInventory["groups"][number],
|
||||
"names"
|
||||
> & { names: string[] };
|
||||
|
||||
const EMPTY_CLIENT_REQUIREMENTS: ClientRequirements = {
|
||||
required: [],
|
||||
optional: [],
|
||||
missing_required: [],
|
||||
missing_optional: [],
|
||||
};
|
||||
|
||||
/** Compact repeated metadata while retaining every operation's current availability inline. */
|
||||
export const compactToolAvailability = (
|
||||
availability: readonly ToolAvailability[],
|
||||
): ToolAvailabilityInventory => {
|
||||
const clientRequirements =
|
||||
availability[0]?.client_requirements ?? EMPTY_CLIENT_REQUIREMENTS;
|
||||
const groups = new Map<string, MutableAvailabilityGroup>();
|
||||
|
||||
for (const entry of availability) {
|
||||
const effects = TOOL_EFFECT_NAMES.filter((name) => entry.effects[name]);
|
||||
const annotations = TOOL_ANNOTATION_NAMES.filter(
|
||||
(name) => entry.annotations[name],
|
||||
);
|
||||
const groupFacts = {
|
||||
surface: entry.surface,
|
||||
effects,
|
||||
annotations,
|
||||
available: entry.available,
|
||||
reason: entry.reason,
|
||||
remediation: entry.remediation,
|
||||
...(entry.default_mode_available === undefined
|
||||
? {}
|
||||
: { default_mode_available: entry.default_mode_available }),
|
||||
...(entry.modes === undefined ? {} : { modes: [...entry.modes] }),
|
||||
...(JSON.stringify(entry.client_requirements) ===
|
||||
JSON.stringify(clientRequirements)
|
||||
? {}
|
||||
: { client_requirements: entry.client_requirements }),
|
||||
};
|
||||
const key = JSON.stringify(groupFacts);
|
||||
const existing = groups.get(key);
|
||||
if (existing) existing.names.push(entry.name);
|
||||
else groups.set(key, { ...groupFacts, names: [entry.name] });
|
||||
}
|
||||
|
||||
return toolAvailabilityInventory.parse({
|
||||
client_requirements: clientRequirements,
|
||||
groups: [...groups.values()],
|
||||
});
|
||||
};
|
||||
|
||||
const availabilityFor = (context: AvailabilityContext): Availability => {
|
||||
// These built-in workflows accept a caller-selected endpoint; they do not load the optional passive provider.
|
||||
if (
|
||||
@@ -626,14 +687,15 @@ const navigationContextAvailability = (
|
||||
};
|
||||
if (availableMode !== undefined)
|
||||
return { ...facts, reason: "available", remediation: null };
|
||||
const missingOperations = [
|
||||
...new Set(modes.flatMap((mode) => mode.missing_operations)),
|
||||
];
|
||||
return {
|
||||
...facts,
|
||||
reason: failure?.reason ?? "provider_missing",
|
||||
remediation:
|
||||
specificFailureRemediation ??
|
||||
`Configure a provider for one of: ${modes
|
||||
.flatMap((mode) => mode.missing_operations)
|
||||
.join(", ")}.`,
|
||||
`Configure a provider for one of: ${missingOperations.join(", ")}.`,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user