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 as unset on the workflow path
marcoteb392c040c5c88
diff --git a/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.ts b/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.tsindex 6d9cb3cf6..cdb58da18 100644--- a/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.ts@@ -393,6 +393,22 @@ const ACCEPTED: Array<[string, string, Record<string, unknown>]> = [},},],+ [+ 'null for every optional argument of a PDF',+ 'clerum__generate_pdf',+ { filename: 'n.pdf', body: 'x', title: null, images: null, tables: null, palette: null },+ ],+ [+ 'null for an optional chart size',+ 'clerum__generate_chart',+ {+ filename: 'n.png',+ type: 'bar',+ width: null,+ height: null,+ data: { labels: ['a'], datasets: [{ data: [1] }] },+ },+ ],['a numeric PPTX KPI','clerum__generate_pptx',diff --git a/mcp-host/src/workflow/stepRouter.ts b/mcp-host/src/workflow/stepRouter.tsindex 13bfecd3f..60dfb0d84 100644--- a/mcp-host/src/workflow/stepRouter.ts+++ b/mcp-host/src/workflow/stepRouter.ts@@ -12,6 +12,7 @@ import Ajv, { type ValidateFunction } from 'ajv'import { logger } from '../logger'import { VisualInputBudget } from '../visualInput/policy'import { projectInternalToolResult } from './internalToolProjection'+import { withoutUnsetNulls } from './schemaArguments'import {AllowedToolsConfig,InternalToolDefinition,@@ -224,11 +225,14 @@ 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.+ 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)// so the LLM can read the error and retry within the same step.const validator = this.internalToolValidators.get(toolName)- if (validator && !validator(args)) {+ if (validator && !validator(input)) {const errorText = this.ajv.errorsText(validator.errors, { separator: '; ' })const errorResult = {success: false,@@ -237,7 +241,7 @@ export class StepMcpRouter {const record: ToolCallRecord = {serverName: 'clerum',toolName: toolName.replace('clerum__', ''),- args,+ args: input,result: errorResult,durationMs: 0,}@@ -248,7 +252,7 @@ export class StepMcpRouter {}const start = Date.now()const internalResult = projectInternalToolResult(- await internalTool.execute(args, this.outputDir, {+ await internalTool.execute(input, this.outputDir, {signal: options.signal,timeoutMs: options.timeoutMs,readBudget: this.readBudget,@@ -258,7 +262,7 @@ export class StepMcpRouter {const record: ToolCallRecord = {serverName: 'clerum',toolName: toolName.replace('clerum__', ''),- args,+ args: input,result: internalResult,durationMs,}