upstash/context7 · error
TOML files containing multiline strings are not safely…
Error message
TOML files containing multiline strings are not safely editable
What it means
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.
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
Example fix
// before description = """ Context7 MCP server """ args = ["-y", "@context7/mcp"] // after description = "Context7 MCP server" args = ["-y", "@context7/mcp"]
Defensive patterns
Strategy: validation
Validate before calling
if (raw.includes('\"\"\"') || raw.includes("''" + "'")) {
throw new Error("File uses TOML multiline strings; rewrite as single-line strings first");
} Try / catch
try {
await patchTomlStdioApiKey(tomlPath, serverName, apiKey);
} catch (e) {
if (e.message.includes("multiline strings")) {
console.error("Rewrite multiline strings as single-line (use \\n escapes) before patching");
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Users adding long descriptions or documentation blocks to their MCP config with triple-quoted strings, or configs migrated from tools that emit multiline strings.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Existing MCP args do not invoke
- Existing MCP server has no safely editable args array
- Expected a comma or closing bracket in MCP args
- Expected a TOML array for MCP args
- MCP args must be a TOML array containing only strings
AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16).
Data as JSON: /api/errors/08f32fe0c74d3b0c.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/setup/toml-editor.ts:186
* Updates only the `args` value of an existing Context7 stdio TOML entry.
* Every other byte in the config is preserved. Unsupported `args` syntax
* throws instead of allowing setup to replace a configuration it cannot read.
* Returns false only when the requested server table is absent.
*/
export async function patchTomlStdioApiKey(
filePath: string,
serverName: string,
apiKey: string | undefined
): Promise<boolean> {
let raw: string;
try {
raw = await readFile(filePath, "utf-8");
} catch {
return false;
}
if (raw.includes('"""') || raw.includes("'''")) {
throw new Error("TOML files containing multiline strings are not safely editable");
}
const range = findTomlServerArgs(raw, serverName);
if (!range) return false;
const args = range.tokens.map((token) => token.value);
if (!args.some(isContext7Package)) {
throw new Error(`Existing MCP args do not invoke ${STDIO_PACKAGE}`);
}
const apiKeyIndexes = args.flatMap((arg, index) => (arg === "--api-key" ? [index] : []));
let content: string;
if (apiKey && apiKeyIndexes.length === 1 && apiKeyIndexes[0] + 1 < range.tokens.length) {
const valueToken = range.tokens[apiKeyIndexes[0] + 1];
content = raw.slice(0, valueToken.start) + JSON.stringify(apiKey) + raw.slice(valueToken.end);
} else {
const patched = withoutApiKey(args);
if (apiKey) patched.push("--api-key", apiKey);View on GitHub (pinned to 4416fb855b)