{"record":{"id":"263fd8ed31ebd2dd","repo":"googleapis/mcp-toolbox","slug":"tool-type-q-already-registered-263fd8","errorCode":null,"errorMessage":"tool type %q already registered","messagePattern":"tool type %q already registered","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview.go","lineNumber":48,"sourceCode":"const resourceType string = \"postgres-database-overview\"\n\nconst databaseOverviewStatement = `\n    SELECT\n    current_setting('server_version') AS pg_version,\n    pg_is_in_recovery() AS is_replica,\n    (now() - pg_postmaster_start_time())::TEXT AS uptime,\n    current_setting('max_connections')::int AS max_connections,\n    (SELECT count(*) FROM pg_stat_activity) AS current_connections,\n    (SELECT count(*) FROM pg_stat_activity WHERE state = 'active') AS active_connections,\n    round(\n        (100.0 * (SELECT count(*) FROM pg_stat_activity) / current_setting('max_connections')::int),\n        2\n    ) AS pct_connections_used;\n`\n\nfunc init() {\n\tif !tools.Register(resourceType, newConfig) {\n\t\tpanic(fmt.Sprintf(\"tool type %q already registered\", resourceType))\n\t}\n}\n\nfunc newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.ToolConfig, error) {\n\tactual := Config{ConfigBase: tools.ConfigBase{Name: name}}\n\tif err := decoder.DecodeContext(ctx, &actual); err != nil {\n\t\treturn nil, err\n\t}\n\treturn actual, nil\n}\n\ntype compatibleSource interface {\n\tPostgresPool() *pgxpool.Pool\n\tRunSQL(context.Context, string, []any) (any, error)\n}\n\ntype Config struct {\n\ttools.ConfigBase `yaml:\",inline\"`","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview.go#L30-L66","documentation":"This is a startup panic from postgresdatabaseoverview's init(): tools.Register (internal/tools/tools.go:43) returned false because a factory for the resourceType string (\"postgres-database-overview\") is already in the global toolRegistry map. The registry maps YAML config `type` strings to factory functions; a collision is treated as a programmer error and the binary panics during package initialization, before any server code runs.","triggerScenarios":"Linking a binary that imports two packages whose init() both register the same postgres tool type string — almost always a copied postgresdatabaseoverview.go whose `resourceType` constant kept the original value, or two files declaring the same constant in one package.","commonSituations":"Cloning the file to add a tweaked overview tool and renaming only the package; a bad merge leaving duplicate directories; vendoring/forking the package and importing both versions into cmd/toolbox.","solutions":["rg '\"postgres-database-overview\"' across internal/ and cmd/ to find the colliding registration; change one `resourceType` constant.","If the copy is a legitimate new tool, give it its own kebab-case type (e.g. \"postgres-database-overview-detailed\") and matching package name.","Delete the redundant copied package and import if it is leftover.","Verify with `go build ./...` and the postgres tool unit tests."],"exampleFix":"// before (duplicate copy)\nconst resourceType string = \"postgres-database-overview\"\n// after\nconst resourceType string = \"postgres-database-overview-detailed\"","handlingStrategy":"validation","validationCode":"// Pre-build uniqueness check (script or test):\n//   rg -F '\"postgres-database-overview\"' internal/ cmd/  # expect exactly 1 match\n// Go-side smoke test:\nfunc TestToolboxInit(t *testing.T) {\n\t// importing all tool packages + calling any code path that triggers init()\n\t// must not panic with \"already registered\"\n\t_ = tools.ErrUnknownToolType\n}","typeGuard":"func typeIsTaken(resourceType string) bool {\n\treturn !tools.Register(resourceType, func(ctx context.Context, name string, d *yaml.Decoder) (tools.ToolConfig, error) {\n\t\treturn nil, fmt.Errorf(\"probe\")\n\t})\n}","tryCatchPattern":null,"preventionTips":["When creating a variant of a postgres tool, change `resourceType` first, then the SQL and package name.","Keep the constant equal to the tool's kebab-case name and directory name.","Add an init-touching smoke test to CI so duplicate registrations surface before release.","Run `rg -F '\"<type>\"'` before importing any new/forked tool package.","Delete dead copied packages promptly instead of leaving them importable."],"tags":["go","init-panic","duplicate-registration","tool-registry","postgres"],"backgroundTag":"duplicate-tool-type-registration","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}