upstash/context7 · error · Error
TOML files containing multiline strings are not safely edita
Error message
TOML files containing multiline strings are not safely editable
What it means
A whole-file pre-check found triple quotes ('"""' or "'''") anywhere in the TOML. Because the editor rewrites by character offsets, any multiline string in the file makes offsets unsafe, so it refuses to edit rather than corrupt the file.
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 edc9eeb77b)
Solutions
- Convert multiline strings in the file to single-line strings with \n escapes
- Move large blobs (certs, prompts) to a separate file referenced by path
- Then re-run the patch/setup command
Example fix
// before description = """ long text """ // after description = "long text\n"
Defensive patterns
Strategy: validation
Validate before calling
if (raw.includes('"""') || raw.includes("'''")) {
throw new Error('TOML files containing multiline strings are not safely editable');
} Type guard
function isSafelyEditableToml(raw: string): boolean {
return !raw.includes('"""') && !raw.includes("'''");
} Try / catch
try { await patchTomlStdioApiKey(...); } catch (e) { if (/multiline strings are not safely editable/.test(e.message)) { /* convert triple-quoted strings to single-line, then retry */ } throw e; } Prevention
- Avoid multiline strings in MCP config files
- Store certs/prompts in separate files referenced by path
- Pre-check with isSafelyEditableToml before calling the patcher
When it happens
Trigger: Running the stdio API-key patch on a config that contains any multiline string, even in an unrelated section (e.g. a long description or certificate block).
Common situations: Configs with embedded PEM certificates, long prompts, or templated text stored as multiline strings; shared team configs with comment-like blocks.
Related errors
- Multiline strings are not supported in MCP args
- Unsupported TOML escape \\${escape}
- Expected a TOML array for MCP args
- MCP args must be a TOML array containing only strings
- Existing MCP server has no safely editable args array
AI-assisted analysis of upstash/context7@edc9eeb77b (2026-08-28).
Data as JSON: /api/errors/08f32fe0c74d3b0c.
Report an issue: GitHub.