alibaba/open-code-review · error
tool names in %s must not be empty
Error message
tool names in %s must not be empty
What it means
After successfully parsing the tools JSON array, setMCPServerValue rejects empty strings inside the array with "tool names in <server> must not be empty". Empty tool names would never match a server-exposed tool, so they are treated as config mistakes.
Source
Thrown at cmd/opencodereview/config_cmd.go:915
return fmt.Errorf("MCP server URL %q must include a host", value)
}
entry.URL = value
case "headers":
parsed, err := parseMCPHeaders(value)
if err != nil {
return fmt.Errorf("invalid headers for %s: %w", key, err)
}
entry.Headers = parsed
case "tools":
var tools []string
if err := json.Unmarshal([]byte(value), &tools); err != nil {
return fmt.Errorf("invalid JSON array for %s: %w", key, err)
}
seen := make(map[string]struct{}, len(tools))
filtered := make([]string, 0, len(tools))
for _, t := range tools {
if t == "" {
return fmt.Errorf("tool names in %s must not be empty", key)
}
if _, dup := seen[t]; dup {
continue
}
seen[t] = struct{}{}
filtered = append(filtered, t)
}
entry.Tools = filtered
case "setup":
entry.Setup = value
default:
return fmt.Errorf("unknown MCP server field %q: supported fields are type, command, args, env, url, headers, tools, setup", field)
}
cfg.MCPServers[name] = entry
return nil
}
View on GitHub (pinned to 5cf97d0d15)
Solutions
- Remove the empty entry: `ocr config set mcp-servers.myserver.tools '["read_file"]'`
- Check for double or trailing commas in the array
- Verify each tool name against the server's advertised tool list
Example fix
// before ocr config set mcp-servers.myserver.tools '["read_file",]' // after ocr config set mcp-servers.myserver.tools '["read_file"]'
Defensive patterns
Strategy: validation
Validate before calling
func hasNoEmptyNames(s string) bool {
var a []string
if json.Unmarshal([]byte(s), &a) != nil { return false }
for _, t := range a { if t == "" { return false } }
return len(a) > 0
} Type guard
func allNonEmpty(xs []string) bool { for _, x := range xs { if x == "" { return false } }; return true } Try / catch
if err := setMCPServerValue(cfg, name, "tools", raw); err != nil {
if strings.Contains(err.Error(), "must not be empty") { /* drop empty entries and retry */ }
return err
} Prevention
- Filter empty strings before serializing the tools list
- Join tool names into JSON via encoding/json, not strings.Join with commas
- Validate the list against the server's advertised tools
When it happens
Trigger: A tools array containing "" — e.g. '["read_file",""]' — usually from a trailing comma in a hand-written list, or from splitting an empty string into an element.
Common situations: Trailing comma left inside the JSON array; programmatic construction joining values with commas producing "a,,b"; placeholder left unfilled.
Related errors
- MCP server %q not found
- invalid max_tokens %q: must be a positive integer
- unknown config key: %s Supported keys: %s Provider fields: a
- invalid URL for %s: %w
- invalid model list for %s: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/db9769bccc50676d.
Report an issue: GitHub.