{"record":{"id":"35c2957a4fcf42a3","repo":"googleapis/mcp-toolbox","slug":"invalid-source-for-q-tool-source-q-is-not-a-com-35c295","errorCode":null,"errorMessage":"invalid source for %q tool: source %q is not a compatible type","messagePattern":"invalid source for %q tool: source %q is not a compatible type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/cloudmonitoring/cloudmonitoring.go","lineNumber":103,"sourceCode":"// validate interface\nvar _ tools.Tool = Tool{}\n\ntype Tool struct {\n\ttools.BaseTool[Config]\n}\n\nfunc (t Tool) GetSourceName() string {\n\treturn t.Cfg.Source\n}\n\nfunc (t Tool) ToConfig() tools.ToolConfig {\n\treturn t.Cfg\n}\n\nfunc (t Tool) ValidateSource(source sources.Source) error {\n\t_, ok := source.(compatibleSource)\n\tif !ok {\n\t\treturn fmt.Errorf(\"invalid source for %q tool: source %q is not a compatible type\", t.Cfg.Type, t.Cfg.Source)\n\t}\n\treturn nil\n}\n\nfunc (t Tool) Invoke(ctx context.Context, s sources.Source, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {\n\tsource, ok := s.(compatibleSource)\n\tif !ok {\n\t\treturn nil, util.NewClientServerError(\"source used is not compatible with the tool\", http.StatusInternalServerError, nil)\n\t}\n\tparamsMap := params.AsMap()\n\tprojectID, ok := paramsMap[\"projectId\"].(string)\n\tif !ok {\n\t\treturn nil, util.NewAgentError(\"projectId parameter not found or not a string\", nil)\n\t}\n\tquery, ok := paramsMap[\"query\"].(string)\n\tif !ok {\n\t\treturn nil, util.NewAgentError(\"query parameter not found or not a string\", nil)\n\t}","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/cloudmonitoring/cloudmonitoring.go#L85-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Bind the tool to a cloud-monitoring kind source.","Validate the tools.yaml at startup so the mismatch fails fast.","If wrapping sources, implement compatibleSource (including any UseClientAuthorization method) on the wrapper.","Cross-check that the source name in the tool matches the intended entry under `sources:`."],"exampleFix":"// before\n  execute-promql:\n    kind: cloud-monitoring-execute-promql\n    source: logging-prod\n// after\n  execute-promql:\n    kind: cloud-monitoring-execute-promql\n    source: monitoring-prod","handlingStrategy":"type-guard","validationCode":"// Go: check source compatibility before Invoke\nif _, ok := src.(compatibleSource); !ok {\n    return fmt.Errorf(\"promql tool requires a cloud-monitoring source, got %T\", src)\n}","typeGuard":"func toMonitoringSource(s sources.Source) (compatibleSource, bool) {\n    cs, ok := s.(compatibleSource)\n    return cs, ok\n}","tryCatchPattern":"result, tbErr := tool.Invoke(ctx, src, params, token)\nif tbErr != nil {\n    return fmt.Errorf(\"invoke failed: %v\", tbErr)\n}","preventionTips":["Bind promql tools only to cloud-monitoring sources.","Add startup validation of every tool/source pair.","Use unique, kind-indicating source names to avoid copy-paste misbindings."],"tags":["go","config","type-assertion","source-compatibility"],"backgroundTag":"incompatible-source-type","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}