JuliusBrussee/caveman · error
unsupported catalog shape
Error message
unsupported catalog shape
What it means
After successfully unmarshalling, extractTools only recognizes top-level shapes: object with "tools", object with "functions", array, or a single tool object. Anything else (scalar, string, object with unrelated keys) is rejected as 'unsupported catalog shape'.
Solutions
- Unwrap to the tools array first, e.g. `jq '.tools' catalog.json | caveman-shrink lint -`
- Use an MCP client to fetch the live tool list and save that ({"tools":[...]}) instead of the server config
- Check the top-level shape: it must be an array, a single tool object, or an object with a "tools" or "functions" array key
- If double-encoded, decode once (`jq -r . | jq .`) before passing in
Example fix
// before
cat mcp-server-config.json | caveman-shrink lint - # {"mcpServers":{...}}
// after
jq '{tools}' tools.json | caveman-shrink lint - # {"tools":[...]} Defensive patterns
Strategy: type-guard
Validate before calling
const top = JSON.parse(input)
const isCatalog = Array.isArray(top) ||
(typeof top === 'object' && top !== null &&
(Array.isArray((top as any).tools) || Array.isArray((top as any).functions))) Type guard
function isToolCatalog(v: unknown): boolean {
if (Array.isArray(v)) return true
if (typeof v !== 'object' || v === null) return false
const o = v as Record<string, unknown>
return Array.isArray(o.tools) || Array.isArray(o.functions)
} Try / catch
tools, err := extractTools(input)
if err != nil && err.Error() == "unsupported catalog shape" {
// unwrap nested tools or convert server-config to a tool list
} Prevention
- Always pass the tools array ({"tools":[...]}), never an MCP server config file
- Unwrap nested fields with jq before linting
- Check the top-level JSON type before calling Lint/SelectionProfile
When it happens
Trigger: Passing valid JSON that is not a tool catalog: a plain string, a number, `{"mcpServers": {...}}` (server-config not tool-list), `null`, or a config object with the tools nested under a different key.
Common situations: Feeding an MCP server configuration file (which lists servers, not tools) instead of the tools payload; passing a JSON string with tools embedded inside another field; double-quoted JSON (a JSON string containing a catalog).
Related errors
- cave_output_schema_mismatch
- local learn snapshot has no sinks array at
- report fixture
- assembly slot content is not JSON-serializable
- canonical span
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/04f8c6f7b52b8f91.
Report an issue: GitHub.
Appendix: source
Thrown at shrink/shrink.go:258
func extractTools(input []byte) ([]toolEntry, error) {
var top any
if err := json.Unmarshal(input, &top); err != nil {
return nil, fmt.Errorf("not valid JSON: %w", err)
}
var rawList []any
switch t := top.(type) {
case map[string]any:
if v, ok := t["tools"].([]any); ok {
rawList = v
} else if v, ok := t["functions"].([]any); ok {
rawList = v
} else {
rawList = []any{t} // a single tool object
}
case []any:
rawList = t
default:
return nil, fmt.Errorf("unsupported catalog shape")
}
var entries []toolEntry
for _, item := range rawList {
obj, ok := item.(map[string]any)
if !ok {
continue
}
// OpenAI nests under "function".
toolObj := obj
if fn, ok := obj["function"].(map[string]any); ok {
toolObj = fn
}
name, _ := toolObj["name"].(string)
if name == "" {
continue
}
raw, _ := json.Marshal(obj)View on GitHub (pinned to 3ee70a1026)