upstash/context7 · error · Error

Expected a comma or closing bracket in MCP args

Error message

Expected a comma or closing bracket in MCP args

What it means

While walking the args array, after a string element the parser found neither a comma nor the closing bracket — i.e. malformed separation, such as a missing comma between elements or stray characters after an element.

Source

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

    const quote = source[index];
    if (quote !== '"' && quote !== "'") {
      throw new Error("MCP args must be a TOML array containing only strings");
    }
    if (source.slice(index, index + 3) === quote.repeat(3)) {
      throw new Error("Multiline strings are not supported in MCP args");
    }

    const token =
      quote === '"' ? parseTomlBasicString(source, index) : parseTomlLiteralString(source, index);
    tokens.push(token);
    index = skipTomlArrayTrivia(source, token.end);

    if (source[index] === ",") {
      index++;
      continue;
    }
    if (source[index] !== "]") {
      throw new Error("Expected a comma or closing bracket in MCP args");
    }
  }
  throw new Error("Unterminated TOML array in MCP args");
}

function findTomlServerArgs(
  raw: string,
  serverName: string
): { start: number; end: number; tokens: TomlStringToken[] } | null {
  const escapedName = serverName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  const tableKey = `(?:mcp_servers|"mcp_servers"|'mcp_servers')`;
  const serverKey = `(?:${escapedName}|"${escapedName}"|'${escapedName}')`;
  const headerRe = new RegExp(
    `^[\\uFEFF\\t ]*\\[[\\t ]*${tableKey}[\\t ]*\\.[\\t ]*${serverKey}[\\t ]*\\][\\t ]*(?:#.*)?\\r?$`,
    "m"
  );
  const header = headerRe.exec(raw);
  if (!header) return null;

View on GitHub (pinned to edc9eeb77b)

Solutions

  1. Separate elements with commas: args = ["a", "b"]
  2. Remove stray characters between elements
  3. A trailing comma before ] is fine; missing commas are not

Example fix

// before
args = ["--a" "--b"]
// after
args = ["--a", "--b"]
Defensive patterns

Strategy: validation

Validate before calling

// strip strings then check only commas/brackets/whitespace remain between elements
const stripped = arrayBody.replace(/"[^"\\n]*"|'[^'\\n]*'/g, '');
if (!/^[\\s,]*\\]?$/.test(stripped)) throw new Error('bad separator');

Type guard

function hasCleanSeparators(arrayBody: string): boolean {
  return /^[\\s,]*$/.test(arrayBody.replace(/"[^"\\n]*"|'[^'\\n]*'/g, '').replace(/\\]$/, ''));
}

Try / catch

catch (e) { if (/comma or closing bracket/.test(e.message)) { /* fix separators */ } throw e; }

Prevention

When it happens

Trigger: args = ["a" "b"] (missing comma), args = ["a"; "b"], or trailing garbage like args = ["a" x].

Common situations: Hand-adding an element and forgetting the comma; using semicolons (JS style) instead of commas; stray characters from a bad paste.

Related errors


AI-assisted analysis of upstash/context7@edc9eeb77b (2026-08-28). Data as JSON: /api/errors/592c7e5fad348715. Report an issue: GitHub.