Skip to content

Commit 97a2e09

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion-admission
2 parents 30e21fa + 0beedcd commit 97a2e09

22 files changed

Lines changed: 956 additions & 42 deletions

‎docs/client-configuration.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,33 @@ does not repair a client's naming behavior or infer permission drift from an
102102
unfamiliar prefix. The unavailable fork reported in
103103
[#5512](https://github.com/morluto/rea/issues/5512) has not been reverified.
104104

105+
## Hot/cold catalogs
106+
107+
For a client that supports MCP catalog refresh, set
108+
`REA_MCP_TOOL_CATALOG_PROFILE=hot-cold` in REA's server environment and restart
109+
the connection. REA then advertises a small initial catalog and loads other
110+
named tools through `discover_tools`. Setup preserves this explicit setting.
111+
See the [discovery contract](mcp-contracts.md#hotcold-catalog-discovery) for
112+
pagination, identity and family-scope semantics.
113+
114+
Codex CLI 0.165.0 requires its experimental `mcp_tool_list_changed` feature for
115+
this workflow. Merge these entries into the existing `~/.codex/config.toml`
116+
without replacing other feature or REA settings:
117+
118+
```toml
119+
[features]
120+
mcp_tool_list_changed = true
121+
122+
[mcp_servers.rea.env]
123+
REA_MCP_TOOL_CATALOG_PROFILE = "hot-cold"
124+
```
125+
126+
The server setting alone does not enable client refresh. If a successful
127+
discovery call is followed by a missing tool, check the client's refresh feature
128+
and tool allow/deny lists. Clients without refresh should use the default
129+
`REA_MCP_TOOL_CATALOG_PROFILE=full`; reconnect after changing it. Other clients'
130+
hot/cold behavior has not been verified.
131+
105132
## Fiddler Everywhere alongside REA
106133

107134
Connect Fiddler Everywhere's MCP server separately for HTTP traffic debugging,

‎docs/mcp-contracts.md‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ registrations, reports their command vectors as aligned, stale, missing, or
899899
invalid, and keeps live-server state `unknown` unless the active connection
900900
supplies identity.
901901

902-
`tools/list` returns the complete canonical tool inventory, including tools that
902+
By default, `tools/list` returns the complete canonical tool inventory, including tools that
903903
are currently unavailable. Opening or closing a target or observing a provider
904904
health transition leaves that catalog unchanged and does not emit
905905
`notifications/tools/list_changed`.
@@ -911,7 +911,7 @@ share status facts. `tool_availability.client_requirements` is the baseline for
911911
each group; a group's optional `client_requirements` replaces that baseline for
912912
the group's tools. Expand each group's `names` into one tool entry, carrying its
913913
availability, reason, remediation, default-mode status, modes, and client
914-
requirements. Compare the union of group names with `tools/list` when checking
914+
requirements. With the default full catalog, compare the union of group names with `tools/list` when checking
915915
that a client received the full catalog. An operation absent from all groups is
916916
missing from the complete inventory; it is not an implicit unavailable entry.
917917

@@ -1873,6 +1873,47 @@ check full-profile local-path rules. Compact MCP workflow tests verify canonical
18731873
rejection of invalid inputs before provider work, independent of how much detail
18741874
the selected advertisement retains.
18751875

1876+
### Hot/cold catalog discovery
1877+
1878+
`REA_MCP_TOOL_CATALOG_PROFILE=hot-cold` opts into per-connection loading for
1879+
clients that refresh `tools/list` after `notifications/tools/list_changed`.
1880+
The default, `full`, retains the complete upfront advertisement. Restart the
1881+
server to change profiles. See [client configuration](client-configuration.md#hotcold-catalogs).
1882+
1883+
Hot/cold initially advertises `binary_session`, `open_binary`, `close_binary`,
1884+
`get_evidence_bundle`, `inspect_analysis_view`, and the adapter's `discover_tools`.
1885+
An explicit tool-family scope can remove any of those domain tools.
1886+
`discover_tools` searches canonical names and descriptions using case-insensitive
1887+
words, or accepts exact `names`. It loads the matching page and returns names
1888+
and abbreviated descriptions with their configured input schemas, so the next
1889+
call can use the returned arguments contract. Output schemas remain in
1890+
`tools/list`. Search defaults to three results, allows up to
1891+
20 per page, and returns `total_matches` and `next_offset`. Exact names preserve
1892+
request order and reject unknown or excluded names before loading anything.
1893+
Use fewer keywords when no result matches; search requires every word to match.
1894+
Both reply representations must fit the configured response budget before any
1895+
tools load. An oversized page returns a resource constraint; reduce `limit` or
1896+
request fewer exact names and retry. Input schemas are retained in full within
1897+
the selected input profile.
1898+
1899+
Loaded definitions retain their original names, complete configured schemas,
1900+
annotations, handlers and client approval rules. Loading does not execute an
1901+
analysis, open a target, or initialize the deferred analysis runtime. A batch
1902+
emits one list-change notification; repeating it emits none. Loaded tools remain
1903+
available until the connection ends. There is no generic execution gateway.
1904+
If a loaded tool does not appear in the client, enable client catalog refresh
1905+
or reconnect using `REA_MCP_TOOL_CATALOG_PROFILE=full`.
1906+
1907+
The catalog identity covers the complete in-scope inventory, the discovery
1908+
contract and the hot/cold policy; its count includes `discover_tools`. It differs
1909+
from full advertisement and remains stable as tools load. `rea mcp doctor`
1910+
checks the profile's initial advertisement and identity. The domain inventory in
1911+
`binary_session.tool_availability` continues to describe provider and target
1912+
availability, independently of whether a definition is loaded. Load a listed
1913+
cold tool before calling it. Provider health and target changes do not load,
1914+
unload or remove definitions. The input/output schema profiles and explicit
1915+
family exclusions continue to apply.
1916+
18761917
### Tool family advertising scope
18771918

18781919
Agents pay context for every advertised tool schema, and clients that send

‎docs/tool-design.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ Extend a tool when intent and result contract match; add one for a distinct
88
outcome or materially different authority. Public names and semantics remain
99
provider-neutral, with exact coverage reported per provider.
1010

11-
Keep the catalog complete; report capability/session availability instead of
12-
truncating schemas. Serialized bytes alone do not establish agent usability.
11+
Keep the discoverable inventory complete within the caller's selected scope;
12+
report capability/session availability independently of catalog visibility.
13+
An opt-in dynamic catalog must retain canonical named contracts and provide
14+
discovery and recovery for clients without refresh. Serialized bytes alone do
15+
not establish agent usability.
1316

1417
## Choose the tool shape
1518

‎scripts/lib/artifact-e2e.mjs‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
77
import { withVerifierCleanup } from "./verifier-cleanup.mjs";
88
import { INLINE_EVIDENCE_MCP_ENVIRONMENT } from "./mcp-verification-environment.mjs";
99

10-
// REA registers process-static tool contracts. Bind their parsed definitions to
11-
// the SDK's negotiated connection identity, including when a Client reconnects.
10+
// Bind parsed definitions to this connection. Hot/cold catalogs may add tools;
11+
// refresh a missing name once without throwing away already validated bindings.
1212
const toolBindings = new WeakMap();
13+
const readDefinitions = (client) =>
14+
client.listTools().then(({ tools }) => {
15+
const definitions = new Map();
16+
for (const tool of tools) {
17+
assert.ok(
18+
!definitions.has(tool.name),
19+
`Duplicate MCP tool: ${tool.name}`,
20+
);
21+
definitions.set(tool.name, tool);
22+
}
23+
return definitions;
24+
});
1325

1426
const advertisedTool = async (client, name) => {
1527
const connection = client.getServerVersion();
@@ -18,23 +30,19 @@ const advertisedTool = async (client, name) => {
1830
if (binding?.connection !== connection) {
1931
binding = {
2032
connection,
21-
definitions: client.listTools().then(({ tools }) => {
22-
const definitions = new Map();
23-
for (const tool of tools) {
24-
assert.ok(
25-
!definitions.has(tool.name),
26-
`Duplicate MCP tool: ${tool.name}`,
27-
);
28-
definitions.set(tool.name, tool);
29-
}
30-
return definitions;
31-
}),
33+
definitions: readDefinitions(client),
3234
};
3335
toolBindings.set(client, binding);
3436
}
3537
let definitions;
38+
const snapshot = binding.definitions;
3639
try {
37-
definitions = await binding.definitions;
40+
definitions = await snapshot;
41+
if (!definitions.has(name)) {
42+
if (binding.definitions === snapshot)
43+
binding.definitions = readDefinitions(client);
44+
definitions = await binding.definitions;
45+
}
3846
assert.equal(
3947
client.getServerVersion(),
4048
connection,

‎src/application/DirectAnalysisStatus.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { providerCapabilitySets } from "./binary/BinarySessionStatus.js";
88
import { sqliteDatabaseCapability } from "./sqlite/SqliteDatabaseCapability.js";
99
import { CURRENT_ENTRYPOINT_PATH } from "../process/CurrentEntrypointPath.js";
1010
import { catalogIdentityForToolFamilies } from "../catalogIdentity.js";
11+
import { progressiveCatalogIdentity } from "../catalogDiscovery.js";
1112
import { compactPresentationForMcpInputSchemaProfile } from "../config/mcpInputSchemaProfile.js";
1213
import {
1314
directAnalysisCleanupFailure,
@@ -31,6 +32,15 @@ export const runSessionStatus = async (
3132
session,
3233
async () => {
3334
const status = jsonObjectSchema.parse(await session.status());
35+
const catalog = catalogIdentityForToolFamilies(
36+
compactPresentationForMcpInputSchemaProfile(
37+
config.value.mcpInputSchemaProfile,
38+
),
39+
config.value.mcpOutputSchemaProfile ?? "full",
40+
config.value.mcpToolFamilies === undefined
41+
? undefined
42+
: new Set(config.value.mcpToolFamilies),
43+
);
3444
return {
3545
...status,
3646
capabilities: [
@@ -42,15 +52,10 @@ export const runSessionStatus = async (
4252
server_identity: createServerIdentity({
4353
startedAt: new Date().toISOString(),
4454
commandPath: CURRENT_ENTRYPOINT_PATH,
45-
catalog: catalogIdentityForToolFamilies(
46-
compactPresentationForMcpInputSchemaProfile(
47-
config.value.mcpInputSchemaProfile,
48-
),
49-
config.value.mcpOutputSchemaProfile ?? "full",
50-
config.value.mcpToolFamilies === undefined
51-
? undefined
52-
: new Set(config.value.mcpToolFamilies),
53-
),
55+
catalog:
56+
config.value.mcpToolCatalogProfile === "hot-cold"
57+
? progressiveCatalogIdentity(catalog)
58+
: catalog,
5459
}),
5560
};
5661
},

‎src/application/SetupRegistrationEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const SELECTED_REGISTRATION_SETTINGS = [
7272
"REA_MCP_INPUT_SCHEMA_PROFILE",
7373
"REA_MCP_TOOL_FAMILIES",
7474
"REA_MCP_OUTPUT_SCHEMA_PROFILE",
75+
"REA_MCP_TOOL_CATALOG_PROFILE",
7576
"REA_MCP_MAX_RESPONSE_BYTES",
7677
"REA_MCP_MAX_INPUT_ELEMENTS",
7778
"REA_NATIVE_MATCHING_REPRESENTATION_BYTES",

‎src/catalogDiscovery.ts‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { createHash } from "node:crypto";
2+
import { z } from "zod";
3+
import type { createCatalogIdentity } from "./catalogIdentity.js";
4+
5+
export const HOT_TOOL_NAMES: ReadonlySet<string> = new Set([
6+
"binary_session",
7+
"open_binary",
8+
"close_binary",
9+
"get_evidence_bundle",
10+
"inspect_analysis_view",
11+
]);
12+
13+
// One page activates at most 20 schemas: callers can page a broad search instead
14+
// of inadvertently expanding the entire catalog into their client's context.
15+
const pageSize = z.int().min(1).max(20).default(3);
16+
const inputSchema = z
17+
.strictObject({
18+
query: z
19+
.string()
20+
.trim()
21+
.optional()
22+
.describe(
23+
"Case-insensitive words matched against tool names and descriptions; all words must match. Omit to browse.",
24+
),
25+
names: z
26+
.array(z.string().min(1))
27+
.min(1)
28+
.max(20)
29+
.optional()
30+
.describe("Exact tool names to load instead of searching."),
31+
offset: z.int().min(0).default(0),
32+
limit: pageSize.describe(
33+
"Search page size; does not apply to exact names.",
34+
),
35+
})
36+
.refine(
37+
(input) =>
38+
input.names === undefined ||
39+
(input.query === undefined && input.offset === 0),
40+
{
41+
message: "Use names alone, or query with offset/limit.",
42+
},
43+
);
44+
const outputSchema = z.strictObject({
45+
profile: z.literal("hot-cold"),
46+
inventory_count: z.int().nonnegative(),
47+
loaded_count: z.int().nonnegative(),
48+
total_matches: z.int().nonnegative(),
49+
next_offset: z.int().nonnegative().nullable(),
50+
tools: z.array(
51+
z.strictObject({
52+
name: z.string(),
53+
description: z
54+
.string()
55+
.describe(
56+
"Abbreviated canonical description; read tools/list for the complete contract.",
57+
),
58+
input_schema: z
59+
.record(z.string(), z.unknown())
60+
.describe(
61+
"The configured advertised input schema for calling this named tool.",
62+
),
63+
}),
64+
),
65+
next_step: z.string(),
66+
});
67+
68+
export const DISCOVER_TOOLS = {
69+
name: "discover_tools",
70+
description:
71+
"Find and load REA tools on demand. Search by task keywords (for example javascript, sqlite, strings, imports), or supply exact names. Returned tools become callable with their original names and full schemas after your client refreshes tools/list. Loaded tools remain available for this connection. This only changes catalog visibility; it does not run analysis or grant execution authority. If tools do not appear, enable MCP catalog refresh in your client or use REA_MCP_TOOL_CATALOG_PROFILE=full.",
72+
inputSchema,
73+
outputSchema,
74+
annotations: {
75+
readOnlyHint: true,
76+
idempotentHint: true,
77+
openWorldHint: false,
78+
},
79+
} as const;
80+
81+
export type CatalogIdentity = ReturnType<typeof createCatalogIdentity>;
82+
const digest = (value: unknown): string =>
83+
createHash("sha256").update(JSON.stringify(value)).digest("hex");
84+
85+
/** Identity covers the discoverable inventory and policy, not mutable visibility. */
86+
export const progressiveCatalogIdentity = (
87+
base: CatalogIdentity,
88+
): CatalogIdentity => {
89+
const policy = {
90+
profile: "hot-cold",
91+
hot: [...HOT_TOOL_NAMES],
92+
tool: {
93+
...DISCOVER_TOOLS,
94+
inputSchema: z.toJSONSchema(inputSchema, { io: "input" }),
95+
outputSchema: z.toJSONSchema(outputSchema),
96+
},
97+
};
98+
const tools_sha256 = digest({ base: base.digests.tools_sha256, policy });
99+
return {
100+
counts: { ...base.counts, mcp_tools: base.counts.mcp_tools + 1 },
101+
digests: {
102+
tools_sha256,
103+
prompts_sha256: base.digests.prompts_sha256,
104+
combined_sha256: digest({
105+
base: base.digests.combined_sha256,
106+
tools_sha256,
107+
}),
108+
},
109+
};
110+
};

‎src/config/environment.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from "../domain/analysisResourceLimits.js";
2727
import { mcpInputSchemaProfileSchema } from "./mcpInputSchemaProfile.js";
2828
import { mcpOutputSchemaProfileSchema } from "./mcpOutputSchemaProfile.js";
29+
import { mcpToolCatalogProfileSchema } from "./mcpToolCatalogProfile.js";
2930
import { mcpResponseBudgetSchema } from "./mcpResponseBudget.js";
3031
import { asarMaxHeaderBytesSchema } from "./asarHeaderAdmission.js";
3132
import { bridgeMaxRequestBytesSchema } from "./bridgeMaxRequestBytes.js";
@@ -62,6 +63,7 @@ const environmentSchema = z.object({
6263
REA_MCP_INPUT_SCHEMA_PROFILE: mcpInputSchemaProfileSchema.optional(),
6364
REA_MCP_TOOL_FAMILIES: mcpToolFamiliesSchema.optional(),
6465
REA_MCP_OUTPUT_SCHEMA_PROFILE: mcpOutputSchemaProfileSchema.optional(),
66+
REA_MCP_TOOL_CATALOG_PROFILE: mcpToolCatalogProfileSchema.optional(),
6567
REA_IDA_MCP_CONFIG: z
6668
.string()
6769
.min(1)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { z } from "zod";
2+
import { ConfigurationError } from "../domain/configurationErrors.js";
3+
import { err, ok, type Result } from "../domain/result.js";
4+
5+
/** Full advertisement remains the default for clients without catalog refresh. */
6+
export const mcpToolCatalogProfileSchema = z.enum(["full", "hot-cold"]);
7+
export type McpToolCatalogProfile = z.infer<typeof mcpToolCatalogProfileSchema>;
8+
9+
export const parseMcpToolCatalogProfile = (
10+
value: string | undefined,
11+
): Result<McpToolCatalogProfile | undefined, ConfigurationError> => {
12+
if (value === undefined) return ok(undefined);
13+
const parsed = mcpToolCatalogProfileSchema.safeParse(value);
14+
const constraint =
15+
'REA_MCP_TOOL_CATALOG_PROFILE must be "full" (default) or "hot-cold". Hot/cold requires a client that refreshes tools after notifications/tools/list_changed.';
16+
return parsed.success
17+
? ok(parsed.data)
18+
: err(
19+
new ConfigurationError(constraint, {
20+
settings: [{ setting: "REA_MCP_TOOL_CATALOG_PROFILE", constraint }],
21+
}),
22+
);
23+
};

‎src/config/parseConfig.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ export const parseConfig = (
119119
...(env.REA_MCP_OUTPUT_SCHEMA_PROFILE === undefined
120120
? {}
121121
: { mcpOutputSchemaProfile: env.REA_MCP_OUTPUT_SCHEMA_PROFILE }),
122+
...(env.REA_MCP_TOOL_CATALOG_PROFILE === undefined
123+
? {}
124+
: { mcpToolCatalogProfile: env.REA_MCP_TOOL_CATALOG_PROFILE }),
122125
analysisProvider: env.REA_ANALYSIS_PROVIDER,
123126
...(env.REA_IDA_MCP_CONFIG === undefined
124127
? {}

0 commit comments

Comments
 (0)