alibaba/open-code-review · error

invalid MCP server type %q: must be "stdio" or "remote"

Error message

invalid MCP server type %q: must be "stdio" or "remote"

What it means

Validation guard in setMCPServerValue for `ocr config set mcp_servers.<name>.type`: the only supported MCP server transport types are stdio (launch a local subprocess) and remote (connect to a URL). Any other string would leave the config with a type the client cannot dispatch on, so it is rejected when writing the config.

Source

Thrown at cmd/opencodereview/config_cmd.go:859

	return nil
}

func setMCPServerValue(cfg *Config, key, value string) error {
	parts := strings.SplitN(key, ".", 3)
	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)
		}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Use exactly "stdio" for a local command-based server
  2. Use exactly "remote" for an HTTP/HTTPS URL-based server
  3. Check spelling and lowercase the value; "STDIO" is rejected

Example fix

// before
ocr config set mcp_servers.filesystem.type local
// after
ocr config set mcp_servers.filesystem.type stdio
Defensive patterns

Strategy: validation

Validate before calling

if v != "stdio" && v != "remote" {
	return fmt.Errorf("type must be stdio or remote, got %q", v)
}

Type guard

func isMCPServerType(v string) bool {
	return v == "stdio" || v == "remote"
}

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 "type" and a value other than "stdio" or "remote", e.g. "local", "http", "sse", or a value with different casing like "STDIO".

Common situations: Users guessing the type name from other MCP client configs (some clients use "sse" or "http"), typing the value in uppercase, or copying config from incompatible tools.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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