googleapis/mcp-toolbox · critical

tool type %q already registered

Error message

tool type %q already registered

What it means

This panic is raised by init() in internal/tools/dataplex/dataplexcheckdataquality when tools.Register finds "dataplex-check-data-quality" already in the registry and returns false. The library panics at startup to guarantee one tool type maps to exactly one Config factory. The key must be unique for the process to boot.

Source

Thrown at internal/tools/dataplex/dataplexcheckdataquality/dataplexcheckdataquality.go:34

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

	"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/tools/dataplex/dataplexcommon"
	"github.com/googleapis/mcp-toolbox/internal/util"
	"github.com/googleapis/mcp-toolbox/internal/util/parameters"
)

const resourceType string = "dataplex-check-data-quality"

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 {
	ProjectID() string
	GenerateDataQuality(ctx context.Context, location, resourcePath string, specJSON string, publish bool) (string, error)
}

type Config struct {
	tools.ConfigBase `yaml:",inline"`

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Grep the repo for "dataplex-check-data-quality" and remove or rename the duplicate resourceType.
  2. Enforce unique kebab-case resourceType per tool package.
  3. Check for duplicate module copies (go.mod/vendor) causing double init.
  4. Restructure tests so they do not re-register init-registered tools.

Example fix

// before
const resourceType string = "dataplex-check-data-quality" // registered twice
// after
const resourceType string = "dataplex-check-data-quality" // keep single declaration; delete duplicate
Defensive patterns

Strategy: validation

Validate before calling

const want = "dataplex-check-data-quality"
// before building, verify uniqueness:
//   git grep -n '"dataplex-check-data-quality"' -- '*.go'
// more than one const hit guarantees a startup panic.

Try / catch

func init() {
    defer func() {
        if r := recover(); r != nil {
            log.Fatalf("dataplex tool registration failed: %v", r)
        }
    }()
    tools.Register(resourceType, newConfig)
}

Prevention

When it happens

Trigger: Duplicate resourceType const declared in another file/package whose init() also registers "dataplex-check-data-quality"; or explicit re-registration from test/bootstrap code after init.

Common situations: Copy-pasted dataplex tool with unchanged const; merge introducing two identical tool types; vendoring duplicate module copies; tests calling Register after package init already ran.

Related errors


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