{"record":{"id":"3fd45a2f150a248b","repo":"mastra-ai/mastra","slug":"missing-argument-3fd45a","errorCode":"MISSING_ARGUMENT","errorMessage":"MISSING_ARGUMENT: Missing required argument <${name}>","messagePattern":"MISSING_ARGUMENT: Missing required argument <(.+?)>","errorType":"error_code","errorClass":"ApiCliError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/api/input.ts","lineNumber":42,"sourceCode":"  } 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  }\n}\n\nexport function resolvePathParams(\n  descriptor: ApiCommandDescriptor,\n  positionalValues: string[],\n  input?: Record<string, unknown>,\n): Record<string, string> {\n  const params: Record<string, string> = {};\n\n  descriptor.positionals.forEach((name, index) => {\n    const value = positionalValues[index];\n    if (!value) {\n      throw new ApiCliError('MISSING_ARGUMENT', `Missing required argument <${name}>`, { argument: name });\n    }\n    params[name] = value;\n  });\n\n  for (const name of pathParamNames(descriptor.path)) {\n    if (params[name]) continue;\n    const value = input?.[name];\n    if (typeof value !== 'string' || !value) {\n      throw new ApiCliError('MISSING_ARGUMENT', `Missing required argument <${name}>`, { argument: name });\n    }\n    params[name] = value;\n  }\n\n  return params;\n}\n\nexport function stripPathParamsFromInput(\n  input: Record<string, unknown> | undefined,","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/api/input.ts#L24-L60","documentation":"resolvePathParams fills each positional declared by the command descriptor (descriptor.positionals) from the ordered positionalValues list. If the value at a position is missing or empty, it throws MISSING_ARGUMENT naming the expected argument, because the positional is required to build the request URL.","triggerScenarios":"Calling a command like `mastra api agents get <agentId>` with too few positionals — e.g. `mastra api agents get` or `mastra api agents get \"\"` — so positionalValues[index] is undefined/empty for a declared positional.","commonSituations":"Forgetting an ID the command requires; an empty shell variable (`$AGENT_ID` unset); wrapping the argument in an option flag so the CLI doesn't count it as a positional; reordering arguments by mistake.","solutions":["Pass all required positionals in order: `mastra api agents get my-agent-id`","Check the command help output to see the declared positional list","Verify the env variable feeding the positional is non-empty before invoking","Supply path params via the JSON --input object as a fallback (see the next branch, which reads input[name] for path params)"],"exampleFix":"// before\nmastra api agents get\n// after\nmastra api agents get weather-agent","handlingStrategy":"validation","validationCode":"const required = commandDescriptor.positionals;\nif (argv.filter(a => !a.startsWith('-')).length < required.length) {\n  throw new Error(`Missing positionals: ${required.slice(argv.length).join(', ')}`);\n}","typeGuard":"function hasPositionals(args: string[], count: number): args is [string, ...string[]] { return args.length >= count && args.slice(0, count).every(v => v.length > 0); }","tryCatchPattern":"try { await runApiCommand(cmd, args); } catch (e) { if (String(e).includes('MISSING_ARGUMENT')) { console.error('Usage:', e.message, '- see `mastra api <cmd> --help`'); } else throw e; }","preventionTips":["Run `mastra api <cmd> --help` to list required positionals before invoking","Check shell variables feeding positionals are non-empty (`: \"${AGENT_ID:?unset}\"`)","Don't interleave flags where positionals are expected","Pass path params in --input as an alternative supply path"],"tags":["cli","arguments","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}