{"record":{"id":"aca4d4c1d0247852","repo":"mastra-ai/mastra","slug":"missing-input","errorCode":"MISSING_INPUT","errorMessage":"MISSING_INPUT: Command requires a single inline JSON input argument","messagePattern":"MISSING_INPUT: Command requires a single inline JSON input argument","errorType":"error_code","errorClass":"ApiCliError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/api/input.ts","lineNumber":11,"sourceCode":"import { ApiCliError } from './errors.js';\nimport type { ApiCommandDescriptor } from './types.js';\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\nexport function parseInput(descriptor: ApiCommandDescriptor, input?: string): Record<string, unknown> | undefined {\n  if (!descriptor.acceptsInput) return undefined;\n\n  if (!input) {\n    if (descriptor.inputRequired) {\n      throw new ApiCliError('MISSING_INPUT', 'Command requires a single inline JSON input argument', {\n        command: `mastra api ${descriptor.name}`,\n      });\n    }\n    return undefined;\n  }\n\n  try {\n    const parsed = JSON.parse(input);\n    if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n      throw new ApiCliError('INVALID_JSON', 'Input JSON must be an object');\n    }\n    return parsed as Record<string, unknown>;\n  } catch (error) {\n    if (error instanceof ApiCliError) throw error;\n    throw new ApiCliError('INVALID_JSON', 'Input must be valid JSON', {\n      message: error instanceof Error ? error.message : String(error),\n    });\n  }","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/api/input.ts#L1-L29","documentation":"parseInput resolves the inline JSON input for an API command descriptor. If the descriptor accepts input and declares inputRequired but the CLI invocation supplies no input string, it throws ApiCliError('MISSING_INPUT') naming the command. This ensures commands that must receive a payload (e.g. execute/run endpoints) cannot be invoked without one.","triggerScenarios":"Calling `mastra api <command>` for a descriptor with acceptsInput: true and inputRequired: true (e.g. tool execute, workflow run) without providing the single inline JSON argument.","commonSituations":"Forgetting the JSON payload entirely (`mastra api tool-execute`); passing an empty string from a shell variable; expecting the command to prompt or use defaults when it requires an explicit JSON object.","solutions":["Pass a single inline JSON object as the input argument, e.g. `mastra api tool-execute '{\"toolInput\": ...}'`.","Check `mastra api <command> --help` for the expected input shape documented by the descriptor.","If scripting, guard against empty variables: `[ -n \"$JSON\" ] || exit 1` before invoking.","If the command does not need input, use a different subcommand — you may have picked an execute-style command that always requires a payload."],"exampleFix":"// before\nmastra api tool-execute\n// Error: Command requires a single inline JSON input argument\n// after\nmastra api tool-execute '{\"data\": {\"prompt\": \"hello\"}}'","handlingStrategy":"validation","validationCode":"function requireJsonInput(cmd: string, input?: string): Record<string, unknown> {\n  if (!input) throw new Error(`mastra api ${cmd} requires an inline JSON argument`);\n  const parsed = JSON.parse(input);\n  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n    throw new Error('Input must be a JSON object');\n  }\n  return parsed as Record<string, unknown>;\n}","typeGuard":"function isJsonObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  const input = parseInput(descriptor, rawInput);\n} catch (e) {\n  if (e instanceof ApiCliError && e.code === 'MISSING_INPUT') {\n    console.error(`Provide JSON input: mastra ${e.details.command} '{...}'`);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always quote the JSON argument in shell so spaces and braces survive parsing.","Check --help to confirm whether the command requires input before invoking.","In scripts, assert the JSON payload variable is non-empty before calling the CLI.","Parse and validate the JSON with JSON.parse/isJsonObject before passing it through."],"tags":["cli","input-validation","json"],"backgroundTag":"missing-required-input","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}