{"record":{"id":"a4e5df6934f5b9fe","repo":"googleapis/mcp-toolbox","slug":"params-must-be-a-valid-json-string-w","errorCode":null,"errorMessage":"params must be a valid JSON string: %w","messagePattern":"params must be a valid JSON string: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/invoke/command.go","lineNumber":111,"sourceCode":"\t\t\treturn errMsg\n\t\t}\n\t}\n\n\terr = tool.ValidateSource(src)\n\tif err != nil {\n\t\topts.Logger.ErrorContext(ctx, err.Error())\n\t\treturn err\n\t}\n\n\tvar paramsInput string\n\tif len(args) > 1 {\n\t\tparamsInput = args[1]\n\t}\n\n\tparams := make(map[string]any)\n\tif paramsInput != \"\" {\n\t\tif err := util.DecodeJSON(strings.NewReader(paramsInput), &params); err != nil {\n\t\t\terrMsg := fmt.Errorf(\"params must be a valid JSON string: %w\", err)\n\t\t\topts.Logger.ErrorContext(ctx, errMsg.Error())\n\t\t\treturn errMsg\n\t\t}\n\t}\n\n\ttoolParams, err := tool.GetParameters(src)\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"error getting parameters for tool: %w\", err)\n\t\topts.Logger.ErrorContext(ctx, errMsg.Error())\n\t\treturn errMsg\n\t}\n\n\tparsedParams, err := parameters.ParseParams(toolParams, params, nil)\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"invalid parameters: %w\", err)\n\t\topts.Logger.ErrorContext(ctx, errMsg.Error())\n\t\treturn errMsg\n\t}","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/cmd/internal/invoke/command.go#L93-L129","documentation":"Thrown by runInvoke (cmd/internal/invoke/command.go:111) when the optional second CLI argument (the tool params string) is non-empty but fails util.DecodeJSON into map[string]any. The invoke command requires params to be a single, well-formed JSON object literal so they can be matched against the tool's parameter schema. This is a user-input validation error, not a library fault.","triggerScenarios":"Running `toolbox invoke <tool> '<params>'` where the second arg is malformed JSON: unquoted shell-expanded braces, single quotes inside JSON, trailing commas, unquoted keys, non-object JSON like a bare string, or shell mangling of double quotes.","commonSituations":"Quoting mistakes on the command line (shell strips or splits the JSON), copy-pasting params with smart quotes, forgetting to single-quote the JSON so the shell word-splits it, or passing a JSON array instead of an object.","solutions":["Wrap the params argument in single quotes so the shell does not alter it: toolbox invoke my-tool '{\"name\": \"value\"}'.","Validate the JSON with `echo '<params>' | jq .` before invoking to see the exact syntax error.","Pass an empty string or omit the argument entirely if the tool takes no parameters.","Write complex params to a file and pass its contents: toolbox invoke my-tool \"$(cat params.json)\"."],"exampleFix":"// before (shell eats quotes -> invalid JSON)\ntoolbox invoke execute_sql {\"sql\": \"SELECT 1\"}\n// after\ntoolbox invoke execute_sql '{\"sql\": \"SELECT 1\"}'","handlingStrategy":"validation","validationCode":"params='{\"sql\": \"SELECT 1\"}'\necho \"$params\" | jq -e type >/dev/null || { echo 'params is not valid JSON'; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := runInvoke(...); err != nil {\n  if strings.Contains(err.Error(), \"params must be a valid JSON string\") {\n    // re-prompt for params or show usage\n  }\n}","preventionTips":["Always single-quote the JSON params argument in shell invocations.","Lint params with jq before passing them to `toolbox invoke`.","Store complex params in files and interpolate with $(cat params.json)."],"tags":["cli","json","input-validation"],"backgroundTag":"invalid-json-arguments","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"}