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

Unexpected arguments: ${args.slice(1).join(" ")} ${MCP_SERVE

Error message

Unexpected arguments: ${args.slice(1).join(" ")}
${MCP_SERVE_USAGE}

What it means

After a valid MCP serve target is accepted, any additional arguments are rejected: `mcp serve <target>` takes exactly one argument. The error echoes the extra tokens and the usage string.

Source

Thrown at src/cli/mcp-serve.ts:85

}

export async function mcpServeCommand(
  args: string[],
  options: McpServeCommandOptions = {},
): Promise<void> {
  const firstArg = args[0];
  if (!firstArg || firstArg === "--help" || firstArg === "-h" || firstArg === "help") {
    console.log(MCP_SERVE_USAGE);
    return;
  }

  const target = normalizeOmxMcpServeTarget(firstArg);
  if (!target) {
    throw new Error(`Unknown MCP target: ${firstArg}\n${MCP_SERVE_USAGE}`);
  }

  if (args.length > 1) {
    throw new Error(`Unexpected arguments: ${args.slice(1).join(" ")}\n${MCP_SERVE_USAGE}`);
  }

  const env = options.env ?? process.env;
  const loaders = options.loaders ?? MCP_SERVE_LOADERS;
  env[MCP_ENTRYPOINT_MARKER_ENV] = target;
  await loaders[target]();
  if (options.keepProcessAlive === false) return;

  // MCP server modules start their stdio lifecycle as a top-level import side
  // effect. Keep the CLI command from returning after that import so the MCP
  // client can complete initialize and continue using the inherited stdio
  // transport. The server bootstrap owns shutdown when stdin closes, the parent
  // exits, or the transport disconnects.
  await new Promise<never>(() => undefined);
}

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Remove extra arguments; the command takes only the target
  2. Configure the server via environment variables instead of CLI flags (inspect MCP_SERVE_USAGE / docs)
  3. Quote/trim script argv so no stray tokens are appended

Example fix

# before
mycli mcp serve omx --port 3000

# after
MCP_PORT=3000 mycli mcp serve omx
Defensive patterns

Strategy: validation

Validate before calling

if (args.length > 1) {
  console.error('mcp serve takes exactly one target; configure via env vars');
  process.exit(2);
}

Type guard

function isSingleServeArg(args: readonly string[]): boolean {
  return args.length <= 1;
}

Try / catch

try { await mcpServeCommand(args); }
catch (e) { if (/Unexpected arguments/.test(String(e))) { console.error(e.message); process.exit(2); } throw e; }

Prevention

When it happens

Trigger: Running `mcp serve omx extra`, `mcp serve omx --port 3000`, or any invocation where args.length > 1 after the target.

Common situations: Trying to configure ports/host via flags that the command doesn't support (env vars are used instead); trailing tokens from scripts; assuming pass-through args reach the server process.

Related errors


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