{"record":{"id":"913aed3954b7832a","repo":"googleapis/mcp-toolbox","slug":"tool-execution-failed-w","errorCode":null,"errorMessage":"tool execution failed: %w","messagePattern":"tool execution failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/invoke/command.go","lineNumber":153,"sourceCode":"\t\treturn errMsg\n\t}\n\n\t// Client Auth not supported for ephemeral CLI call\n\trequiresAuth, err := tool.RequiresClientAuthorization(src)\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"failed to check auth requirements: %w\", err)\n\t\topts.Logger.ErrorContext(ctx, errMsg.Error())\n\t\treturn errMsg\n\t}\n\tif requiresAuth {\n\t\terrMsg := fmt.Errorf(\"client authorization is not supported\")\n\t\topts.Logger.ErrorContext(ctx, errMsg.Error())\n\t\treturn errMsg\n\t}\n\n\tresult, err := tool.Invoke(ctx, src, parsedParams, \"\")\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"tool execution failed: %w\", err)\n\t\topts.Logger.ErrorContext(ctx, errMsg.Error())\n\t\treturn errMsg\n\t}\n\n\t// Print Result\n\toutput, err := json.MarshalIndent(result, \"\", \"  \")\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"failed to marshal result: %w\", err)\n\t\topts.Logger.ErrorContext(ctx, errMsg.Error())\n\t\treturn errMsg\n\t}\n\tfmt.Fprintln(opts.IOStreams.Out, string(output))\n\n\treturn nil\n}\n","sourceCodeStart":135,"sourceCodeEnd":169,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/cmd/internal/invoke/command.go#L135-L169","documentation":"Wraps any error returned by tool.Invoke during a direct `toolbox invoke` CLI run. The tool's database/backend call itself failed (bad SQL, connection failure, permission denial, etc.) and the CLI surfaces the underlying cause via %w (cmd/internal/invoke/command.go:151-156).","triggerScenarios":"`toolbox invoke <tool> '{...}'` where the tool executes but its backend operation errors: invalid SQL statement, unreachable database source, failed connection pool, insufficient DB permissions, or a parameter the backend rejects.","commonSituations":"Database host/port wrong in the source config so the pool cannot connect; SQL syntax error in the tool's statement; IAM/service-account lacking access to the table; API-based tools (e.g. HTTP sources) returning non-2xx responses.","solutions":["Read the wrapped cause after 'tool execution failed:' — it carries the actual backend error and fix that first.","Verify the tool's source (database) is reachable: check host, port, credentials, and network/VPC from the machine running the CLI.","Run `toolbox invoke` again with corrected parameters to rule out param-driven query errors.","Test the tool's statement directly against the database (psql/mysql console) to isolate SQL problems.","Update credentials/permissions (DB user grants, service-account roles) if the cause is access-denied."],"exampleFix":"// before\n$ toolbox tools invoke search-items '{\"id\": \"x\"}'\n// error: tool execution failed: failed to connect to `host=10.0.0.5 user=admin database=app`\n// after: fix the source config then retry\nsources:\n  my-pg-instance:\n    kind: postgres\n    host: 127.0.0.1\n    port: 5432\n    dbName: app\n    user: admin","handlingStrategy":"try-catch","validationCode":"// Pre-check DB connectivity before invoking:\nconn, err := sql.Open(\"pgx\", dsn)\nif err != nil { log.Fatal(err) }\nif err := conn.PingContext(ctx); err != nil { log.Fatalf(\"source unreachable: %v\", err) }","typeGuard":null,"tryCatchPattern":"// CLI returns exit code 1; capture stderr and inspect the wrapped cause:\nout, err := exec.Command(\"toolbox\", \"invoke\", \"my-tool\", paramsJSON).CombinedOutput()\nif err != nil {\n    var cause string\n    if i := strings.Index(string(out), \"tool execution failed:\"); i >= 0 {\n        cause = strings.TrimSpace(string(out)[i+len(\"tool execution failed:\"):])\n    }\n    fmt.Fprintf(os.Stderr, \"invoke failed: %v (cause: %s)\\n\", err, cause)\n    os.Exit(1)\n}","preventionTips":["Validate the source's connection settings (host/port/creds) before running tools.","Test tool SQL statements directly in the database client first.","Keep DB credentials/grants current; rotate before expiry.","Check the innermost wrapped message — Invoke errors are chained with %w."],"tags":["cli","database","tool-execution"],"backgroundTag":"tool-execution-failed","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"}