alibaba/open-code-review · error

MCP server command cannot be empty

Error message

MCP server command cannot be empty

What it means

When setting mcp_servers.<name>.command, an empty string is rejected because a stdio MCP server needs an executable command to launch. This error guards against writing a config entry that could never start.

Source

Thrown at cmd/opencodereview/config_cmd.go:864

	if len(parts) != 3 || parts[1] == "" || parts[2] == "" {
		return fmt.Errorf("invalid MCP server key %q: expected mcp_servers.<name>.<field>", key)
	}
	name, field := parts[1], parts[2]

	if cfg.MCPServers == nil {
		cfg.MCPServers = make(map[string]MCPServerConfig)
	}
	entry := cfg.MCPServers[name]

	switch field {
	case "type":
		if value != "stdio" && value != "remote" {
			return fmt.Errorf("invalid MCP server type %q: must be \"stdio\" or \"remote\"", value)
		}
		entry.Type = value
	case "command":
		if value == "" {
			return fmt.Errorf("MCP server command cannot be empty")
		}
		entry.Command = value
	case "args":
		var args []string
		if err := json.Unmarshal([]byte(value), &args); err != nil {
			return fmt.Errorf("invalid JSON array for %s: %w", key, err)
		}
		entry.Args = args
	case "env":
		var env []string
		if err := json.Unmarshal([]byte(value), &env); err != nil {
			return fmt.Errorf("invalid JSON array for %s: %w", key, err)
		}
		for _, e := range env {
			idx := strings.Index(e, "=")
			if idx <= 0 {
				return fmt.Errorf("invalid env entry %q: must be in KEY=VALUE format", e)
			}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Pass the actual executable path or name, e.g. npx or /usr/local/bin/myserver
  2. If the server is remote instead, set mcp_servers.<name>.type remote and a url rather than command
  3. Remove the half-configured entry entirely if it is no longer needed

Example fix

// before
ocr config set mcp_servers.filesystem.command ""
// after
ocr config set mcp_servers.filesystem.command npx
Defensive patterns

Strategy: validation

Validate before calling

if command == "" {
	return fmt.Errorf("command is required for stdio servers")
}

Try / catch

if err := setMCPServerValue(cfg, key, value); err != nil {
	fmt.Fprintf(os.Stderr, "config set failed: %v\n", err)
	os.Exit(1)
}

Prevention

When it happens

Trigger: Calling setMCPServerValue with field "command" and value "".

Common situations: Running `ocr config set mcp_servers.myserver.command` with an empty argument (shell consumes the empty string), or scripting config generation that skips the value.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/52f6d37a6989e1b7. Report an issue: GitHub.