upstash/context7 · error

Invalid TOML Unicode code point U+

Error message

Invalid TOML Unicode code point U+${hex}

What it means

Thrown by parseTomlBasicString when a syntactically valid \uXXXX or \UXXXXXXXX escape decodes to a code point that is not a valid Unicode scalar value: above U+10FFFF or within the surrogate range U+D800–U+DFFF. String.fromCodePoint would throw a RangeError on such values, so the parser rejects them first with this clearer message.

Solutions

  1. Replace surrogate pairs with the single combined code point (e.g. \uD83D\uDE00 becomes \U0001F600).
  2. Use a code point ≤ U+10FFFF and outside D800–DFFF.
  3. Paste the actual character into the config file instead of an escape (TOML is UTF-8).
  4. Remove the character or substitute a supported one.

Example fix

// before (config.toml)
args = ["--emoji", "\uD83D\uDE00"]
// after
args = ["--emoji", "\U0001F600"]
Defensive patterns

Strategy: validation

Validate before calling

function validCodePoints(s) {
  return [...s.matchAll(/\\(?:u|U)([0-9A-Fa-f]{4,8})/g)].every(m => {
    const cp = parseInt(m[1], 16);
    return cp <= 0x10ffff && !(cp >= 0xd800 && cp <= 0xdfff);
  });
}
if (!args.every(a => typeof a === 'string' && validCodePoints(a))) throw new Error('invalid Unicode code point in args');

Try / catch

try { parseConfig(toml); } catch (e) { if (e.message.startsWith('Invalid TOML Unicode code point')) { console.error('Replace surrogate pairs with the combined code point:', e.message); } else throw e; }

Prevention

When it happens

Trigger: A TOML basic string in MCP args contains an escape like \uD800 (surrogate half), \uDFFF, or \U00110000 (> U+10FFFF). This typically happens when someone copies a UTF-16 surrogate pair from JSON/JS source instead of the combined code point.

Common situations: Copy-pasting emoji or CJK characters encoded as surrogate pairs (\uD83D\uDE00) from JavaScript source; encoding values above the Unicode maximum; converting UTF-16 code units instead of code points.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

    }

    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 {
  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(

View on GitHub (pinned to 4416fb855b)