upstash/context7 · error

Unsupported TOML escape \\

Error message

Unsupported TOML escape \\${escape}

What it means

Thrown by parseTomlBasicString when a backslash inside a TOML basic string starts an escape sequence that the parser does not recognize. TOML only permits a fixed set of short escapes (\b \t \n \f \r \" \\) plus \uXXXX and \UXXXXXXXX; anything else is invalid TOML. This minimal parser throws rather than guessing at the intent.

Solutions

  1. Double every backslash intended as a literal backslash: "C:\\Users\\foo".
  2. Use a single-quoted TOML literal string so backslashes are taken literally: 'C:\Users\foo'.
  3. Replace the unknown escape with a supported one (\n, \t, \r, \b, \f, \", \\, \uXXXX, \UXXXXXXXX).
  4. For unicode, use the \uXXXX (4 hex digits) or \UXXXXXXXX (8 hex digits) form.

Example fix

// before (config.toml)
args = ["--path", "C:\Users\foo"]
// after
args = ["--path", "C:\\Users\\foo"]
Defensive patterns

Strategy: validation

Validate before calling

const TOML_ESCAPES = new Set(['b','t','n','f','r','"','\\','u','U']);
function validEscapes(s) { return [...s.matchAll(/\\(.)/g)].every(([, c]) => TOML_ESCAPES.has(c)); }
if (!args.every(a => typeof a === 'string' && validEscapes(a))) throw new Error('invalid TOML escape in args');

Try / catch

try { parseConfig(toml); } catch (e) { if (e.message.startsWith('Unsupported TOML escape')) { console.error('Double the backslashes or use a literal single-quoted string:', e.message); } else throw e; }

Prevention

When it happens

Trigger: A double-quoted string in the MCP config args contains a backslash followed by a character outside the TOML escape set, e.g. "C:\Users\foo" (\U... eventually fails) or "a\/b".

Common situations: Windows file paths with unescaped backslashes; regexes like "\d+" written for another language; shell-escape habits copied into TOML strings.

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/8c170a8235dfde3c. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/setup/toml-editor.ts:54

  let index = start + 1;
  while (index < source.length) {
    const char = source[index++];
    if (char === '"') return { value, start, end: index };
    if (char === "\n" || char === "\r") {
      throw new Error("Multiline strings are not supported in MCP args");
    }
    if (char !== "\\") {
      value += char;
      continue;
    }

    const escape = source[index++];
    if (Object.hasOwn(TOML_BASIC_ESCAPES, escape)) {
      value += TOML_BASIC_ESCAPES[escape];
      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 {

View on GitHub (pinned to 4416fb855b)