upstash/context7 · error

Existing MCP args do not invoke

Error message

Existing MCP args do not invoke ${STDIO_PACKAGE}

What it means

Thrown by patchTomlStdioApiKey after successfully parsing the server's args array when none of the argument strings references the Context7 stdio package (STDIO_PACKAGE, optionally with an @version suffix, checked by isContext7Package). The editor only rewrites API keys into args arrays that actually launch the Context7 MCP server; patching any other server's args would silently corrupt a foreign configuration.

Solutions

  1. Make sure the args array invokes the Context7 package, e.g. args = ["-y", "@context7/mcp"] (a version suffix like @context7/mcp@1.0.0 is also accepted)
  2. Use the correct serverName — the name passed to patchTomlStdioApiKey must be the one whose args actually run the Context7 stdio server
  3. If you intentionally run a different MCP server, configure its API key manually instead of using this patch path

Example fix

// before
args = ["-y", "@someother/mcp"]
// after
args = ["-y", "@context7/mcp"]
Defensive patterns

Strategy: validation

Validate before calling

const pkg = "@context7/mcp"; // STDIO_PACKAGE
const argsMatch = raw.match(new RegExp(`\\[mcp_servers\\.["']?${server}["']?\\][\\s\\S]*?args\\s*=\\s*\\[([^\\]]*)\\]`));
if (!argsMatch || !argsMatch[1].split(",").some(a => a.trim().replace(/^["']|["']$/g, "") === pkg || a.includes(pkg + "@"))) {
  throw new Error(`Server '${server}' does not invoke ${pkg}`);
}

Try / catch

try {
  await patchTomlStdioApiKey(tomlPath, serverName, apiKey);
} catch (e) {
  if (e.message.includes("do not invoke")) {
    console.error(`${serverName} does not run the Context7 package — check serverName or reconfigure the server`);
  }
}

Prevention

When it happens

Trigger: Calling patchTomlStdioApiKey(filePath, serverName, apiKey) where `[mcp_servers.<serverName>]` exists and has a parseable args array, but no element equals the package name or `package@version` — e.g. args = ["-y", "other/mcp-server"].

Common situations: Reusing a server name that points at a different package, having renamed or swapped the package after initial setup, or vendoring the package via a local path instead of the registry name.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

  apiKey: string | undefined
): Promise<boolean> {
  let raw: string;
  try {
    raw = await readFile(filePath, "utf-8");
  } catch {
    return false;
  }

  if (raw.includes('"""') || raw.includes("'''")) {
    throw new Error("TOML files containing multiline strings are not safely editable");
  }

  const range = findTomlServerArgs(raw, serverName);
  if (!range) return false;

  const args = range.tokens.map((token) => token.value);
  if (!args.some(isContext7Package)) {
    throw new Error(`Existing MCP args do not invoke ${STDIO_PACKAGE}`);
  }

  const apiKeyIndexes = args.flatMap((arg, index) => (arg === "--api-key" ? [index] : []));
  let content: string;
  if (apiKey && apiKeyIndexes.length === 1 && apiKeyIndexes[0] + 1 < range.tokens.length) {
    const valueToken = range.tokens[apiKeyIndexes[0] + 1];
    content = raw.slice(0, valueToken.start) + JSON.stringify(apiKey) + raw.slice(valueToken.end);
  } else {
    const patched = withoutApiKey(args);
    if (apiKey) patched.push("--api-key", apiKey);
    content = raw.slice(0, range.start) + JSON.stringify(patched) + raw.slice(range.end);
  }

  if (content !== raw) {
    await mkdir(dirname(filePath), { recursive: true });
    await writeFile(filePath, content, "utf-8");
  }
  return true;

View on GitHub (pinned to 4416fb855b)