upstash/context7 · error

Existing MCP server has no safely editable args array

Error message

Existing MCP server has no safely editable args array

What it means

Thrown by findTomlServerArgs when the header `[mcp_servers.<name>]` was found, but no line inside that table's body matches the strict `args = ` pattern the editor supports. The regex requires the key literally named `args` (optionally quoted), so the editor cannot locate a safe splice point for the args array.

Solutions

  1. Add an `args = ["..."]` line to the `[mcp_servers.<name>]` table (use the package name and any flags the server needs)
  2. Verify the key is exactly `args` (or "args"/'args') and not a variant like `arguments` or `argv`
  3. Ensure the args line is inside the same `[mcp_servers.<name>]` table, before the next `[...]` header
  4. If this server is not a stdio Context7 server, it should not be patched by this entry point — configure it separately

Example fix

// before
[mcp_servers.context7]
command = "npx"
// after
[mcp_servers.context7]
command = "npx"
args = ["-y", "@context7/mcp"]
Defensive patterns

Strategy: validation

Validate before calling

const hasTable = /^[\t ]*\[mcp_servers\.["']?name["']?\]/m.test(raw);
const hasArgs = /^[\t ]*(args|["']args["'])[\t ]*=/m.test(raw);
if (hasTable && !hasArgs) throw new Error("Server table exists but has no args = [...] line");

Try / catch

try {
  await patchTomlStdioApiKey(tomlPath, serverName, apiKey);
} catch (e) {
  if (e.message.includes("no safely editable args array")) {
    console.error(`Add an args = ["..."] entry to [mcp_servers.${serverName}] or set it up via the CLI`);
  }
}

Prevention

When it happens

Trigger: Calling patchTomlStdioApiKey on a server table that defines the command inline without args (e.g. `[mcp_servers.context7] command = "npx" url = "..."`), or where the array key is named differently (`arguments =`, `argv =`), or where the args assignment sits under a different table header in the same body range.

Common situations: Configs written for a different tool that uses another key name, servers configured with a URL/SSE transport instead of a stdio command, or users renaming `args` while hand-editing.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

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

  const headerRe = new RegExp(
    `^[\\uFEFF\\t ]*\\[[\\t ]*${tableKey}[\\t ]*\\.[\\t ]*${serverKey}[\\t ]*\\][\\t ]*(?:#.*)?\\r?$`,
    "m"
  );
  const header = headerRe.exec(raw);
  if (!header) return null;

  const bodyStart = raw.indexOf("\n", header.index + header[0].length) + 1;
  const effectiveBodyStart = bodyStart === 0 ? raw.length : bodyStart;
  const nextHeaderRe = /^[\t ]*\[[^\r\n]+\][\t ]*(?:#.*)?\r?$/gm;
  nextHeaderRe.lastIndex = effectiveBodyStart;
  const nextHeader = nextHeaderRe.exec(raw);
  const bodyEnd = nextHeader?.index ?? raw.length;

  const body = raw.slice(effectiveBodyStart, bodyEnd);
  const argsRe = /^[\t ]*(?:args|"args"|'args')[\t ]*=[\t ]*/gm;
  const args = argsRe.exec(body);
  if (!args) {
    throw new Error("Existing MCP server has no safely editable args array");
  }

  const start = effectiveBodyStart + args.index + args[0].length;
  const parsed = parseTomlStringArray(raw, start);
  return { start, end: parsed.end, tokens: parsed.tokens };
}

function withoutApiKey(args: string[]): string[] {
  const result: string[] = [];
  for (let index = 0; index < args.length; index++) {
    if (args[index] === "--api-key") {
      index++;
      continue;
    }
    result.push(args[index]);
  }
  return result;
}

View on GitHub (pinned to 4416fb855b)