googleapis/mcp-toolbox · critical

tool type %q already registered

Error message

tool type %q already registered

What it means

This panic originates in init() of internal/tools/dataplex/dataplexcreatedataasset because tools.Register("dataplex-create-data-asset", newConfig) returned false, meaning the registry already holds that tool type key. The library fails fast at startup to prevent one tool definition from silently overwriting another. Resolution requires a unique registration per tool type.

Source

Thrown at internal/tools/dataplex/dataplexcreatedataasset/dataplexcreatedataasset.go:33

package dataplexcreatedataasset

import (
	"context"
	"fmt"
	"net/http"

	yaml "github.com/goccy/go-yaml"
	"github.com/googleapis/mcp-toolbox/internal/sources"
	"github.com/googleapis/mcp-toolbox/internal/tools"
	"github.com/googleapis/mcp-toolbox/internal/util"
	"github.com/googleapis/mcp-toolbox/internal/util/parameters"
)

const resourceType string = "dataplex-create-data-asset"

func init() {
	if !tools.Register(resourceType, newConfig) {
		panic(fmt.Sprintf("tool type %q already registered", resourceType))
	}
}

func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.ToolConfig, error) {
	actual := Config{ConfigBase: tools.ConfigBase{Name: name}}
	if err := decoder.DecodeContext(ctx, &actual); err != nil {
		return nil, err
	}
	return actual, nil
}

type compatibleSource interface {
	CreateDataAsset(
		ctx context.Context,
		locationID string,
		dataProductID string,
		dataAssetID string,
		resourceURI string,

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Search the codebase for "dataplex-create-data-asset" and eliminate the duplicate const.
  2. Give each tool package a unique resourceType per naming convention.
  3. Deduplicate linked module copies so init runs once per package path.
  4. Remove manual re-registration calls in tests.

Example fix

// before
const resourceType string = "dataplex-create-data-asset" // duplicate in another file
// after
const resourceType string = "dataplex-create-data-asset" // single source of truth; duplicate deleted
Defensive patterns

Strategy: validation

Validate before calling

const want = "dataplex-create-data-asset"
// uniqueness check before merge:
//   git grep -n 'dataplex-create-data-asset' -- '*.go'
// expect a single const resourceType declaration.

Try / catch

defer func() {
    if r := recover(); r != nil {
        if strings.Contains(fmt.Sprint(r), "already registered") {
            log.Fatalf("duplicate dataplex tool type: %v", r)
        }
        panic(r)
    }
}()

Prevention

When it happens

Trigger: Another declaration of the const "dataplex-create-data-asset" exists and its init() registers it too; or code (e.g., tests) calls tools.Register again for the same key after package initialization.

Common situations: Copy-paste of a sibling dataplex tool without renaming the const; merges bringing duplicate registrations; duplicate module/vendor copies; manual registration in test setup.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/bffb55980d817bb2. Report an issue: GitHub.