{"record":{"id":"c339008309b6f370","repo":"googleapis/mcp-toolbox","slug":"error-building-req-for-endpoint-v-v-c33900","errorCode":null,"errorMessage":"error building req for endpoint [%v] : %v","messagePattern":"error building req for endpoint \\[(.+?)\\] : (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/dgraph/dgraph.go","lineNumber":299,"sourceCode":"\tcredentials := map[string]interface{}{\n\t\t\"refreshJWT\": hc.RefreshToken,\n\t\t\"namespace\":  hc.Namespace,\n\t}\n\treturn hc.doLogin(credentials)\n}\n\nfunc (hc *DgraphClient) doLogin(creds map[string]interface{}) error {\n\turl, err := getUrl(hc.baseUrl, \"/login\", nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\tpayload, err := json.Marshal(creds)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal credentials: %v\", err)\n\t}\n\treq, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payload))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error building req for endpoint [%v] : %v\", url, err)\n\t}\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\tif hc.apiKey != \"\" {\n\t\treq.Header.Set(\"Dg-Auth\", hc.apiKey)\n\t}\n\n\tresp, err := hc.doReq(req)\n\tif err != nil {\n\t\tif strings.Contains(err.Error(), \"Token is expired\") &&\n\t\t\t!strings.Contains(err.Error(), \"unable to authenticate the refresh token\") {\n\t\t\treturn hc.loginWithToken()\n\t\t}\n\t\treturn err\n\t}\n\n\tif err := checkError(resp); err != nil {\n\t\treturn err\n\t}","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/dgraph/dgraph.go#L281-L317","documentation":"doLogin returns this error when http.NewRequest fails to construct the POST request to the Dgraph /login endpoint. http.NewRequest validates the URL and method; the most common cause is an invalid hc.baseUrl (unparseable or unsupported scheme) combined via getUrl. The failing URL is embedded in the message via [%v] to aid diagnosis.","triggerScenarios":"hc.baseUrl is malformed (bad scheme, control characters, spaces) or nil/empty such that the joined login URL cannot be parsed by url.Parse, causing http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payload)) to error.","commonSituations":"Misconfigured source YAML where the dgraph source's baseURL is empty, misspelled (e.g. 'dgraph://host:port' instead of 'http://host:port'), or contains whitespace; env-substituted values left unresolved.","solutions":["Check the dgraph source config and set a valid absolute baseURL, e.g. http://localhost:8080 (http/https only, no trailing garbage).","Print or inspect the endpoint shown between [%v ...] in the message and paste it into a browser/curl to validate the URL syntax.","Ensure any environment-variable placeholders in the config resolve to non-empty values before the toolbox starts.","If the base URL comes from user input, validate it with url.ParseRequestURI at source initialization time."],"exampleFix":"// before (config)\nbaseURL: dgraph://localhost:8080\n// after (config)\nbaseURL: http://localhost:8080","handlingStrategy":"validation","validationCode":"u, err := url.ParseRequestURI(baseURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n  return fmt.Errorf(\"invalid dgraph baseURL: %q\", baseURL)\n}","typeGuard":"func isValidHTTPURL(s string) bool {\n  u, err := url.Parse(s)\n  return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"err := loginWithToken(ctx, token)\nif err != nil && strings.Contains(err.Error(), \"error building req for endpoint\") {\n  // extract URL between [%v] and fix baseURL in the source config\n  log.Fatalf(\"invalid dgraph endpoint: %v\", err)\n}","preventionTips":["Always use absolute http:// or https:// URLs for the dgraph baseURL in source config.","Validate the URL with url.ParseRequestURI at source initialization, not at request time.","Resolve environment-variable placeholders in config before startup and fail fast if empty.","Avoid trailing whitespace and stray characters in config values; trim before use."],"tags":["http","url","dgraph","request-building","configuration"],"backgroundTag":"invalid-url","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"}