Tencent/WeKnora · error
MCP client config and service are required
Error message
MCP client config and service are required
What it means
NewMCPClient validates its input before doing any work: a nil config or a config whose Service field is nil cannot describe a transport, so construction fails immediately with this sentinel-style error. It is a pure programming/config error, not a runtime failure.
Source
Thrown at internal/mcp/client.go:152
// signal that carries RFC 9728 protected-resource metadata. It returns a
// non-nil *OAuthRequiredError ONLY when the server advertised a metadata URL —
// a bare 401 without metadata is treated as an ordinary auth failure (e.g. a
// wrong/missing API key) so we don't misdirect the user toward OAuth.
func asOAuthRequired(err error) *OAuthRequiredError {
if err == nil {
return nil
}
var authErr *transport.AuthorizationRequiredError
if errors.As(err, &authErr) && authErr.ResourceMetadataURL != "" {
return &OAuthRequiredError{MetadataURL: authErr.ResourceMetadataURL, Err: err}
}
return nil
}
// NewMCPClient creates a new MCP client based on the transport type
func NewMCPClient(config *ClientConfig) (MCPClient, error) {
if config == nil || config.Service == nil {
return nil, fmt.Errorf("MCP client config and service are required")
}
if err := ValidateServiceOutboundURLs(config.Service); err != nil {
return nil, err
}
// Create HTTP client with timeout
timeout := 30 * time.Second
if config.Service.AdvancedConfig != nil && config.Service.AdvancedConfig.Timeout > 0 {
timeout = time.Duration(config.Service.AdvancedConfig.Timeout) * time.Second
}
clientCfg := secutils.DefaultSSRFSafeHTTPClientConfig()
clientCfg.Timeout = timeout
httpClient := secutils.NewSSRFSafeHTTPClient(clientCfg)
// Build headers
headers := make(map[string]string)
for key, value := range config.Service.Headers {View on GitHub (pinned to 988cbb0330)
Solutions
- Ensure the ClientConfig is fully populated — especially the Service field — before calling NewMCPClient
- Fix config loading so MCP service definitions are parsed and attached
- Add a nil check with a clear log line at the call site to catch wiring bugs early
- Validate config at startup rather than at client creation time
Example fix
// before
client, err := NewMCPClient(cfg) // cfg.Service is nil
// after
if cfg == nil || cfg.Service == nil {
return fmt.Errorf("mcp service %q not configured", serviceID)
}
client, err := NewMCPClient(cfg) Defensive patterns
Strategy: validation
Validate before calling
func validateMCPConfig(cfg *ClientConfig) error {
if cfg == nil || cfg.Service == nil { return errors.New("MCP client config and service are required") }
return nil
} Type guard
func hasMCPService(cfg *ClientConfig) bool { return cfg != nil && cfg.Service != nil } Try / catch
client, err := NewMCPClient(cfg)
if err != nil {
if strings.Contains(err.Error(), "required") { return fmt.Errorf("mcp service misconfigured: %w", err) }
return err
} Prevention
- Validate full config at application startup, not lazily at client creation
- Use constructors/builder functions that cannot produce a Service-less config
- Log the service ID at call sites so nil configs are traceable
- Add unit tests covering nil and zero-value config paths
When it happens
Trigger: Calling NewMCPClient(nil), or with &ClientConfig{} where Service was never set; GetOrCreateClient passing through an unresolved service record.
Common situations: Config loading skipped or partially failed so the service entry is missing; a map lookup returning a zero-value struct; wiring bugs where the service pointer is dropped between layers.
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
- URL is required for SSE transport
- URL is required for HTTP Streamable transport
- MCP service is required
- invalid sandbox type
- timeout cannot be negative
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/5c175de0781d4cb0.
Report an issue: GitHub.