{"record":{"id":"a6e7afcdfabab3c6","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-google-tokeninfo-request-w","errorCode":null,"errorMessage":"failed to create Google tokeninfo request: %w","messagePattern":"failed to create Google tokeninfo request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/google/google.go","lineNumber":184,"sourceCode":"\t\t\tfor _, s := range tokenScopes {\n\t\t\t\tscopeMap[s] = true\n\t\t\t}\n\n\t\t\tfor _, requiredScope := range a.ScopesRequired {\n\t\t\t\tif !scopeMap[requiredScope] {\n\t\t\t\t\treturn nil, &auth.MCPAuthError{Code: http.StatusForbidden, Message: \"insufficient scopes\", ScopesRequired: a.ScopesRequired}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn payload.Claims, nil\n\t}\n\n\t// Validate opaque Google access token via tokeninfo\n\tdata := url.Values{}\n\tdata.Set(\"access_token\", tokenStr)\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", \"https://oauth2.googleapis.com/tokeninfo\", strings.NewReader(data.Encode()))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Google tokeninfo request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\n\tclient := a.client\n\tif client == nil {\n\t\tclient = http.DefaultClient\n\t}\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, &auth.MCPAuthError{Code: http.StatusInternalServerError, Message: fmt.Sprintf(\"failed to call Google tokeninfo: %v\", err), ScopesRequired: a.ScopesRequired}\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, &auth.MCPAuthError{Code: http.StatusUnauthorized, Message: fmt.Sprintf(\"Google token validation failed with status: %d\", resp.StatusCode), ScopesRequired: a.ScopesRequired}\n\t}\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/auth/google/google.go#L166-L202","documentation":"ValidateMCPAuth verifies opaque Google access tokens by POSTing to Google's tokeninfo endpoint. This error wraps a failure to construct that outbound http.Request (http.NewRequestWithContext), which is almost always a malformed URL or an invalid context.","triggerScenarios":"http.NewRequestWithContext returns error before the request is sent — practically only if the hardcoded URL 'https://oauth2.googleapis.com/tokeninfo' is invalid or the request body reader fails; rare, typically indicates a code-level bug or exotic ctx misuse.","commonSituations":"Very rare in practice; could surface in tests that replace the endpoint constant, or in restricted environments instrumenting http.NewRequest.","solutions":["Inspect the wrapped inner error for the exact cause","Confirm the tokeninfo endpoint URL constant has not been overridden/altered","Retry after upgrading the library; a stock build should never hit this"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"claims, err := svc.ValidateMCPAuth(ctx, h)\nif err != nil && strings.Contains(err.Error(), \"failed to create Google tokeninfo request\") {\n    return fmt.Errorf(\"google auth request construction failed: %w\", err) // non-retryable; escalate\n}","preventionTips":["This is nearly always a code-level bug; report/upgrade rather than retry blindly","Keep the stock library build; do not override endpoint URL constants","Wrap calls and log the wrapped cause (%w) for diagnosis"],"tags":["go","auth","google","http-request","network"],"backgroundTag":"http-request-build-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"}