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

ValidateSource in cloudhealthcaregetfhirstoremetrics returns this error when the provided sources.Source does not implement compatibleSource. The metrics tool can only query store metrics through the Cloud Healthcare source's API helpers, so foreign source types are rejected before invocation.

Source

Thrown at internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics.go:101

// validate interface
var _ tools.Tool = 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
}

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)
	}
	storeID, err := common.ValidateAndFetchStoreID(params, source.AllowedFHIRStores())
	if err != nil {
		return nil, util.NewAgentError("failed to validate store ID", err)
	}
	var tokenStr string
	if source.UseClientAuthorization() {
		tokenStr, err = accessToken.ParseBearerToken()
		if err != nil {
			return nil, util.NewClientServerError("error parsing access token", http.StatusUnauthorized, err)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Bind the tool to a cloudhealthcare-kind source.
  2. Verify source initialization completed and SourceType matches.
  3. Update mocks to implement the full compatibleSource interface.
  4. Grep config for the tool kind and confirm its source field points at the healthcare source.

Example fix

// before
  source: bq-source
// after
  source: healthcare-source
Defensive patterns

Strategy: type-guard

Validate before calling

if _, ok := src.(cloudhealthcare.Source); !ok {
    return errors.New("metrics tool requires a cloudhealthcare source")
}

Type guard

func isCompatible(s sources.Source) bool {
    _, ok := s.(interface {
        UseClientAuthorization() bool
        AllowedFHIRStores() []string
    })
    return ok
}

Try / catch

if err := tool.ValidateSource(src); err != nil {
    return fmt.Errorf("source incompatible with metrics tool: %w", err)
}

Prevention

When it happens

Trigger: Toolset wiring or Invoke-time validation passing a source of a different engine kind to this tool.

Common situations: Wrong source key in tools.yaml; post-refactor source types no longer matching the interface; test stubs missing interface methods after the interface gained AllowedFHIRStores/UseClientAuthorization.

Related errors


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