Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): keep prompt guidance for natives hidden by native auto

Alfredo Lopez3a18b5819352
diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.md
index 603616338..894b0c38e 100644
--- a/docs/architecture/codex-subscription-transport-contract.md
+++ b/docs/architecture/codex-subscription-transport-contract.md
@@ -745,8 +745,10 @@ integer, default 2048; `0` is rejected at startup). At the default that is the
pdf, xlsx, pptx, chart and dashboard generators. A removed native stays reachable:
`clerum__tool_search` lists natives under the `native` server,
`clerum__tool_describe` returns their schema, and `clerum__tool_call` runs them
-by their real name, so validation and approval apply to that name. The bridge
-never targets itself. When an MCP tool and a native share a name, the native wins.
+by their real name, so the admission checks of a direct call (safety parameter
+checks, guardrails, approval) apply to that name. Neither path validates native
+arguments against the native's own schema (#1017). The bridge never targets
+itself. When an MCP tool and a native share a name, the native wins.
The native decision runs after the MCP decision and only removes natives, so MCP
tools in `tools[]` are the same for both native modes. When `auto` hides a
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index ae1cfe4e2..affae0926 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.501",
+ "version": "0.1.502",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.501",
+ "version": "0.1.502",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 5f434642c..41ab8c29c 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.501",
+ "version": "0.1.502",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/agent/taskExecutor.ts b/mcp-host/src/agent/taskExecutor.ts
index 23f952914..08d32ccb3 100644
--- a/mcp-host/src/agent/taskExecutor.ts
+++ b/mcp-host/src/agent/taskExecutor.ts
@@ -41,7 +41,10 @@ import { DefaultLoopController } from '../core/orchestration/loopConfig'
import { NativeToolPresentationController } from '../core/orchestration/nativeToolPresentationController'
import type { SpilloverResolver } from '../core/orchestration/spilloverResolver'
import { StubSpilloverResolver } from '../core/orchestration/spilloverResolver'
-import { resolveToolPresentation } from '../core/orchestration/toolPresentationPolicy'
+import {
+ resolveToolPresentation,
+ selectDeferredNatives,
+} from '../core/orchestration/toolPresentationPolicy'
import {
buildOutputPreview,
executeSingleTool,
@@ -284,6 +287,8 @@ interface TaskToolRegistry {
registry: ToolRegistry
nativeRegistry: NativeToolRegistry
loopController: LoopController
+ /** Natives hidden from `tools[]` by native `auto`; empty in `direct`. */
+ discoverableNatives: ToolDefinition[]
bridge?: LoopConfig['bridge']
}
@@ -1556,7 +1561,7 @@ export class TaskExecutor {
}
}
- const { registry, loopController, bridge } = await this.buildToolRegistry()
+ const { registry, loopController, bridge, discoverableNatives } = await this.buildToolRegistry()
// T2.2 — when the prompt-cache flag is ON and we have the dependencies
// wired (PromptCache + WorkspaceService), build the tiered
@@ -1565,7 +1570,10 @@ export class TaskExecutor {
// single-string identity built by `buildSystemIdentity`.
const reasoningFactory = new DefaultReasoningFactory(
hookedLlmPort,
- new DefaultPromptBuilder({ nativeToolPresentation: appConfig.nativeToolPresentation }),
+ new DefaultPromptBuilder({
+ nativeToolPresentation: appConfig.nativeToolPresentation,
+ discoverableNatives,
+ }),
metadata,
// F1.4 — wire the send-time context-window-breakdown capture. The sink is
// bound to the captured `conversation` local (not `this.conversation!`) so
@@ -1594,6 +1602,7 @@ export class TaskExecutor {
} else {
const promptBuilder = new DefaultPromptBuilder({
nativeToolPresentation: appConfig.nativeToolPresentation,
+ discoverableNatives,
})
systemPromptFor = tools => promptBuilder.buildSystemPrompt(tools, identity, metadata).content
}
@@ -2286,6 +2295,11 @@ export class TaskExecutor {
mode: appConfig.nativeToolPresentation,
discoveryBytes: appConfig.nativeToolDiscoveryBytes,
})
+ // The natives that controller hides, for the prompt builder's guidance.
+ const deferredNatives = nativeAuto
+ ? selectDeferredNatives(nativeDefinitions, appConfig.nativeToolDiscoveryBytes)
+ : new Set<string>()
+ const discoverableNatives = nativeDefinitions.filter(d => deferredNatives.has(d.name))
// The bridge intercept (executeToolCalls) needs `nativeNames` + the live
// deferrable catalog. It exists exactly when NativeToolRegistry registered
@@ -2315,6 +2329,7 @@ export class TaskExecutor {
registry: compositeRegistry,
nativeRegistry,
loopController: withNativePresentation(innerController),
+ discoverableNatives,
// Native `auto` only: MCP presentation is unchanged (no MCP decision on
// this path) but the bridge serves natives and keeps MCP tools callable.
bridge,
@@ -2347,6 +2362,7 @@ export class TaskExecutor {
registry: compositeRegistry,
nativeRegistry,
loopController: withNativePresentation(loopController),
+ discoverableNatives,
bridge,
}
}
diff --git a/mcp-host/src/core/orchestration/__tests__/nativeToolPresentation.integration.test.ts b/mcp-host/src/core/orchestration/__tests__/nativeToolPresentation.integration.test.ts
index 8f3001e2c..67bb6de10 100644
--- a/mcp-host/src/core/orchestration/__tests__/nativeToolPresentation.integration.test.ts
+++ b/mcp-host/src/core/orchestration/__tests__/nativeToolPresentation.integration.test.ts
@@ -22,7 +22,11 @@ import { logger } from '../../../logger'
import { McpManager } from '../../../mcp/manager'
import type { Task, TaskResponsePayload } from '../../../queue/types'
import { ConversationManager } from '../../conversation/conversation'
-import { NATIVE_TOOL_DISCOVERY_TEXT, TOOL_DISCOVERY_TEXT } from '../../reasoning/promptBuilder'
+import {
+ CAPABILITY_CONTRACT_TEXT,
+ NATIVE_TOOL_DISCOVERY_TEXT,
+ TOOL_DISCOVERY_TEXT,
+} from '../../reasoning/promptBuilder'
import { type ChatMessage, FinishReason, type ToolCall, type ToolDefinition } from '../../types'
import { SimpleEventEmitter } from '../eventEmitter'
import {
@@ -291,6 +295,15 @@ async function runScenario(scenario: Scenario, turns: Turn[]) {
dynamicEnvProvider: () => ({}),
}
const executor = new TaskExecutor(task, deps)
+ // `tool:called` is emitted once per execution, after admission. The call ids
+ // per tool prove exactly-once execution; an artifact on disk cannot (a second
+ // run with the same filename overwrites it).
+ const emit = vi.spyOn(deps.coreEvents, 'emit')
+ const executed = (toolName: string) =>
+ emit.mock.calls
+ .map(([event]) => event)
+ .filter(event => event.type === 'tool:called' && event.data.toolName === toolName)
+ .map(event => event.data.toolCallId)
/**
* Fails the test with the first turn-callback error, or if the task failed.
* Once the task has settled without suspending, every scripted turn must have
@@ -305,7 +318,7 @@ async function runScenario(scenario: Scenario, turns: Turn[]) {
}
await executor.run()
settle()
- return { executor, deps, providerCalls, responses, workspaceService, settle }
+ return { executor, deps, providerCalls, responses, workspaceService, settle, executed }
}
/** Search → describe → bridged call for the pptx generator, then a final answer. */
@@ -354,6 +367,7 @@ function expectPptxDelivered(run: Awaited<ReturnType<typeof runScenario>>, provi
expect(run.executor.executorState).toBe('completed')
expect(run.providerCalls).toHaveLength(providerCalls)
expect(pptxFiles()).toEqual(['bridged-deck.pptx'])
+ expect(run.executed('clerum__generate_pptx')).toEqual(['pptx-call'])
expect(run.responses).toHaveLength(1)
expect(run.responses[0].response).toBe('The deck is attached.')
expect(run.responses[0].attachments).toEqual([
@@ -408,10 +422,12 @@ describe('T1 — native discovery journeys through TaskExecutor.run()', () => {
// Suspended before execution: the provider has not seen any tool result.
expect(run.providerCalls).toHaveLength(1)
expect(run.deps.onApprovalNeeded).toHaveBeenCalledTimes(1)
+ expect(run.executed('shell_exec')).toEqual([])
await run.executor.resumeAfterApproval(false)
run.settle()
expect(run.executor.executorState).toBe('completed')
+ expect(run.executed('shell_exec')).toEqual(['shell-call'])
expect(run.providerCalls).toHaveLength(2)
expect(
run.providerCalls[1].messages.filter(
@@ -537,6 +553,33 @@ describe('T1 — native discovery journeys through TaskExecutor.run()', () => {
expect.objectContaining({ budget: 1, presentedCount: BRIDGE.length }),
])
})
+
+ it('a native hidden by a low budget keeps its prompt guidance without being described (uncached path)', async () => {
+ const capabilities = 'clerum__get_capabilities'
+ const firstTurn = async (native: NativeToolPresentation) => {
+ const run = await runScenario(
+ { provider: 'openai', legacy: false, native, mcp: null, discoveryBytes: 300 },
+ [() => ({ content: 'ok' })]
+ )
+ // Witness: the uncached builder produced this prompt (no cache snapshot).
+ expect(run.workspaceService).toBeUndefined()
+ return {
+ tools: names(run.providerCalls[0].tools),
+ text: systemText(run.providerCalls[0].messages),
+ }
+ }
+ const hidden = await firstTurn('auto')
+ // clerum__get_capabilities (391 B) is over the 300 B budget: off tools[], still callable.
+ expect(hidden.tools).not.toContain(capabilities)
+ expect(hidden.tools).toEqual(expect.arrayContaining(BRIDGE))
+ expect(hidden.text).toContain(CAPABILITY_CONTRACT_TEXT)
+ expect(hidden.text).not.toContain(`**${capabilities}**`)
+ // Witness: listed directly in native direct, with the same guidance.
+ const listed = await firstTurn('direct')
+ expect(listed.tools).toContain(capabilities)
+ expect(listed.text).toContain(CAPABILITY_CONTRACT_TEXT)
+ expect(listed.text).toContain(`**${capabilities}**`)
+ })
})
describe('T2 — independence matrix (I1, I2 with deviation D1)', () => {
@@ -711,11 +754,12 @@ describe('T3 — negative guards with liveness witnesses (through TaskExecutor.r
)
expect(pptxFiles()).toEqual([])
// Witness: the identical call executes once in native auto.
- await runScenario(
+ const bridgedRun = await runScenario(
{ provider: 'codex-subscription', codexMode: 'discovery', native: 'auto', mcp: 2 },
turns(false)
)
expect(pptxFiles()).toEqual(['bridged-deck.pptx'])
+ expect(bridgedRun.executed('clerum__generate_pptx')).toEqual(['pptx-call'])
})
it('native direct: search lists no native entries while MCP entries are found', async () => {
@@ -751,7 +795,7 @@ describe('T3 — negative guards with liveness witnesses (through TaskExecutor.r
})
it('bridge recursion is rejected for every bridge tool while a native target executes', async () => {
- await runScenario(
+ const bridgedRun = await runScenario(
{ provider: 'codex-subscription', codexMode: 'direct', native: 'auto', mcp: 2 },
[
() =>
@@ -771,6 +815,7 @@ describe('T3 — negative guards with liveness witnesses (through TaskExecutor.r
]
)
expect(pptxFiles()).toEqual(['bridged-deck.pptx'])
+ expect(bridgedRun.executed('clerum__generate_pptx')).toEqual(['pptx-call'])
})
it('a bridged native call passes the same parameter validation as a direct one', async () => {
@@ -805,6 +850,7 @@ describe('T3 — negative guards with liveness witnesses (through TaskExecutor.r
expect(run.deps.onApprovalNeeded).not.toHaveBeenCalled()
expect(run.executor.executorState).toBe('completed')
expect(pptxFiles()).toEqual(['bridged-deck.pptx'])
+ expect(run.executed('clerum__generate_pptx')).toEqual(['pptx-call'])
})
it('the catalog never lists bridge tools while it lists the hidden generators', async () => {
@@ -846,7 +892,7 @@ describe('T3 — negative guards with liveness witnesses (through TaskExecutor.r
],
}
let described: Record<string, unknown> = {}
- await runScenario(
+ const bridgedRun = await runScenario(
{ provider: 'codex-subscription', codexMode: 'discovery', native: 'auto', mcp: catalogs },
[
() =>
@@ -872,6 +918,7 @@ describe('T3 — negative guards with liveness witnesses (through TaskExecutor.r
expect(described).toMatchObject({ found: true, server: 'native' })
expect(described.description).not.toBe('Impostor deck builder')
expect(pptxFiles()).toEqual(['bridged-deck.pptx'])
+ expect(bridgedRun.executed('clerum__generate_pptx')).toEqual(['pptx-call'])
// Witness: the MCP-only name reached MCP, and the colliding name never did.
expect(remote.calls.mock.calls).toEqual([['clerum', { name: 'mcp_only', arguments: {} }]])
})
diff --git a/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts b/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts
index 94644724f..e91b536a8 100644
--- a/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts
+++ b/mcp-host/src/core/orchestration/toolUseLoopToolBatch.ts
@@ -101,8 +101,10 @@ function resolveBridgeCall(
// #1003 — native `auto`: a native target is valid. Its scope gate is
// membership in the native registry (deferred natives are not in the MCP
// catalog). The rewrite keeps `call.id` and the normal gate below then
- // validates and approves the REAL native, exactly like a direct call, so
- // the bridge never widens what the model could call directly.
+ // admits the REAL native exactly like a direct call (safety parameter
+ // checks, guardrails, approval; no native schema validation on either
+ // path, #1017), so the bridge never widens what the model could call
+ // directly.
if (bridge.nativeTargets && bridge.nativeNames.has(name)) {
return {
id: call.id,
diff --git a/mcp-host/src/core/reasoning/promptBuilder.ts b/mcp-host/src/core/reasoning/promptBuilder.ts
index f92e48f58..0909078f9 100644
--- a/mcp-host/src/core/reasoning/promptBuilder.ts
+++ b/mcp-host/src/core/reasoning/promptBuilder.ts
@@ -170,17 +170,34 @@ export function toolDiscoveryText(nativeToolPresentation: NativeToolPresentation
*/
export class DefaultPromptBuilder implements PromptBuilder {
private readonly discoveryText: string
+ private readonly discoverableNatives: ReadonlyArray<ToolDefinition>
- constructor(options: { nativeToolPresentation: NativeToolPresentation }) {
+ /**
+ * `discoverableNatives` (#1003): natives that native `auto` keeps out of
+ * `tools[]` and serves through the bridge. They still select capability
+ * guidance (a hidden tool stays callable), but are never described in the
+ * "Available tools" section. Empty in native `direct`.
+ */
+ constructor(options: {
+ nativeToolPresentation: NativeToolPresentation
+ discoverableNatives?: ReadonlyArray<ToolDefinition>
+ }) {
this.discoveryText = toolDiscoveryText(options.nativeToolPresentation)
+ this.discoverableNatives = options.discoverableNatives ?? []
}
buildSystemPrompt(
- tools: ToolDefinition[],
+ presentedTools: ToolDefinition[],
identity?: string,
metadata?: Record<string, unknown>
): ChatMessage {
const sections: string[] = []
+ const presentedNames = new Set(presentedTools.map(t => t.name))
+ // Guidance is chosen from every callable tool; only presented tools are described.
+ const tools = [
+ ...presentedTools,
+ ...this.discoverableNatives.filter(t => !presentedNames.has(t.name)),
+ ]
// 1. Identity / base system prompt
if (identity) {
@@ -193,8 +210,8 @@ export class DefaultPromptBuilder implements PromptBuilder {
}
// 2. Tool capabilities description
- if (tools.length > 0) {
- sections.push(this.buildToolsDescription(tools))
+ if (presentedTools.length > 0) {
+ sections.push(this.buildToolsDescription(presentedTools))
}
// 2a. Capability discovery contract. Always emitted when
@@ -270,7 +287,7 @@ export class DefaultPromptBuilder implements PromptBuilder {
logger.debug(
{
component: 'PromptBuilder',
- toolCount: tools.length,
+ toolCount: presentedTools.length,
promptLength: content.length,
metadataKeys: metaKeys,
},