{"record":{"id":"8f3e492ac2ded9f4","repo":"upstash/context7","slug":"existing-mcp-server-has-no-safely-editable-args-ar","errorCode":null,"errorMessage":"Existing MCP server has no safely editable args array","messagePattern":"Existing MCP server has no safely editable args array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/setup/toml-editor.ts","lineNumber":143,"sourceCode":"  const headerRe = new RegExp(\n    `^[\\\\uFEFF\\\\t ]*\\\\[[\\\\t ]*${tableKey}[\\\\t ]*\\\\.[\\\\t ]*${serverKey}[\\\\t ]*\\\\][\\\\t ]*(?:#.*)?\\\\r?$`,\n    \"m\"\n  );\n  const header = headerRe.exec(raw);\n  if (!header) return null;\n\n  const bodyStart = raw.indexOf(\"\\n\", header.index + header[0].length) + 1;\n  const effectiveBodyStart = bodyStart === 0 ? raw.length : bodyStart;\n  const nextHeaderRe = /^[\\t ]*\\[[^\\r\\n]+\\][\\t ]*(?:#.*)?\\r?$/gm;\n  nextHeaderRe.lastIndex = effectiveBodyStart;\n  const nextHeader = nextHeaderRe.exec(raw);\n  const bodyEnd = nextHeader?.index ?? raw.length;\n\n  const body = raw.slice(effectiveBodyStart, bodyEnd);\n  const argsRe = /^[\\t ]*(?:args|\"args\"|'args')[\\t ]*=[\\t ]*/gm;\n  const args = argsRe.exec(body);\n  if (!args) {\n    throw new Error(\"Existing MCP server has no safely editable args array\");\n  }\n\n  const start = effectiveBodyStart + args.index + args[0].length;\n  const parsed = parseTomlStringArray(raw, start);\n  return { start, end: parsed.end, tokens: parsed.tokens };\n}\n\nfunction withoutApiKey(args: string[]): string[] {\n  const result: string[] = [];\n  for (let index = 0; index < args.length; index++) {\n    if (args[index] === \"--api-key\") {\n      index++;\n      continue;\n    }\n    result.push(args[index]);\n  }\n  return result;\n}","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/setup/toml-editor.ts#L125-L161","documentation":"Thrown by findTomlServerArgs when the header `[mcp_servers.<name>]` was found, but no line inside that table's body matches the strict `args = ` pattern the editor supports. The regex requires the key literally named `args` (optionally quoted), so the editor cannot locate a safe splice point for the args array.","triggerScenarios":"Calling patchTomlStdioApiKey on a server table that defines the command inline without args (e.g. `[mcp_servers.context7] command = \"npx\" url = \"...\"`), or where the array key is named differently (`arguments =`, `argv =`), or where the args assignment sits under a different table header in the same body range.","commonSituations":"Configs written for a different tool that uses another key name, servers configured with a URL/SSE transport instead of a stdio command, or users renaming `args` while hand-editing.","solutions":["Add an `args = [\"...\"]` line to the `[mcp_servers.<name>]` table (use the package name and any flags the server needs)","Verify the key is exactly `args` (or \"args\"/'args') and not a variant like `arguments` or `argv`","Ensure the args line is inside the same `[mcp_servers.<name>]` table, before the next `[...]` header","If this server is not a stdio Context7 server, it should not be patched by this entry point — configure it separately"],"exampleFix":"// before\n[mcp_servers.context7]\ncommand = \"npx\"\n// after\n[mcp_servers.context7]\ncommand = \"npx\"\nargs = [\"-y\", \"@context7/mcp\"]","handlingStrategy":"validation","validationCode":"const hasTable = /^[\\t ]*\\[mcp_servers\\.[\"']?name[\"']?\\]/m.test(raw);\nconst hasArgs = /^[\\t ]*(args|[\"']args[\"'])[\\t ]*=/m.test(raw);\nif (hasTable && !hasArgs) throw new Error(\"Server table exists but has no args = [...] line\");","typeGuard":null,"tryCatchPattern":"try {\n  await patchTomlStdioApiKey(tomlPath, serverName, apiKey);\n} catch (e) {\n  if (e.message.includes(\"no safely editable args array\")) {\n    console.error(`Add an args = [\"...\"] entry to [mcp_servers.${serverName}] or set it up via the CLI`);\n  }\n}","preventionTips":["Define every stdio MCP server with a command + args pair","Keep the key spelled exactly `args`","Keep server definitions inside their own [mcp_servers.<name>] table"],"tags":["toml","config","mcp","missing-key"],"backgroundTag":"missing-required-config-field","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"}