{"record":{"id":"1b5f272fab4d6ecf","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-introspection-request-w","errorCode":null,"errorMessage":"failed to create introspection request: %w","messagePattern":"failed to create introspection request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/generic/generic.go","lineNumber":373,"sourceCode":"\t}\n\n\tparamName := a.IntrospectionParamName\n\tif paramName == \"\" {\n\t\tparamName = \"token\"\n\t}\n\n\tvar req *http.Request\n\tif a.IntrospectionMethod == \"GET\" {\n\t\tu, err := url.Parse(introspectionURL)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse introspection URL: %w\", err)\n\t\t}\n\t\tq := u.Query()\n\t\tq.Set(paramName, tokenStr)\n\t\tu.RawQuery = q.Encode()\n\t\treq, err = http.NewRequestWithContext(ctx, \"GET\", u.String(), nil)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create introspection request: %w\", err)\n\t\t}\n\t} else {\n\t\tdata := url.Values{}\n\t\tdata.Set(paramName, tokenStr)\n\t\treq, err = http.NewRequestWithContext(ctx, \"POST\", introspectionURL, strings.NewReader(data.Encode()))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create introspection request: %w\", err)\n\t\t}\n\t\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\t}\n\treq.Header.Set(\"Accept\", \"application/json\")\n\n\t// Send request to auth server's introspection endpoint\n\tresp, err := a.client.Do(req)\n\tif err != nil {\n\t\tlogger.ErrorContext(ctx, \"failed to call introspection endpoint: %v\", err)\n\t\treturn nil, &MCPAuthError{Code: http.StatusInternalServerError, Message: fmt.Sprintf(\"failed to call introspection endpoint: %v\", err), ScopesRequired: a.ScopesRequired}\n\t}","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/auth/generic/generic.go#L355-L391","documentation":"After building the GET request URL, the library creates the outgoing HTTP request with http.NewRequestWithContext. If request construction fails (invalid method/URL combination or a malformed url.URL string), the error is wrapped with this message. This is the GET branch of opaque-token introspection.","triggerScenarios":"IntrospectionMethod is \"GET\", the parsed URL stringified via u.String() is somehow invalid, or ctx is already cancelled making NewRequestWithContext fail at this layer; err from http.NewRequestWithContext is wrapped here.","commonSituations":"Extremely rare in practice; usually caused by a corrupted URL after query encoding or an invalid method constant due to custom configuration subclassing.","solutions":["Verify the final introspection URL is valid by decoding it manually or with a curl GET request.","Check that IntrospectionMethod is exactly \"GET\" (case-sensitive) so the intended branch runs.","Ensure the context passed to the auth service is not pre-cancelled."],"exampleFix":"// before\nintrospectionMethod: \"get\"  # falls into POST branch or mishandled\n// after\nintrospectionMethod: \"GET\"","handlingStrategy":"validation","validationCode":"if cfg.IntrospectionMethod != \"\" && cfg.IntrospectionMethod != \"GET\" && cfg.IntrospectionMethod != \"POST\" {\n    return fmt.Errorf(\"introspectionMethod must be GET or POST, got %q\", cfg.IntrospectionMethod)\n}","typeGuard":"func isSupportedIntrospectionMethod(m string) bool {\n    return m == \"\" || m == \"GET\" || m == \"POST\"\n}","tryCatchPattern":"claims, err := svc.ValidateMCPAuth(ctx, header)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to create introspection request\") {\n        // verify ctx not cancelled and URL valid, then retry once\n        if ctx.Err() == nil { claims, err = svc.ValidateMCPAuth(ctx, header) }\n    }\n    return claims, err\n}","preventionTips":["Use the exact uppercase method strings GET/POST in config","Check IdP docs for whether introspection expects GET query params or POST form body","Ensure request contexts are alive when auth validation runs"],"tags":["http","oauth","introspection"],"backgroundTag":"http-request-construction-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"}