{"record":{"id":"e380a08d5f6a99c7","repo":"upstash/context7","slug":"existing-mcp-args-do-not-invoke-stdio-package","errorCode":null,"errorMessage":"Existing MCP args do not invoke ${STDIO_PACKAGE}","messagePattern":"Existing MCP args do not invoke (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/setup/toml-editor.ts","lineNumber":194,"sourceCode":"  apiKey: string | undefined\n): Promise<boolean> {\n  let raw: string;\n  try {\n    raw = await readFile(filePath, \"utf-8\");\n  } catch {\n    return false;\n  }\n\n  if (raw.includes('\"\"\"') || raw.includes(\"'''\")) {\n    throw new Error(\"TOML files containing multiline strings are not safely editable\");\n  }\n\n  const range = findTomlServerArgs(raw, serverName);\n  if (!range) return false;\n\n  const args = range.tokens.map((token) => token.value);\n  if (!args.some(isContext7Package)) {\n    throw new Error(`Existing MCP args do not invoke ${STDIO_PACKAGE}`);\n  }\n\n  const apiKeyIndexes = args.flatMap((arg, index) => (arg === \"--api-key\" ? [index] : []));\n  let content: string;\n  if (apiKey && apiKeyIndexes.length === 1 && apiKeyIndexes[0] + 1 < range.tokens.length) {\n    const valueToken = range.tokens[apiKeyIndexes[0] + 1];\n    content = raw.slice(0, valueToken.start) + JSON.stringify(apiKey) + raw.slice(valueToken.end);\n  } else {\n    const patched = withoutApiKey(args);\n    if (apiKey) patched.push(\"--api-key\", apiKey);\n    content = raw.slice(0, range.start) + JSON.stringify(patched) + raw.slice(range.end);\n  }\n\n  if (content !== raw) {\n    await mkdir(dirname(filePath), { recursive: true });\n    await writeFile(filePath, content, \"utf-8\");\n  }\n  return true;","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/setup/toml-editor.ts#L176-L212","documentation":"Thrown by patchTomlStdioApiKey after successfully parsing the server's args array when none of the argument strings references the Context7 stdio package (STDIO_PACKAGE, optionally with an @version suffix, checked by isContext7Package). The editor only rewrites API keys into args arrays that actually launch the Context7 MCP server; patching any other server's args would silently corrupt a foreign configuration.","triggerScenarios":"Calling patchTomlStdioApiKey(filePath, serverName, apiKey) where `[mcp_servers.<serverName>]` exists and has a parseable args array, but no element equals the package name or `package@version` — e.g. args = [\"-y\", \"other/mcp-server\"].","commonSituations":"Reusing a server name that points at a different package, having renamed or swapped the package after initial setup, or vendoring the package via a local path instead of the registry name.","solutions":["Make sure the args array invokes the Context7 package, e.g. args = [\"-y\", \"@context7/mcp\"] (a version suffix like @context7/mcp@1.0.0 is also accepted)","Use the correct serverName — the name passed to patchTomlStdioApiKey must be the one whose args actually run the Context7 stdio server","If you intentionally run a different MCP server, configure its API key manually instead of using this patch path"],"exampleFix":"// before\nargs = [\"-y\", \"@someother/mcp\"]\n// after\nargs = [\"-y\", \"@context7/mcp\"]","handlingStrategy":"validation","validationCode":"const pkg = \"@context7/mcp\"; // STDIO_PACKAGE\nconst argsMatch = raw.match(new RegExp(`\\\\[mcp_servers\\\\.[\"']?${server}[\"']?\\\\][\\\\s\\\\S]*?args\\\\s*=\\\\s*\\\\[([^\\\\]]*)\\\\]`));\nif (!argsMatch || !argsMatch[1].split(\",\").some(a => a.trim().replace(/^[\"']|[\"']$/g, \"\") === pkg || a.includes(pkg + \"@\"))) {\n  throw new Error(`Server '${server}' does not invoke ${pkg}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await patchTomlStdioApiKey(tomlPath, serverName, apiKey);\n} catch (e) {\n  if (e.message.includes(\"do not invoke\")) {\n    console.error(`${serverName} does not run the Context7 package — check serverName or reconfigure the server`);\n  }\n}","preventionTips":["Use distinct, accurate server names per MCP entry","Only call the patch on servers initially created by the CLI setup","Keep the package name (optionally @version) intact when editing args"],"tags":["toml","config","mcp","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}