{"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":"exception","errorClass":"Error","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/edc9eeb77bbfc553e08a122ca783293fdb477daf/packages/cli/src/setup/toml-editor.ts#L125-L161","documentation":"The tool located the named MCP server's table in the TOML file but found no 'args = ...' key (plain, quoted, or single-quoted) inside that table body. It refuses to edit because there is no args array to patch — the server entry is malformed for automated editing.","triggerScenarios":"A [mcp.context7] (or similar) server table that defines only command/env but omits args, so the API-key patch cannot find where to insert.","commonSituations":"Minimal hand-written server entries missing args; args defined in a different table or after another header so it falls outside the server's body; renamed key (arguments instead of args).","solutions":["Add an args = [...] array to the server's TOML table, including the package invocation","Ensure args appears inside the correct [server] table before the next header","If you don't want automated patching, run the setup with a mode that doesn't edit this server"],"exampleFix":"// before\n[context7]\ncommand = \"npx\"\n\n// after\n[context7]\ncommand = \"npx\"\nargs = [\"-y\", \"@upstash/context7-mcp\"]","handlingStrategy":"validation","validationCode":"const serverBody = raw.slice(raw.indexOf(`[${serverName}]`));\nif (!/(^|\\\\n)\\\\s*(args|\"args\"|'args')\\\\s*=/.test(serverBody)) throw new Error('server table lacks args key');","typeGuard":"function serverHasEditableArgs(raw: string, serverName: string): boolean {\n  const i = raw.indexOf(`[${serverName}]`);\n  if (i === -1) return false;\n  const body = raw.slice(i).split(/\\\\n\\\\s*\\\\[/).slice(0, 1)[0];\n  return /(args|\"args\"|'args')\\\\s*=\\\\s*\\\\[/.test(body);\n}","tryCatchPattern":"catch (e) { if (/no safely editable args array/.test(e.message)) { /* add args = [...] to the server table */ } throw e; }","preventionTips":["Always define command + args in MCP server tables","Keep args inside the correct table before the next header"],"tags":["toml","mcp","missing-key","config-structure"],"backgroundTag":"missing-config-key","analyzedSha":"edc9eeb77bbfc553e08a122ca783293fdb477daf","analyzedAt":"2026-08-28T10:18:41.476Z","contentChangedAt":"2026-08-28T10:18:41.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}