googleapis/mcp-toolbox · error
failed to read a prebuilt tool %w
Error message
failed to read a prebuilt tool %w
What it means
After listing the embedded tools directory, loadPrebuiltToolYAMLs reads each .yaml file with prebuiltConfigsFS.ReadFile. This error wraps a failure reading one specific embedded file — for embedded FSs this is rare (contents are in the binary) and usually indicates an inconsistent build or corrupted embed state.
Source
Thrown at internal/prebuiltconfigs/prebuiltconfigs.go:77
}
// Load all available pre built tools
func loadPrebuiltToolYAMLs() (map[string][]byte, []string, error) {
toolYAMLs := make(map[string][]byte)
var sourceTypes []string
entries, err := prebuiltConfigsFS.ReadDir("tools")
if err != nil {
errMsg := fmt.Errorf("failed to read prebuilt tools %w", err)
return nil, nil, errMsg
}
for _, entry := range entries {
lowerName := strings.ToLower(entry.Name())
if !entry.IsDir() && (strings.HasSuffix(lowerName, ".yaml")) {
filePathInFS := path.Join("tools", entry.Name())
content, err := prebuiltConfigsFS.ReadFile(filePathInFS)
if err != nil {
errMsg := fmt.Errorf("failed to read a prebuilt tool %w", err)
return nil, nil, errMsg
}
sourceTypeKey := entry.Name()[:len(entry.Name())-len(".yaml")]
sourceTypes = append(sourceTypes, sourceTypeKey)
toolYAMLs[sourceTypeKey] = content
}
}
if len(toolYAMLs) == 0 {
errMsg := fmt.Errorf("no prebuilt tool configurations were loaded.%w", err)
return nil, nil, errMsg
}
return toolYAMLs, sourceTypes, nil
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Identify which file fails from the wrapped error and confirm it is a regular file under internal/prebuiltconfigs/tools/.
- Remove/rename any directory or symlink whose name ends in .yaml.
- Rebuild the binary to refresh embedded contents.
- If a custom prebuiltConfigsFS is injected in tests, ensure it returns readable bytes for every listed entry.
Defensive patterns
Strategy: try-catch
Try / catch
content, err := prebuiltConfigsFS.ReadFile(filePathInFS)
if err != nil {
return fmt.Errorf("failed to read a prebuilt tool %w (path=%s)", err, filePathInFS)
} Prevention
- Keep tools/ entries as regular .yaml files — never directories or symlinks with a .yaml name.
- Rebuild binaries after modifying embedded assets; never mix stale binaries with new sources.
- Include the failing path in error context when wrapping.
When it happens
Trigger: ReadFile fails on a file discovered by ReadDir — e.g. the entry vanished between listing and reading in a non-embedded (OS-dir) build variant, a directory named "*.yaml" passes the suffix check but can't be ReadFile'd, or path.Join produced an unexpected path.
Common situations: Someone committed a directory named like "mydb.yaml/" which IsDir()==false handling misses in odd builds; a modified FS wrapper in tests injecting a fake that lists but cannot serve files.
Related errors
- failed to read prebuilt tools %w
- error finding YAML files in %q: %w
- error finding YML files in %q: %w
- failed to stat file: %w
- failed to rename file: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/84ded948be98c436.
Report an issue: GitHub.