upstash/context7 · error · Error
Unterminated TOML basic string in MCP args
Error message
Unterminated TOML basic string in MCP args
What it means
A double-quoted string in the MCP args array was opened but never closed before the end of the file — the scanning loop ran off the end without finding a closing quote.
Source
Thrown at packages/cli/src/setup/toml-editor.ts:69
continue;
}
if (escape !== "u" && escape !== "U") {
throw new Error(`Unsupported TOML escape \\${escape}`);
}
const width = escape === "u" ? 4 : 8;
const hex = source.slice(index, index + width);
if (!new RegExp(`^[0-9A-Fa-f]{${width}}$`).test(hex)) {
throw new Error(`Invalid TOML Unicode escape \\${escape}${hex}`);
}
const codePoint = Number.parseInt(hex, 16);
if (codePoint > 0x10ffff || (codePoint >= 0xd800 && codePoint <= 0xdfff)) {
throw new Error(`Invalid TOML Unicode code point U+${hex}`);
}
value += String.fromCodePoint(codePoint);
index += width;
}
throw new Error("Unterminated TOML basic string in MCP args");
}
function parseTomlLiteralString(source: string, start: number): TomlStringToken {
const endQuote = source.indexOf("'", start + 1);
if (endQuote === -1) throw new Error("Unterminated TOML literal string in MCP args");
const value = source.slice(start + 1, endQuote);
if (value.includes("\n") || value.includes("\r")) {
throw new Error("Multiline strings are not supported in MCP args");
}
return { value, start, end: endQuote + 1 };
}
function parseTomlStringArray(
source: string,
start: number
): { tokens: TomlStringToken[]; end: number } {
if (source[start] !== "[") throw new Error("Expected a TOML array for MCP args");
View on GitHub (pinned to edc9eeb77b)
Solutions
- Add the missing closing double quote on the same line
- Ensure plain ASCII quotes (" not \u201c/\u201d)
- Validate the TOML with a linter/editor before saving
Example fix
// before args = ["--api-key // after args = ["--api-key"]
Defensive patterns
Strategy: validation
Validate before calling
const openQuotes = (line.match(/(^|[^\\])"/g) ?? []).length;
if (openQuotes % 2 !== 0) throw new Error('Unterminated basic string'); Type guard
function lineHasBalancedQuotes(line: string): boolean {
return ((line.match(/"/g) ?? []).length) % 2 === 0;
} Try / catch
catch (e) { if (/Unterminated TOML basic string/.test(e.message)) { /* add closing quote, re-run */ } throw e; } Prevention
- Disable smart quotes in editors
- Run a TOML parser (e.g. SmolToml) as a pre-check
When it happens
Trigger: args = ["--flag missing closing quote, or the closing quote was deleted/turned into a smart quote by an editor.
Common situations: Manually editing args and deleting a quote; rich-text editors converting " to curly quotes; truncated file from a failed write.
Related errors
- Unterminated TOML literal string in MCP args
- Expected a comma or closing bracket in MCP args
- Unterminated TOML array in MCP args
- Multiline strings are not supported in MCP args
- Unsupported TOML escape \\${escape}
AI-assisted analysis of upstash/context7@edc9eeb77b (2026-08-28).
Data as JSON: /api/errors/e6289e3aaa17b633.
Report an issue: GitHub.