googleapis/mcp-toolbox · error

tool type %q already registered

Error message

tool type %q already registered

What it means

The package's init() registers the 'postgres-list-query-stats' tool type in the global registry and panics if tools.Register returns false, meaning the type string was already claimed. This is a duplicate-registration guard for programming errors (e.g. a vendored or duplicated package copy linked into the binary), not a user config issue.

Source

Thrown at internal/tools/postgres/postgreslistquerystats/postgreslistquerystats.go:54

          s.calls,
          s.total_exec_time,
          s.min_exec_time,
          s.max_exec_time,
          s.mean_exec_time,
          s.rows,
          s.shared_blks_hit,
          s.shared_blks_read
      FROM
          pg_stat_statements s
      JOIN pg_database d ON d.oid = s.dbid
      WHERE d.datname <> 'cloudsqladmin' AND ($1::text IS NULL OR d.datname LIKE '%' || $1::text || '%')
      ORDER BY total_exec_time DESC
      LIMIT COALESCE($2::int, 50);
`

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 {
	PostgresPool() *pgxpool.Pool
	RunSQL(context.Context, string, []any) (any, error)
}

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

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Ensure the package is not imported twice under different paths (e.g. vendored and module copies)
  2. Rename the conflicting resourceType constant if two distinct tools share it
  3. Clean go.mod/go.sum and rebuild to eliminate stale duplicate dependencies
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/tools/postgres/postgreslistquerystats/postgreslistquerystats.go:54 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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