{"record":{"id":"e5d4448018267bc2","repo":"JuliusBrussee/caveman","slug":"cave-delegate-missing-task","errorCode":"cave_delegate_missing_task","errorMessage":"cave_delegate_missing_task","messagePattern":"cave_delegate_missing_task","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"agents/delegate/caveman-delegate-mcp.mjs","lineNumber":143,"sourceCode":"  },\n};\n\nasync function handle(msg) {\n  const { id, method, params } = msg;\n  if (method === \"initialize\") {\n    return {\n      protocolVersion: params?.protocolVersion || PROTOCOL_FALLBACK,\n      capabilities: { tools: { listChanged: false } },\n      serverInfo: { name: \"caveman-delegate\", version: \"0.1.0\" },\n    };\n  }\n  if (method === \"tools/list\") return { tools: [TOOL] };\n  if (method === \"ping\") return {};\n  if (method === \"tools/call\") {\n    if (params?.name !== TOOL.name) throw new Error(`unknown tool: ${params?.name}`);\n    if (process.env.CAVEMAN_DELEGATE_CHILD === \"1\") throw new Error(\"cave_delegate_depth_exceeded\");\n    const task = params?.arguments?.task;\n    if (!task || typeof task !== \"string\") throw new Error(\"cave_delegate_missing_task\");\n    const r = await runWorker(task, params?.arguments?.cwd);\n    const lines = [r.out || \"(worker produced no output)\"];\n    if (r.usage) {\n      const u = r.usage;\n      let usageLine = `delegate usage (measured, provider-reported): input ${u.input + u.cacheRead + u.cacheWrite} (cacheRead ${u.cacheRead}, cacheWrite ${u.cacheWrite}), output ${u.output}`;\n      if (u.cost > 0) usageLine += `, cost $${u.cost.toFixed(4)}`;\n      lines.push(\"---\", usageLine);\n    }\n    if (r.code !== 0) {\n      lines.push(\"---\", `worker exit ${r.code}: ${r.err.slice(-500)}`);\n      return { content: [{ type: \"text\", text: lines.join(\"\\n\") }], isError: true };\n    }\n    return { content: [{ type: \"text\", text: lines.join(\"\\n\") }] };\n  }\n  if (method?.startsWith(\"notifications/\")) return undefined;\n  throw Object.assign(new Error(`method not found: ${method}`), { code: -32601 });\n}\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/agents/delegate/caveman-delegate-mcp.mjs#L125-L161","documentation":"The caveman-delegate MCP server's `handle` function throws this when a tools/call request for the delegate tool arrives without a valid `task` string in `params.arguments.task`. The delegate's whole purpose is to run a delegated task string in a worker process; without it there is nothing to execute. It is an input-validation guard before spawning the worker.","triggerScenarios":"Calling the delegate tool with `arguments` missing, with `arguments.task` undefined, or with a non-string value (number, object, empty string) via MCP tools/call.","commonSituations":"An MCP client sends a hand-built tools/call JSON and omits the task field; a wrapper script serializes the task under a different key; a model hallucinates the tool schema and passes task as an object; empty task after trimming in upstream code.","solutions":["Include a non-empty string `task` in the tool arguments: {\"name\": TOOL.name, \"arguments\": {\"task\": \"...\"}}","Check the caller's JSON: ensure params.arguments exists and arguments.task is typeof string with length > 0","If a wrapper produces the call, fix the key name so the prompt lands in `task`","Log the incoming params before the call to confirm what the MCP client actually sent"],"exampleFix":"// before\nawait client.callTool({ name: \"delegate\", arguments: { prompt: \"run tests\" } });\n// after\nawait client.callTool({ name: \"delegate\", arguments: { task: \"run tests\" } });","handlingStrategy":"validation","validationCode":"const args = params?.arguments ?? {};\nif (typeof args.task !== \"string\" || args.task.length === 0) {\n  throw new Error(\"delegate tool requires a non-empty string 'task'\");\n}","typeGuard":"const hasTask = (p) => typeof p?.arguments?.task === \"string\" && p.arguments.task.length > 0;","tryCatchPattern":"try {\n  await client.callTool({ name: \"delegate\", arguments: { task } });\n} catch (e) {\n  if (e.message === \"cave_delegate_missing_task\") {\n    console.error(\"task argument missing or not a string — check tool call payload\");\n  } else throw e;\n}","preventionTips":["Always pass task as a string in arguments — never another key name","Validate tool arguments against the schema from tools/list before calling","Add a unit test asserting the tool call payload shape","Log params before tools/call in wrapper code"],"tags":["mcp","input-validation","delegate"],"backgroundTag":"missing-required-argument","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}