Tencent/WeKnora · error

URL is required for SSE transport

Error message

URL is required for SSE transport

What it means

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.

Source

Thrown at internal/mcp/client.go:189

		headers[key] = value
	}
	applyAuthHeaders(headers, config.Service.AuthConfig)

	// Build OAuth config when this service uses the OAuth strategy. The
	// client_id comes from the dynamically-registered client persisted at
	// authorization time; the token store loads the invoking user's token
	// and transparently refreshes it.
	oauthConfig, useOAuth, err := buildOAuthConfig(config, httpClient)
	if err != nil {
		return nil, err
	}

	// Create client based on transport type
	var mcpClient *client.Client
	switch config.Service.TransportType {
	case types.MCPTransportSSE:
		if config.Service.URL == nil || *config.Service.URL == "" {
			return nil, fmt.Errorf("URL is required for SSE transport")
		}
		if useOAuth {
			mcpClient, err = client.NewOAuthSSEClient(*config.Service.URL, oauthConfig,
				transport.WithHTTPClient(httpClient),
				transport.WithHeaders(headers),
			)
		} else {
			mcpClient, err = client.NewSSEMCPClient(*config.Service.URL,
				client.WithHTTPClient(httpClient),
				client.WithHeaders(headers),
			)
		}
		if err != nil {
			return nil, fmt.Errorf("failed to create SSE client: %w", err)
		}
	case types.MCPTransportHTTPStreamable:
		if config.Service.URL == nil || *config.Service.URL == "" {
			return nil, fmt.Errorf("URL is required for HTTP Streamable transport")

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Set the Service.URL to the SSE endpoint (e.g. https://host/sse) before creating the client
  2. Fix the config/save path so SSE services always persist a URL
  3. Enforce URL presence in the UI/form when SSE transport is selected
  4. Validate at startup that every SSE-type service has a non-empty URL

Example fix

// before
svc := &types.MCPService{TransportType: types.MCPTransportSSE} // URL unset
client, err := NewMCPClient(&ClientConfig{Service: svc})
// after
svc := &types.MCPService{TransportType: types.MCPTransportSSE, URL: strPtr("https://mcp.example.com/sse")}
if svc.URL == nil || *svc.URL == "" { return errors.New("sse service requires a URL") }
client, err := NewMCPClient(&ClientConfig{Service: svc})
Defensive patterns

Strategy: validation

Validate before calling

func validateSSEService(svc *types.MCPService) error {
    if svc.TransportType == types.MCPTransportSSE && (svc.URL == nil || *svc.URL == "") {
        return errors.New("URL is required for SSE transport")
    }
    return nil
}

Type guard

func sseURLReady(svc *types.MCPService) bool {
    return svc != nil && svc.TransportType == types.MCPTransportSSE && svc.URL != nil && *svc.URL != ""
}

Try / catch

client, err := NewMCPClient(cfg)
if err != nil {
    if strings.Contains(err.Error(), "required for SSE") { return fmt.Errorf("service %s: %w", cfg.Service.ID, err) }
    return err
}

Prevention

When it happens

Trigger: Calling NewMCPClient with a Service whose TransportType == MCPTransportSSE but whose URL field is nil or the empty string.

Common situations: 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.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/52ac823831733e58. Report an issue: GitHub.