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 for the cloudmonitoring tool asserts the source implements compatibleSource (a Cloud Monitoring source). If the bound source is any other type, the assertion fails and this error is returned. Invoke performs the same check independently, so both paths can surface it.

Source

Thrown at internal/tools/cloudmonitoring/cloudmonitoring.go:103

// 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)
	}
	paramsMap := params.AsMap()
	projectID, ok := paramsMap["projectId"].(string)
	if !ok {
		return nil, util.NewAgentError("projectId parameter not found or not a string", nil)
	}
	query, ok := paramsMap["query"].(string)
	if !ok {
		return nil, util.NewAgentError("query parameter not found or not a string", nil)
	}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Bind the tool to a cloud-monitoring kind source.
  2. Validate the tools.yaml at startup so the mismatch fails fast.
  3. If wrapping sources, implement compatibleSource (including any UseClientAuthorization method) on the wrapper.
  4. Cross-check that the source name in the tool matches the intended entry under `sources:`.

Example fix

// before
  execute-promql:
    kind: cloud-monitoring-execute-promql
    source: logging-prod
// after
  execute-promql:
    kind: cloud-monitoring-execute-promql
    source: monitoring-prod
Defensive patterns

Strategy: type-guard

Validate before calling

// Go: check source compatibility before Invoke
if _, ok := src.(compatibleSource); !ok {
    return fmt.Errorf("promql tool requires a cloud-monitoring source, got %T", src)
}

Type guard

func toMonitoringSource(s sources.Source) (compatibleSource, bool) {
    cs, ok := s.(compatibleSource)
    return cs, ok
}

Try / catch

result, tbErr := tool.Invoke(ctx, src, params, token)
if tbErr != nil {
    return fmt.Errorf("invoke failed: %v", tbErr)
}

Prevention

When it happens

Trigger: Tool registration/validation or Invoke called with a source that is not a Cloud Monitoring source — e.g. binding the promql tool to a database or logging source in tools.yaml.

Common situations: Wrong `source:` mapping in tools.yaml; reusing one tool definition across environments where the source name means a different kind; custom sources not implementing compatibleSource.

Related errors


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