different-ai/openwork · error

server_name is required

Error message

server_name is required

What it means

Thrown by `opencodeMcpAuth` in the Electron runtime when the `serverName` argument is missing, null, or whitespace-only. The server name identifies which MCP server to authenticate with via the `opencode` CLI, so it is validated (trimmed, non-empty) before the binary is resolved and executed.

Source

Thrown at apps/desktop/electron/runtime.mjs:2269

      env: { ...(await buildChildEnv()), OPENCODE_INSTALL_DIR: installDir },
      timeoutMs: 180_000,
    });
    return {
      ok: result.status === 0,
      status: result.status,
      stdout: result.stdout,
      stderr: result.stderr,
    };
  }

  async function opencodeMcpAuth(projectDir, serverName) {
    const safeProjectDir = String(projectDir ?? "").trim();
    const safeServerName = String(serverName ?? "").trim();
    if (!safeProjectDir) {
      throw new Error("project_dir is required");
    }
    if (!safeServerName) {
      throw new Error("server_name is required");
    }

    const program = resolveBinary("opencode");
    if (!program) {
      throw new Error("Failed to locate opencode.");
    }

    const result = await runShellCommand(program, ["mcp", "auth", safeServerName], {
      cwd: safeProjectDir,
      env: await buildChildEnv(),
      timeoutMs: 120_000,
    });
    return {
      ok: result.status === 0,
      status: result.status,
      stdout: result.stdout,
      stderr: result.stderr,
    };

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Pass the actual MCP server name (non-empty string) to opencodeMcpAuth
  2. Validate/trim serverName at the call site and surface a UI message if it is blank
  3. Fix the data source so server entries always carry a name

Example fix

// before
await opencodeMcpAuth(projectDir, selectedServer?.name);
// after
const name = selectedServer?.name?.trim();
if (!name) throw new Error('Select an MCP server first');
await opencodeMcpAuth(projectDir, name);
Defensive patterns

Strategy: validation

Validate before calling

function hasServerName(name) {
  return typeof name === 'string' && name.trim().length > 0;
}

Type guard

function isNamedServer(s) {
  return typeof s?.name === 'string' && s.name.trim().length > 0;
}

Try / catch

try {
  await opencodeMcpAuth(projectDir, serverName);
} catch (e) {
  if (e.message === 'server_name is required') {
    showError('Select an MCP server to authenticate');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `opencodeMcpAuth(projectDir)`, `opencodeMcpAuth(projectDir, undefined)`, `opencodeMcpAuth(projectDir, null)` or `opencodeMcpAuth(projectDir, " ")`.

Common situations: Renderer sends an MCP auth request for a server entry that was deleted or never had a name; a list-selection bug passing an empty identifier; deserialized config where serverName defaulted to an empty string.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/4c54b3b2b794b74c. Report an issue: GitHub.