Skip to content

[Go] mcp.NewGenkitMCPClient does not return initialization errors, causing silent failures #4299

@bailinhe

Description

@bailinhe

Describe the bug

The error returned from initializeClient in the MCP client is never surfaced to the user. When mcp.NewGenkitMCPClient is called with a misconfigured BaseURL (or other configuration issues), it does not return an error. The client initialization silently fails, and users only discover something is wrong when making follow-up requests, at which point they receive a generic error message:

"error": "failed to list tools: client not initialized"

This error message provides no context about the root cause (e.g., incorrect BaseURL, connection refused, timeout, etc.), making it extremely difficult to debug configuration issues.

To Reproduce

Steps to reproduce the behavior:

  1. Configure an MCP client with an incorrect or unreachable BaseURL:
client, err := mcp.NewGenkitMCPClient(
    mcp.MCPClientOptions{
        Name:    "my-mcp",
        Version: "v1alpha1",
        StreamableHTTP: &mcp.StreamableHTTPConfig{
            BaseURL: "http://localhost:3000/v1alpha1", // Wrong port or service not running
        },
    },
)
if err != nil {
    // This block never executes (in this case) - err is nil
    l.logger.Fatal("failed to create mcp client", zap.Error(err))
}

// Client appears to be created successfully
tools, err := client.GetActiveTools(context.Background(), g)
if err != nil {
    // Only here do we see: "failed to list tools: client not initialized"
    l.logger.Fatal("failed to get active tools", zap.Error(err))
}
  1. Run the application
  2. The application appears to start successfully
  3. When attempting to use MCP tools, receive the generic "client not initialized" error with no information about why initialization failed

Expected behavior

mcp.NewGenkitMCPClient should either:

  • Return an error immediately if the client cannot be initialized (e.g., connection validation fails), OR
  • The subsequent GetActiveTools call should return a more descriptive error that includes the underlying initialization error (e.g., "failed to list tools: connection refused at http://localhost:3000/v1alpha1", "failed to list tools: invalid BaseURL", etc.)

The root cause of the initialization failure should be accessible to users for debugging purposes.

Screenshots

N/A

Runtime (please complete the following information):

  • OS: macOS
  • Version: 26.2

Go version

go version go1.25.6 darwin/arm64

Additional context

The root cause can be seen in the source code: https://github.com/firebase/genkit/blob/main/go/plugins/mcp/client.go#L135-L146

The error from initializeClient is never returned to the caller, making it impossible for users to detect configuration issues at client creation time.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggo

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions