upstash/context7 · error

Unterminated TOML basic string in MCP args

Error message

Unterminated TOML basic string in MCP args

What it means

Thrown by parseTomlBasicString when the loop reaches the end of the source without finding the closing double quote of a basic string. It is a hard stop after the scanning while-loop exits, meaning the string opened with " but was never closed before EOF.

Solutions

  1. Add the missing closing double quote to the string in the MCP config.
  2. Escape any literal " inside the string as \" so it does not terminate the string early.
  3. Check the lines above the reported location — an earlier unbalanced quote may be consuming subsequent content.
  4. Validate the whole TOML file with a standard TOML parser/linter to locate the unbalanced quote.

Example fix

// before (config.toml)
args = ["--name "my server"]
// after
args = ["--name", "my server"]
Defensive patterns

Strategy: validation

Validate before calling

function balancedDoubleQuotes(s) { return (s.match(/(?<!\\)"/g) || []).length % 2 === 0; }
if (!balancedDoubleQuotes(tomlSource)) console.warn('unbalanced double quotes in TOML');

Try / catch

try { parseConfig(toml); } catch (e) { if (e.message.includes('Unterminated TOML basic string')) { console.error('A "..." string is missing its closing quote — escape inner quotes as \"'); } else throw e; }

Prevention

When it happens

Trigger: Parsing MCP config args where a double-quoted string is missing its closing quote, e.g. args = ["--flag, or a quote character earlier in the file swallowed the rest of the content into one unterminated string.

Common situations: Hand-editing config.toml and deleting a closing quote; an unescaped " inside a basic string (should be \") ending the string early and leaving a later one unterminated; truncated or partially written config files.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16). Data as JSON: /api/errors/e6289e3aaa17b633. Report an issue: GitHub.

Appendix: 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 4416fb855b)