Skip to content

A local MCP server entry may declare an empty command and is then launched with no executable #818

Closed

Description

What happens

Config.McpLocal declares the command as:

export const McpLocal = z.object({
  type: z.literal("local").describe("Type of MCP server connection"),
  command: z.string().array().describe("Command and arguments to run the MCP server"),
  ...
})

z.string().array() accepts an empty list. The connection is then started from src/mcp/index.ts:918:

if (mcp.type === "local") {
  const [cmd, ...args] = mcp.command
  ...
  const sandbox = Sandbox.wrapArgv({ file: cmd, args, ... })

With mcp.command === [], cmd is undefined, so the launch is attempted with file: undefined — a sandbox-wrapped spawn of nothing. The failure surfaces far from the config that caused it, as an MCP server that will not start.

Why it is wrong

An MCP entry with an empty command is a configuration mistake with no valid interpretation: there is no executable to run. It should be rejected where the mistake is, not turned into a spawn attempt.

Compare McpRemote, which validates its url in the schema. A local server's command is the equivalent required field, and it is the only part of the entry with nothing to fall back on.

Repro

Config.McpLocal.safeParse({ type: "local", command: [] })
// -> { success: true }     an empty command is accepted

which then reaches Sandbox.wrapArgv({ file: undefined, args: [] }).

Suggested fix

command: z
  .string()
  .array()
  .min(1, 'A local MCP server needs a command to run, for example ["npx", "-y", "my-mcp-server"]')
  .describe("Command and arguments to run the MCP server"),

The message names the field problem and shows a working example, matching the style of the other schema messages in this file.

test/config/mcp-command-schema.test.ts is new and covers a valid command, the empty list, a bare string, a non-string element, and that the rejection message mentions command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions