Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): address anti-regression audit findings for native discovery
Alfredo Lopez047ea91a4b6c
diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.mdindex 894b0c38e..2faec3881 100644--- a/docs/architecture/codex-subscription-transport-contract.md+++ b/docs/architecture/codex-subscription-transport-contract.md@@ -718,7 +718,10 @@ the grant; revoke of one key fail-closes only that assignment.`CODEX_TOOL_PRESENTATION=auto|direct|discovery` controls presentation, not access.Direct is the default when the primary or an allowed fallback uses Codex. Itpresents all approved definitions without the search/describe/call discovery bridge,-regardless of the discovery thresholds or legacy dynamic-tools flag.+regardless of the discovery thresholds or legacy dynamic-tools flag. The exception is+`CLERUM_NATIVE_TOOL_PRESENTATION=auto` (see below): it adds the three bridge tools so+that natives hidden by the native budget stay reachable; MCP tools are still presented+directly.Explicitly selecting auto uses discovery above the existing`CLERUM_DYNAMIC_TOOLS_THRESHOLD` (60) or `CODEX_TOOL_DISCOVERY_BYTES`(32768 serialized MCP definition bytes). Thesediff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex affae0926..b8d39b9eb 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.502",+ "version": "0.1.503","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.502",+ "version": "0.1.503","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 41ab8c29c..7af022fab 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.502",+ "version": "0.1.503","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts b/mcp-host/src/core/orchestration/toolUseLoopToolBatch.tsindex e91b536a8..2ccddae38 100644--- a/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts+++ b/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts@@ -58,7 +58,7 @@ function resolveBridgeCall(toolResults: ToolResult[],// Computed ONCE per batch by `executeToolCalls` and passed in, so we don't// re-derive the (potentially 290-entry) deferrable catalog Set on every call.- // `undefined` when the bridge is inactive (flag OFF) — no work to do.+ // `undefined` when no bridge tools are registered — no work to do.deferrableCatalogNames: Set<string> | undefined): ToolCall | 'handled' {const bridge = config.bridge@@ -198,8 +198,8 @@ export async function executeToolCalls(const { loopController, events } = configconst toolResults: ToolResult[] = []// F3.2 — derive the deferrable catalog Set ONCE for the whole batch instead of- // per call (it can hold ~290 names). `undefined` when the bridge is inactive- // (flag OFF) so `resolveBridgeCall` short-circuits with no work.+ // per call (it can hold ~290 names). `undefined` when no bridge tools are+ // registered, so `resolveBridgeCall` short-circuits with no work.const deferrableCatalogNames = config.bridge?.getDeferrableCatalogNames()// Crit #2: the batch shares ONE LLM call's usage — attach it to the first// reportToolComplete actually emitted (NOT strictly i === 0; the validation@@ -213,7 +213,8 @@ export async function executeToolCalls(// Runs at the TOP of the per-call loop, BEFORE `beforeExecution` (:29) and// `beforeTool` (:49), so that validation and approval run against the REAL// target tool, not the opaque bridge envelope. The intercept unwraps the- // bridge call into a SYNTHETIC call against the real MCP tool, preserving+ // bridge call into a SYNTHETIC call against the real target (an MCP tool, or a+ // native when `bridge.nativeTargets`), preserving// `call.id` (LOCKED #9) so the provider pairs the tool_result by// tool_use_id. Direct calls to deferred MCP tools (Critical #9) are also// routed through the same scope gate here. A `'handled'` return means andiff --git a/mcp-host/src/llm/drivers/__tests__/googleGenerative.test.ts b/mcp-host/src/llm/drivers/__tests__/googleGenerative.test.tsindex a6b9f8b86..b820f726f 100644--- a/mcp-host/src/llm/drivers/__tests__/googleGenerative.test.ts+++ b/mcp-host/src/llm/drivers/__tests__/googleGenerative.test.ts@@ -232,6 +232,38 @@ describe('GoogleGenerativeDriver — tool round-trip', () => {'resp:file_read=file content',])})++ it('resolves an id only against the preceding assistant turn', async () => {+ const { client, generateContent } = mockClient({+ candidates: [{ content: { parts: [{ text: 'done' }] }, finishReason: 'STOP' }],+ })+ const driver = new GoogleGenerativeDriver(client, 'gemini-2.5-pro')+ const messages: ChatMessage[] = [+ { role: 'user', content: 'go' },+ {+ role: 'assistant',+ content: '',+ tool_calls: [{ id: 'call_0', name: 'search', arguments: {} }],+ },+ { role: 'tool', name: 'search', content: 'r1', tool_call_id: 'call_0' },+ {+ role: 'assistant',+ content: '',+ tool_calls: [{ id: 'call_1', name: 'file_read', arguments: {} }],+ },+ // Witness: an id of this turn resolves through the map.+ { role: 'tool', content: 'r2', tool_call_id: 'call_1' },+ // `call_0` belongs to the earlier turn, not this one: the message keeps its own name.+ { role: 'tool', name: 'late_result', content: 'r3', tool_call_id: 'call_0' },+ ]+ await driver.completeSingleTurnWithTools(messages, [])++ const responses = generateContent.mock.calls[0][0].contents+ .flatMap((c: { parts: Array<{ functionResponse?: { name: string } }> }) => c.parts)+ .filter((p: { functionResponse?: { name: string } }) => p.functionResponse)+ .map((p: { functionResponse: { name: string } }) => p.functionResponse.name)+ expect(responses).toEqual(['search', 'file_read', 'late_result'])+ })})describe('GoogleGenerativeDriver — finish reasons', () => {