googleapis/mcp-toolbox · error

invalid source for %q tool: source %q is not a compatible ty

Error message

invalid source for %q tool: source %q is not a compatible type

What it means

This error is thrown by Tool.ValidateSource when the source bound to the cloud-sql-create-users tool does not implement the tool's private compatibleSource interface (GetDefaultProject, UseClientAuthorization, CreateUsers). MCP Toolbox tools are generic over sources.Source, so at config-resolution time each tool type-asserts its source; a mismatch means the tool was wired to a source kind it cannot operate on (e.g. a plain Postgres source instead of a cloudsql admin source). It is a configuration/typing failure, not a runtime network or SQL failure.

Source

Thrown at internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers.go:100

}

// Tool represents the create-user tool.
type Tool struct {
	tools.BaseTool[Config]
}

func (t Tool) GetSourceName() string {
	return t.Cfg.Source
}

func (t Tool) ToConfig() tools.ToolConfig {
	return t.Cfg
}

func (t Tool) ValidateSource(source sources.Source) error {
	_, ok := source.(compatibleSource)
	if !ok {
		return fmt.Errorf("invalid source for %q tool: source %q is not a compatible type", t.Cfg.Type, t.Cfg.Source)
	}
	return nil
}

// Invoke executes the tool's logic.
func (t Tool) Invoke(ctx context.Context, s sources.Source, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
	source, ok := s.(compatibleSource)
	if !ok {
		return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, nil)
	}
	paramsMap := params.AsMap()

	project, ok := paramsMap["project"].(string)
	if !ok {
		return nil, util.NewAgentError("missing 'project' parameter", nil)
	}
	instance, ok := paramsMap["instance"].(string)
	if !ok {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check the tools.yaml: ensure the tool's source is a Cloud SQL Admin-compatible source (kind: cloud-sql-admin or equivalent that implements CreateUsers), not a database-connection source like postgres/mysql.
  2. If using a custom source, implement all methods of the tool's compatibleSource interface: GetDefaultProject() string, UseClientAuthorization() bool, and CreateUsers(context.Context, string, string, string, string, bool, string) (any, error).
  3. Upgrade the source package and tool package together so their interfaces match; the compatibleSource interface can change between versions.
  4. Before calling Invoke/GetParameters, call tool.ValidateSource(yourSource) explicitly to fail fast with this same message.
  5. Print the concrete type of the source (fmt.Printf("%T", src)) and compare it with the source kind the tool expects.

Example fix

// before (tools.yaml)
tools:
  create-users:
    kind: cloud-sql-create-users
    source: my-postgres-instance   # wrong source kind
// after
tools:
  create-users:
    kind: cloud-sql-create-users
    source: my-cloudsql-admin      # source implementing compatibleSource
Defensive patterns

Strategy: type-guard

Validate before calling

type compatibleSource interface {
	GetDefaultProject() string
	UseClientAuthorization() bool
	CreateUsers(context.Context, string, string, string, string, bool, string) (any, error)
}
if _, ok := src.(compatibleSource); !ok {
	return fmt.Errorf("source %T is not compatible with cloud-sql-create-users", src)
}

Type guard

func isCreateUsersSource(s sources.Source) bool {
	_, ok := s.(interface {
		GetDefaultProject() string
		UseClientAuthorization() bool
		CreateUsers(context.Context, string, string, string, string, bool, string) (any, error)
	})
	return ok
}

Try / catch

if err := tool.ValidateSource(src); err != nil {
	var typeErr *fmt.Errorf
	log.Fatalf("source/tool mismatch: %v — check tools.yaml source binding", err)
}

Prevention

When it happens

Trigger: Calling ValidateSource (via server toolset initialization or Invoke dispatch) with a sources.Source that fails the source.(compatibleSource) type assertion — e.g. a cloudsqlcreateusers Tool resolved against a postgres, mysql, or bigquery Source instead of a Cloud SQL Admin source whose type implements CreateUsers/GetDefaultProject/UseClientAuthorization.

Common situations: Developers hit this when their tools.yaml binds cloud-sql-create-users to the wrong source kind, when a custom/older source implementation does not implement the current compatibleSource interface (API surface changed across toolbox versions), or when programmatically constructing the tool and passing a source of the wrong concrete type.

Related errors


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