{"record":{"id":"09de108e83883216","repo":"Yeachan-Heo/oh-my-codex","slug":"unknown-mcp-target-firstarg-mcp-serve-usage","errorCode":null,"errorMessage":"Unknown MCP target: ${firstArg}\n${MCP_SERVE_USAGE}","messagePattern":"Unknown MCP target: (.+?)\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/cli/mcp-serve.ts","lineNumber":81,"sourceCode":"  if (typeof rawTarget !== \"string\") return null;\n  const normalized = rawTarget.trim().toLowerCase();\n  if (!normalized) return null;\n  return MCP_SERVE_TARGET_ALIASES[normalized] ?? null;\n}\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);","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/cli/mcp-serve.ts#L63-L99","documentation":"mcp-serve routes to an MCP server target by normalizing the first argument; only a fixed set of targets (keys of MCP_SERVE_LOADERS after normalization) are valid. An unrecognized first argument throws `Unknown MCP target: <arg>` together with the serve usage text.","triggerScenarios":"Running `mcp serve <target>` where target is not one of the supported normalized targets — e.g. 'omx', 'everything', etc. typos or targets that don't exist in this build.","commonSituations":"Target renamed or added between versions; copy-pasting a target name from docs for a different distribution; assuming a generic 'start'/'all' target exists.","solutions":["Check MCP_SERVE_USAGE in the error output for the enumerated valid targets","Fix the target spelling to exactly match a listed target","Compare against your installed version's supported targets (they may differ from upstream docs)"],"exampleFix":"# before\nmycli mcp serve allmcp\n\n# after\nmycli mcp serve omx","handlingStrategy":"validation","validationCode":"const VALID_TARGETS = new Set(['omx']); // mirror MCP_SERVE_LOADERS keys\nif (!VALID_TARGETS.has(normalizeTarget(firstArg))) {\n  console.error(`Valid targets: ${[...VALID_TARGETS].join(', ')}`);\n  process.exit(2);\n}","typeGuard":"function isServeTarget(v: string, loaders: Record<string, unknown>): boolean {\n  return Object.prototype.hasOwnProperty.call(loaders, normalizeOmxMcpServeTarget(v) ?? '');\n}","tryCatchPattern":"try { await mcpServeCommand(args); }\ncatch (e) { if (/Unknown MCP target/.test(String(e))) { console.error(e.message); process.exit(2); } throw e; }","preventionTips":["Print usage on empty args to discover valid targets","Version-pin the CLI in MCP client configs"],"tags":["cli","mcp","server","usage","argument-validation"],"backgroundTag":"unknown-cli-target","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}