Yeachan-Heo/oh-my-codex · error · Error

Invalid --input JSON: ${error instanceof Error ? error.messa

Error message

Invalid --input JSON: ${error instanceof Error ? error.message : String(error)}

What it means

parseInputJson wraps JSON.parse of the --input value for the MCP parity CLI. It rejects values that are not JSON objects (arrays, scalars, null are invalid) and re-wraps any parse failure as `Invalid --input JSON: <reason>`.

Source

Thrown at src/cli/mcp-parity.ts:84

    descriptor.title,
    "",
    "Available tools:",
    toolLines,
    "",
    "Examples:",
    `  omx ${descriptor.commandName} ${descriptor.tools[0]?.name ?? "<tool>"} --input '{}' --json`,
  ].join("\n");
}

function parseInputJson(raw: string): Record<string, unknown> {
  try {
    const parsed = JSON.parse(raw);
    if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
      throw new Error("input JSON must decode to an object");
    }
    return parsed as Record<string, unknown>;
  } catch (error) {
    throw new Error(
      `Invalid --input JSON: ${error instanceof Error ? error.message : String(error)}`,
    );
  }
}

export function parseMcpCliArgs(args: string[]): ParsedMcpCliArgs {
  if (args.length === 0 || args[0] === "--help" || args[0] === "-h" || args[0] === "help") {
    return { toolName: null, input: {}, json: false, help: true };
  }

  const [toolName, ...rest] = args;
  let input: Record<string, unknown> = {};
  let json = false;

  for (let i = 0; i < rest.length; i += 1) {
    const token = rest[i];
    if (token === "--json") {
      json = true;

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Pass the JSON single-quoted in shell and use double quotes inside: --input '{"key":"value"}'
  2. Ensure the top-level value is an object {} not an array or scalar
  3. Validate with a linter or `echo '<json>' | jq type` expecting 'object' before invoking
  4. Use a file and command substitution if the payload is large: --input "$(cat input.json)"

Example fix

# before
mycli mcp-tool run --input {"key":"value"}  # shell strips quotes -> invalid JSON

# after
mycli mcp-tool run --input '{"key":"value"}'
Defensive patterns

Strategy: validation

Validate before calling

function parseSafe(raw: string): Record<string, unknown> {
  const v = JSON.parse(raw); // throws SyntaxError on bad JSON
  if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('not an object');
  return v as Record<string, unknown>;
}
const input = parseSafe(payload); // validate before invoking CLI

Type guard

function isJsonObject(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null && !Array.isArray(v);
}

Try / catch

try { await run(tool, input); }
catch (e) { if (/Invalid --input JSON/.test(String(e))) { console.error('Fix JSON quoting/shape'); process.exit(2); } throw e; }

Prevention

When it happens

Trigger: Passing --input '[1,2]' (array), --input '"x"' or --input 'null' (non-object), or malformed JSON like --input '{a:1}' (unquoted keys) or a shell-mangled payload to the mcp parity command.

Common situations: Unquoted shell strings losing or garbling quotes; single vs double quote confusion in bash/zsh; JSON produced by a tool that emits a top-level array; trailing commas; Windows cmd escaping issues.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/dca235d485dc3933. Report an issue: GitHub.