{"record":{"id":"8b839d8488bf071f","repo":"upstash/context7","slug":"unterminated-toml-array-in-mcp-args","errorCode":null,"errorMessage":"Unterminated TOML array in MCP args","messagePattern":"Unterminated TOML array in MCP args","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/setup/toml-editor.ts","lineNumber":115,"sourceCode":"    }\n    if (source.slice(index, index + 3) === quote.repeat(3)) {\n      throw new Error(\"Multiline strings are not supported in MCP args\");\n    }\n\n    const token =\n      quote === '\"' ? parseTomlBasicString(source, index) : parseTomlLiteralString(source, index);\n    tokens.push(token);\n    index = skipTomlArrayTrivia(source, token.end);\n\n    if (source[index] === \",\") {\n      index++;\n      continue;\n    }\n    if (source[index] !== \"]\") {\n      throw new Error(\"Expected a comma or closing bracket in MCP args\");\n    }\n  }\n  throw new Error(\"Unterminated TOML array in MCP args\");\n}\n\nfunction findTomlServerArgs(\n  raw: string,\n  serverName: string\n): { start: number; end: number; tokens: TomlStringToken[] } | null {\n  const escapedName = serverName.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n  const tableKey = `(?:mcp_servers|\"mcp_servers\"|'mcp_servers')`;\n  const serverKey = `(?:${escapedName}|\"${escapedName}\"|'${escapedName}')`;\n  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;","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/setup/toml-editor.ts#L97-L133","documentation":"Thrown by parseTomlStringArray when the loop over the args array runs off the end of the file without ever seeing the closing `]`. It is a safety guard: the byte-preserving TOML editor refuses to rewrite an array it cannot fully delimit, since splicing at the wrong offset would corrupt the config.","triggerScenarios":"Calling patchTomlStdioApiKey on a config where the `[mcp_servers.<name>]` args array has an opening `[` but no matching `]` anywhere after it — e.g. `args = [\"-y\",` at end of file, or the closing bracket was deleted during manual editing or a bad merge.","commonSituations":"Files truncated by an interrupted write, merge conflicts where the closing bracket ended up inside conflict markers, or users hand-deleting the last line of the array.","solutions":["Open the TOML file and add the missing closing `]` at the end of the args array","Check for merge-conflict markers (<<<<<<< / >>>>>>>) inside or right after the array and resolve them","If the file looks truncated, restore it from version control or re-run the CLI setup to regenerate the server entry"],"exampleFix":"// before (unclosed array)\nargs = [\"-y\", \"@context7/mcp\",\n// after\nargs = [\"-y\", \"@context7/mcp\"]","handlingStrategy":"validation","validationCode":"const open = (raw.match(/\\[/g) || []).length;\nconst close = (raw.match(/\\]/g) || []).length;\nif (open !== close) throw new Error(\"Unbalanced brackets in TOML file\");","typeGuard":null,"tryCatchPattern":"try {\n  await patchTomlStdioApiKey(tomlPath, serverName, apiKey);\n} catch (e) {\n  if (e.message.includes(\"Unterminated TOML array\")) {\n    console.error(`${tomlPath} has an unclosed args array — restore from git or fix manually`);\n    // offer: await restoreFromGit(tomlPath)\n  }\n}","preventionTips":["Keep bracket counts balanced — run a TOML linter after manual edits","Never leave merge-conflict markers in config files","Restore truncated files from version control rather than patching them"],"tags":["toml","parsing","config","mcp"],"backgroundTag":"invalid-argument-format","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"}