{"record":{"id":"9d668397594786fd","repo":"Yeachan-Heo/oh-my-codex","slug":"unexpected-arguments-args-slice-1-join","errorCode":null,"errorMessage":"Unexpected arguments: ${args.slice(1).join(\" \")}\n${MCP_SERVE_USAGE}","messagePattern":"Unexpected arguments: (.+?)\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/cli/mcp-serve.ts","lineNumber":85,"sourceCode":"}\n\nexport async function mcpServeCommand(\n  args: string[],\n  options: McpServeCommandOptions = {},\n): Promise<void> {\n  const firstArg = args[0];\n  if (!firstArg || firstArg === \"--help\" || firstArg === \"-h\" || firstArg === \"help\") {\n    console.log(MCP_SERVE_USAGE);\n    return;\n  }\n\n  const target = normalizeOmxMcpServeTarget(firstArg);\n  if (!target) {\n    throw new Error(`Unknown MCP target: ${firstArg}\\n${MCP_SERVE_USAGE}`);\n  }\n\n  if (args.length > 1) {\n    throw new Error(`Unexpected arguments: ${args.slice(1).join(\" \")}\\n${MCP_SERVE_USAGE}`);\n  }\n\n  const env = options.env ?? process.env;\n  const loaders = options.loaders ?? MCP_SERVE_LOADERS;\n  env[MCP_ENTRYPOINT_MARKER_ENV] = target;\n  await loaders[target]();\n  if (options.keepProcessAlive === false) return;\n\n  // MCP server modules start their stdio lifecycle as a top-level import side\n  // effect. Keep the CLI command from returning after that import so the MCP\n  // client can complete initialize and continue using the inherited stdio\n  // transport. The server bootstrap owns shutdown when stdin closes, the parent\n  // exits, or the transport disconnects.\n  await new Promise<never>(() => undefined);\n}\n","sourceCodeStart":67,"sourceCodeEnd":101,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/cli/mcp-serve.ts#L67-L101","documentation":"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.","triggerScenarios":"Running `mcp serve omx extra`, `mcp serve omx --port 3000`, or any invocation where args.length > 1 after the target.","commonSituations":"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.","solutions":["Remove extra arguments; the command takes only the target","Configure the server via environment variables instead of CLI flags (inspect MCP_SERVE_USAGE / docs)","Quote/trim script argv so no stray tokens are appended"],"exampleFix":"# before\nmycli mcp serve omx --port 3000\n\n# after\nMCP_PORT=3000 mycli mcp serve omx","handlingStrategy":"validation","validationCode":"if (args.length > 1) {\n  console.error('mcp serve takes exactly one target; configure via env vars');\n  process.exit(2);\n}","typeGuard":"function isSingleServeArg(args: readonly string[]): boolean {\n  return args.length <= 1;\n}","tryCatchPattern":"try { await mcpServeCommand(args); }\ncatch (e) { if (/Unexpected arguments/.test(String(e))) { console.error(e.message); process.exit(2); } throw e; }","preventionTips":["Pass server config through environment variables, not trailing flags","Trim argv arrays built by scripts"],"tags":["cli","mcp","server","unexpected-arguments","usage"],"backgroundTag":"invalid-cli-argument","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}