{"record":{"id":"08f32fe0c74d3b0c","repo":"upstash/context7","slug":"toml-files-containing-multiline-strings-are-not-sa","errorCode":null,"errorMessage":"TOML files containing multiline strings are not safely editable","messagePattern":"TOML files containing multiline strings are not safely editable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/setup/toml-editor.ts","lineNumber":186,"sourceCode":" * Updates only the `args` value of an existing Context7 stdio TOML entry.\n * Every other byte in the config is preserved. Unsupported `args` syntax\n * throws instead of allowing setup to replace a configuration it cannot read.\n * Returns false only when the requested server table is absent.\n */\nexport async function patchTomlStdioApiKey(\n  filePath: string,\n  serverName: string,\n  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);","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/setup/toml-editor.ts#L168-L204","documentation":"Thrown by patchTomlStdioApiKey before any parsing when the file contains TOML multiline strings (`\"\"\"` or `'''`). The byte-preserving editor deliberately bails out on files with multiline strings because their contents can contain quotes, brackets, or lines that look like `args = ` / table headers, which its lightweight scanner cannot safely interpret.","triggerScenarios":"Calling patchTomlStdioApiKey with a filePath whose TOML content includes any occurrence of `\"\"\"` or `'''` — e.g. multi-line descriptions, embedded prompts, or notes inside the mcp_servers config.","commonSituations":"Users adding long descriptions or documentation blocks to their MCP config with triple-quoted strings, or configs migrated from tools that emit multiline strings.","solutions":["Rewrite the multiline string(s) in the config as single-line basic strings with \\n escapes","Move long text out of the TOML config entirely (e.g. into a separate doc file)","Re-run the patch after removing all `\"\"\"` and `'''` sequences from the file"],"exampleFix":"// before\ndescription = \"\"\"\nContext7 MCP server\n\"\"\"\nargs = [\"-y\", \"@context7/mcp\"]\n// after\ndescription = \"Context7 MCP server\"\nargs = [\"-y\", \"@context7/mcp\"]","handlingStrategy":"validation","validationCode":"if (raw.includes('\\\"\\\"\\\"') || raw.includes(\"''\" + \"'\")) {\n  throw new Error(\"File uses TOML multiline strings; rewrite as single-line strings first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await patchTomlStdioApiKey(tomlPath, serverName, apiKey);\n} catch (e) {\n  if (e.message.includes(\"multiline strings\")) {\n    console.error(\"Rewrite multiline strings as single-line (use \\\\n escapes) before patching\");\n  }\n}","preventionTips":["Avoid triple-quoted strings in machine-managed TOML configs","Keep long descriptions in separate files, not inline config values","Use \\n escapes in basic strings when multiline text is required"],"tags":["toml","config","unsupported-feature","multiline-string"],"backgroundTag":"unsupported-operation","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"}