{"record":{"id":"cd70a1ff900a751d","repo":"micro/go-micro","slug":"reflect-grpc-target-s-w","errorCode":null,"errorMessage":"reflect grpc target %s: %w","messagePattern":"reflect grpc target (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gateway/mcp/grpcreflect.go","lineNumber":74,"sourceCode":"\tif timeout == 0 {\n\t\ttimeout = 10 * time.Second\n\t}\n\tctx, cancel := context.WithTimeout(s.opts.Context, timeout)\n\tdefer cancel()\n\n\tdialOpts := target.DialOptions\n\tif len(dialOpts) == 0 {\n\t\tdialOpts = []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}\n\t}\n\tconn, err := grpc.NewClient(target.Address, dialOpts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"connect reflected grpc target %s: %w\", target.Address, err)\n\t}\n\tdefer conn.Close()\n\n\tfiles, services, err := loadReflectedFiles(ctx, conn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reflect grpc target %s: %w\", target.Address, err)\n\t}\n\n\tprefix := target.Name\n\tif prefix == \"\" {\n\t\tprefix = sanitizeToolPart(target.Address)\n\t}\n\n\tvar out []*Tool\n\tfor _, serviceName := range services {\n\t\tdesc, err := files.FindDescriptorByName(protoreflect.FullName(serviceName))\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tsvc, ok := desc.(protoreflect.ServiceDescriptor)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\t\tfor i := 0; i < svc.Methods().Len(); i++ {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/gateway/mcp/grpcreflect.go#L56-L92","documentation":"After connecting, reflectedGRPCTools calls loadReflectedFiles to perform gRPC server reflection (list services + fetch file descriptors). Any failure inside reflection is wrapped with the target address in this error. The connection itself succeeded; the reflection RPC exchange failed.","triggerScenarios":"grpc.NewClient succeeds but loadReflectedFiles fails: the server does not implement gRPC reflection, reflection RPCs time out, or the reflection stream returns an error.","commonSituations":"Target server was started without grpc reflection (reflection.Register(server) missing or grpcui not enabled); a proxy/firewall blocking the reflection service; server shutting down mid-reflection.","solutions":["Enable reflection on the target server: reflection.Register(server) after NewServer, or run with a reflection-enabled option.","Verify the wrapped (%w) inner error to distinguish NotFound (no reflection service) from timeouts/cancellations.","Check network reachability and that ctx is not cancelled before loadReflectedFiles completes.","If the server cannot enable reflection, provide descriptor files instead of relying on reflection discovery."],"exampleFix":"// before\nserver := grpc.NewServer()\nserver.Serve(lis) // no reflection\n// after\nserver := grpc.NewServer()\nreflection.Register(server)\nserver.Serve(lis)","handlingStrategy":"fallback","validationCode":"// probe reflection support before full discovery\nconn, _ := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))\nclient := grpcreflection.NewReflectionClientAuto(conn)\nctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)\ndefer cancel()\nif _, err := client.ListServices(ctx, &refpb.ListServicesRequest{}); err != nil {\n    return fmt.Errorf(\"target %s lacks reflection: %w\", addr, err)\n}","typeGuard":null,"tryCatchPattern":"tools, err := reflectedGRPCTools(ctx, target)\nif err != nil && strings.Contains(err.Error(), \"reflect grpc target\") {\n    tools = loadToolsFromStaticDescriptors(target) // fallback path\n}","preventionTips":["Enable reflection.Register(server) on every gRPC server you discover from.","Smoke-test reflection with grpcurl before wiring discovery.","Provide static descriptor sets as a fallback for servers without reflection.","Ensure the context has enough deadline for list + file-descriptor round trips."],"tags":["grpc","reflection","discovery","rpc-error"],"backgroundTag":"grpc-reflection-unavailable","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}