Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): read a null optional argument the same from chat and a workflow
marcoteb44c7e8ada606
diff --git a/mcp-host/src/workflow/__tests__/internalTools.nullArguments.test.ts b/mcp-host/src/workflow/__tests__/internalTools.nullArguments.test.tsnew file mode 100644index 000000000..34f12c82f--- /dev/null+++ b/mcp-host/src/workflow/__tests__/internalTools.nullArguments.test.ts@@ -0,0 +1,64 @@+/**+ * Many models send null for every optional argument they leave out. Every+ * internal tool reads such a null as unset, from chat (execute called directly)+ * and from a workflow step (StepMcpRouter), so a call means the same on both+ * paths. The step's record keeps what the model sent.+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import * as fs from 'fs'+import * as os from 'os'+import * as path from 'path'+import { WorkflowTriggerTool } from '../../core/tools/workflowTriggerTool'+import { INTERNAL_TOOLS } from '../internalTools'+import { workflowRouter } from './support/workflowRouter'++const tool = (name: string) => INTERNAL_TOOLS.find(t => t.name === `clerum__${name}`)!++let dir: string+beforeEach(() => {+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'clerum-nulls-'))+})+afterEach(() => {+ vi.restoreAllMocks()+ fs.rmSync(dir, { recursive: true, force: true })+})++describe('a null optional argument', () => {+ it('reaches trigger_workflow from chat as unset, as it does from a step', async () => {+ const execute = vi+ .spyOn(WorkflowTriggerTool.prototype, 'execute')+ .mockResolvedValue({ content: 'started', is_error: false, duration_ms: 0 })+ const sent = {+ namespace: 'team',+ name: 'weekly-report',+ timeoutSeconds: null,+ targetUserId: null,+ }++ await tool('trigger_workflow').execute({ ...sent }, dir)+ await workflowRouter(dir).callTool('clerum__trigger_workflow', { ...sent })++ expect(execute).toHaveBeenCalledTimes(2)+ for (const [args] of execute.mock.calls) {+ expect(args).toEqual({ namespace: 'team', name: 'weekly-report' })+ }+ })++ it('is recorded by a workflow step as the model sent it', async () => {+ const sent = { filename: 'n.pdf', body: 'x', title: null, palette: null }+ const { result, record } = await workflowRouter(dir).callTool('clerum__generate_pdf', {+ ...sent,+ })+ expect(result.isError).toBe(false)+ expect(record.args).toEqual(sent)+ })++ it('is recorded as sent when the arguments fail validation', async () => {+ const sent = { filename: 42, body: 'x', title: null }+ const { result, record } = await workflowRouter(dir).callTool('clerum__generate_pdf', {+ ...sent,+ })+ expect(result.isError).toBe(true)+ expect(record.args).toEqual(sent)+ })+})diff --git a/mcp-host/src/workflow/internalTools.ts b/mcp-host/src/workflow/internalTools.tsindex f74e9f6f9..41f01352b 100644--- a/mcp-host/src/workflow/internalTools.ts+++ b/mcp-host/src/workflow/internalTools.ts@@ -1792,6 +1792,22 @@ function prepared(tool: InternalToolDefinition): InternalToolDefinition {}}+/**+ * A tool that reads a null sent for an optional argument as unset, as the+ * generators do, so a call means the same from chat and from a workflow step.+ */+function nullsUnset(tool: InternalToolDefinition): InternalToolDefinition {+ return {+ ...tool,+ execute: (args, outputDir, options) =>+ tool.execute(+ withoutUnsetNulls(tool.parameters, args ?? {}) as Record<string, unknown>,+ outputDir,+ options+ ),+ }+}+/** All internal tools available to workflow steps. */export const INTERNAL_TOOLS: InternalToolDefinition[] = [...[@@ -1803,10 +1819,7 @@ export const INTERNAL_TOOLS: InternalToolDefinition[] = [generateChart,generateDashboardTool,].map(prepared),- listWorkflows,- readWorkflow,- triggerWorkflow,- ...CONTEXT_FILES_TOOLS,+ ...[listWorkflows, readWorkflow, triggerWorkflow, ...CONTEXT_FILES_TOOLS].map(nullsUnset),]/** Prefix used for all internal tools. */diff --git a/mcp-host/src/workflow/stepRouter.ts b/mcp-host/src/workflow/stepRouter.tsindex 60dfb0d84..24bd71452 100644--- a/mcp-host/src/workflow/stepRouter.ts+++ b/mcp-host/src/workflow/stepRouter.ts@@ -225,8 +225,9 @@ export class StepMcpRouter {// Check internal tools firstconst internalTool = this.internalToolMap.get(toolName)if (internalTool) {- // A null sent for an optional argument counts as unset, as it does on- // the chat path: many models send null for every argument they leave out.+ // A null sent for an optional argument counts as unset, as the tool+ // itself reads it on the chat path, here before validation so it passes.+ // The record keeps what the model sent.const input = withoutUnsetNulls(internalTool.parameters, args) as Record<string, unknown>// Validate args against the tool's JSON Schema before dispatch.// Failures come back as recoverable tool-error results (not thrown)@@ -241,7 +242,7 @@ export class StepMcpRouter {const record: ToolCallRecord = {serverName: 'clerum',toolName: toolName.replace('clerum__', ''),- args: input,+ args,result: errorResult,durationMs: 0,}@@ -262,7 +263,7 @@ export class StepMcpRouter {const record: ToolCallRecord = {serverName: 'clerum',toolName: toolName.replace('clerum__', ''),- args: input,+ args,result: internalResult,durationMs,}