{"record":{"id":"40cdf51cb1c9874a","repo":"googleapis/mcp-toolbox","slug":"tool-type-q-already-registered-40cdf5","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/serverlessspark/serverlesssparkcreatesparkbatch/serverlesssparkcreatesparkbatch.go","lineNumber":32,"sourceCode":"\npackage serverlesssparkcreatesparkbatch\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\tdataproc \"cloud.google.com/go/dataproc/v2/apiv1/dataprocpb\"\n\t\"github.com/goccy/go-yaml\"\n\t\"github.com/googleapis/mcp-toolbox/internal/tools\"\n\t\"github.com/googleapis/mcp-toolbox/internal/tools/serverlessspark/createbatch\"\n\t\"github.com/googleapis/mcp-toolbox/internal/util/parameters\"\n)\n\nconst resourceType = \"serverless-spark-create-spark-batch\"\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\tbaseCfg, err := createbatch.NewConfig(ctx, name, decoder)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn Config{Config: baseCfg}, nil\n}\n\ntype Config struct {\n\tcreatebatch.Config\n\n\tScopesRequired []string `yaml:\"scopesRequired\"`\n}\n\n// validate interface","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/serverlessspark/serverlesssparkcreatesparkbatch/serverlesssparkcreatesparkbatch.go#L14-L50","documentation":"This panic comes from the package-level init() of the serverlesssparkcreatesparkbatch tool. MCP Toolbox keeps a global registry of tool types keyed by a resource type string; tools.Register returns false if the key already exists, and the package deliberately panics to signal a duplicate registration. It is a programming/registration error, not a runtime failure users can trigger.","triggerScenarios":"Two Go packages register the same resourceType string \"serverless-spark-create-spark-batch\", or the same package is linked twice under different import paths (e.g. vendored copy plus module copy), causing init() to run twice against the same registry.","commonSituations":"Copy-pasting a tool package and forgetting to change resourceType; accidentally importing a duplicated/forked copy of internal/tools; renaming a package but keeping the old const, colliding with the original that is still imported.","solutions":["Search the codebase for the duplicate resourceType string and change it so each tool registers a unique constant","Check go.mod / vendor/ for a duplicated import path of the same tools package and remove one copy","If a renamed package should replace an old one, remove the old package's init() registration or delete the old package","Rebuild with `go build -o toolbox` and run `go test ./internal/tools/...` to confirm the panic is gone"],"exampleFix":"// before\nconst resourceType = \"serverless-spark-create-spark-batch\" // duplicate in two packages\n// after\nconst resourceType = \"serverless-spark-create-spark-batch-v2\" // unique per registering package (or delete the duplicate package)","handlingStrategy":"validation","validationCode":"// before importing/registering, ensure uniqueness\ngrep -rn 'serverless-spark-create-spark-batch' internal/ tools/  # expect exactly one hit\n// or in Go: guard tests\ntools.Register(resourceType, newConfig) // write a test asserting each resourceType registers exactly once","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep resourceType constants unique per package and derive them from the tool's canonical name","Add a CI test that imports all tools packages and asserts no duplicate registrations","Avoid vendoring or forking packages under internal/tools","When renaming tools, delete the old package instead of leaving both registered"],"tags":["go","panic","duplicate-registration","init","startup"],"backgroundTag":"duplicate-registration-panic","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"}