mirror of
https://github.com/morluto/rea.git
synced 2026-11-06 06:46:10 +00:00
perf(mcp): add opt-in hot/cold tool discovery (#9046)
Add per-connection discovery that loads canonical named tools on demand while preserving the default full catalog. Bound discovery replies before changing visibility, preserve family exclusions and Evidence workflows, and reset visibility on HTTP reconnect. Verified with focused protocol tests and real Codex CLI artifact investigations; token costs remain task-dependent, so the profile is opt-in.
This commit is contained in:
1 parent
ad518cff65
commit
0beedcd712
22 files changed
+956
-42
No files matched your search
@@ -7,9 +7,21 @@ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { withVerifierCleanup } from "./verifier-cleanup.mjs";
|
||||
import { INLINE_EVIDENCE_MCP_ENVIRONMENT } from "./mcp-verification-environment.mjs";
|
||||
|
||||
// REA registers process-static tool contracts. Bind their parsed definitions to
|
||||
// the SDK's negotiated connection identity, including when a Client reconnects.
|
||||
// Bind parsed definitions to this connection. Hot/cold catalogs may add tools;
|
||||
// refresh a missing name once without throwing away already validated bindings.
|
||||
const toolBindings = new WeakMap();
|
||||
const readDefinitions = (client) =>
|
||||
client.listTools().then(({ tools }) => {
|
||||
const definitions = new Map();
|
||||
for (const tool of tools) {
|
||||
assert.ok(
|
||||
!definitions.has(tool.name),
|
||||
`Duplicate MCP tool: ${tool.name}`,
|
||||
);
|
||||
definitions.set(tool.name, tool);
|
||||
}
|
||||
return definitions;
|
||||
});
|
||||
|
||||
const advertisedTool = async (client, name) => {
|
||||
const connection = client.getServerVersion();
|
||||
@@ -18,23 +30,19 @@ const advertisedTool = async (client, name) => {
|
||||
if (binding?.connection !== connection) {
|
||||
binding = {
|
||||
connection,
|
||||
definitions: client.listTools().then(({ tools }) => {
|
||||
const definitions = new Map();
|
||||
for (const tool of tools) {
|
||||
assert.ok(
|
||||
!definitions.has(tool.name),
|
||||
`Duplicate MCP tool: ${tool.name}`,
|
||||
);
|
||||
definitions.set(tool.name, tool);
|
||||
}
|
||||
return definitions;
|
||||
}),
|
||||
definitions: readDefinitions(client),
|
||||
};
|
||||
toolBindings.set(client, binding);
|
||||
}
|
||||
let definitions;
|
||||
const snapshot = binding.definitions;
|
||||
try {
|
||||
definitions = await binding.definitions;
|
||||
definitions = await snapshot;
|
||||
if (!definitions.has(name)) {
|
||||
if (binding.definitions === snapshot)
|
||||
binding.definitions = readDefinitions(client);
|
||||
definitions = await binding.definitions;
|
||||
}
|
||||
assert.equal(
|
||||
client.getServerVersion(),
|
||||
connection,
|
||||
|
||||
Reference in new issue
Block a user