{"record":{"id":"52ac823831733e58","repo":"Tencent/WeKnora","slug":"url-is-required-for-sse-transport","errorCode":null,"errorMessage":"URL is required for SSE transport","messagePattern":"URL is required for SSE transport","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/mcp/client.go","lineNumber":189,"sourceCode":"\t\theaders[key] = value\n\t}\n\tapplyAuthHeaders(headers, config.Service.AuthConfig)\n\n\t// Build OAuth config when this service uses the OAuth strategy. The\n\t// client_id comes from the dynamically-registered client persisted at\n\t// authorization time; the token store loads the invoking user's token\n\t// and transparently refreshes it.\n\toauthConfig, useOAuth, err := buildOAuthConfig(config, httpClient)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Create client based on transport type\n\tvar mcpClient *client.Client\n\tswitch config.Service.TransportType {\n\tcase types.MCPTransportSSE:\n\t\tif config.Service.URL == nil || *config.Service.URL == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"URL is required for SSE transport\")\n\t\t}\n\t\tif useOAuth {\n\t\t\tmcpClient, err = client.NewOAuthSSEClient(*config.Service.URL, oauthConfig,\n\t\t\t\ttransport.WithHTTPClient(httpClient),\n\t\t\t\ttransport.WithHeaders(headers),\n\t\t\t)\n\t\t} else {\n\t\t\tmcpClient, err = client.NewSSEMCPClient(*config.Service.URL,\n\t\t\t\tclient.WithHTTPClient(httpClient),\n\t\t\t\tclient.WithHeaders(headers),\n\t\t\t)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create SSE client: %w\", err)\n\t\t}\n\tcase types.MCPTransportHTTPStreamable:\n\t\tif config.Service.URL == nil || *config.Service.URL == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"URL is required for HTTP Streamable transport\")","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/mcp/client.go#L171-L207","documentation":"NewMCPClient requires a URL when the service's transport type is SSE; a nil or empty URL cannot establish the SSE connection, so construction fails with this error. It is checked before any connection attempt, right after the outbound-URL safety validation.","triggerScenarios":"Calling NewMCPClient with a Service whose TransportType == MCPTransportSSE but whose URL field is nil or the empty string.","commonSituations":"A service record saved without a URL; migration/import leaving URL unset for SSE-type services; UI allowing transport type selection without enforcing a URL field; config file with transport: sse but missing url key.","solutions":["Set the Service.URL to the SSE endpoint (e.g. https://host/sse) before creating the client","Fix the config/save path so SSE services always persist a URL","Enforce URL presence in the UI/form when SSE transport is selected","Validate at startup that every SSE-type service has a non-empty URL"],"exampleFix":"// before\nsvc := &types.MCPService{TransportType: types.MCPTransportSSE} // URL unset\nclient, err := NewMCPClient(&ClientConfig{Service: svc})\n// after\nsvc := &types.MCPService{TransportType: types.MCPTransportSSE, URL: strPtr(\"https://mcp.example.com/sse\")}\nif svc.URL == nil || *svc.URL == \"\" { return errors.New(\"sse service requires a URL\") }\nclient, err := NewMCPClient(&ClientConfig{Service: svc})","handlingStrategy":"validation","validationCode":"func validateSSEService(svc *types.MCPService) error {\n    if svc.TransportType == types.MCPTransportSSE && (svc.URL == nil || *svc.URL == \"\") {\n        return errors.New(\"URL is required for SSE transport\")\n    }\n    return nil\n}","typeGuard":"func sseURLReady(svc *types.MCPService) bool {\n    return svc != nil && svc.TransportType == types.MCPTransportSSE && svc.URL != nil && *svc.URL != \"\"\n}","tryCatchPattern":"client, err := NewMCPClient(cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"required for SSE\") { return fmt.Errorf(\"service %s: %w\", cfg.Service.ID, err) }\n    return err\n}","preventionTips":["Enforce URL presence in config forms whenever SSE transport is chosen","Run a startup sweep validating every SSE service has a URL","Use pointer-safe helpers when reading *string URL fields","Cover missing-URL cases in config-parsing tests"],"tags":["configuration","sse","mcp","validation"],"backgroundTag":"missing-required-config","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}