Skip to content

[BUG] Default MCP server connection timeout (5s) is too low for sidecar gateway deployments, causing intermittent "Failed to create MCP session" errors #1272

Closed

Description

@skhedim

📋 Prerequisites

  • I have searched the existing issues to avoid creating a duplicate
  • By submitting this issue, you agree to follow our Code of Conduct
  • I am using the latest version of the software
  • I have tried to clear cache/cookies or used incognito mode (if ui-related)
  • I can consistently reproduce this issue

🎯 Affected Service(s)

Controller Service

🚦 Impact/Severity

Blocker

🐛 Bug Description

When an agent references MCP tools via MCPServer CRDs, the agent pod intermittently fails with:

Failed to create MCP session: Failed to connect to MCP server at http://localhost:8081/mcp: [Errno 111] Connection refused

or times out silently, causing the entire tool call to fail.

Root cause: The Python ADK's StreamableHTTPConnectionParams has a hardcoded default timeout: float = 5.0 (see mcp_session_manager.py). When users deploy a MCPServer CRD, the kagent controller automatically generates a corresponding RemoteMCPServer resource. However:

  1. The MCPServer CRD does not expose a timeout field for users to configure
  2. The auto-generated RemoteMCPServer therefore has spec.timeout: nil
  3. The controller does not populate a default timeout in the agent's config.json
  4. The Python ADK falls back to its own 5-second default

Why 5 seconds is insufficient: MCP servers deployed via the MCPServer CRD use a sidecar agentgateway container that spawns a new stdio process (e.g. via uvx or npx) for each MCP session. Process startup time depends heavily on:

  • Package cache state: Cold starts (first invocation, new pod, or cache miss) require downloading/installing the MCP server package via uvx or npx. Even well-known MCP servers like awslabs.eks-mcp-server can take 2–8 seconds on cold starts.
  • Sequential initialization: When an agent references multiple MCPServer tools, each tool's sidecar spawns its own stdio process. These initializations happen sequentially during tool discovery (list_tools), compounding startup time.
  • PR feat(kagent-adk): Use new mcp session for a2a requests #1220 impact: Since #1220 (v0.7.10), a new MCP session is created for every A2A request rather than being reused across calls. This means the stdio process startup penalty is paid on every single request, not just the first one.

Typical failure pattern observed:

  • Cold starts (first call after pod creation): frequently timeout — stdio process installation + initialization exceeds 5s
  • Warm calls: intermittently timeout — natural variability in stdio process spawn time via the sidecar gateway causes 10-30% of requests to exceed 5s, even when the package is cached

The timeout is per-MCP-server, but a single slow initialization is enough to fail the entire agent request.

🔄 Steps To Reproduce

  1. Deploy kagent with the default configuration
  2. Create a MCPServer CRD (e.g. any stdio-based MCP server like @modelcontextprotocol/server-filesystem):
    apiVersion: kagent.dev/v1alpha1
    kind: MCPServer
    metadata:
      name: eks-mcp
    spec:
      transportType: stdio
      stdioTransport:
        command: uvx
        args: ["awslabs.eks-mcp-server@latest"]
    Note: The MCPServer CRD does not have a timeout field — users cannot configure this directly.
  3. Create an Agent that references this MCPServer as a tool
  4. Send a message to the agent that requires using the MCP tool
  5. Observe intermittent "Failed to create MCP session" errors, especially on:
    • The first call after pod creation (cold start)
    • Under load when multiple agents are spawning stdio processes simultaneously
    • After the agentgateway sidecar restarts or cache is cleared

🤔 Expected Behavior

Agents using MCPServer CRDs should connect reliably to their MCP tool servers. Since the MCPServer CRD does not expose a timeout field, the controller should apply a sensible default that accommodates stdio process startup time via the sidecar gateway.

Proposed Solution: Make the default configurable via Helm values / controller config (recommended)

Add a global defaultMCPServerTimeout setting to the kagent controller configuration (exposed via Helm values). This allows cluster operators to tune the default without modifying code:

# values.yaml
controller:
  defaultMCPServerTimeout: 30s

📱 Actual Behavior

Agents intermittently fail to create MCP sessions because the 5-second default timeout from the Python ADK is too low for the sidecar gateway architecture where a new stdio process is spawned per session.

💻 Environment

  • kagent version: 0.7.13 (also affects all versions since feat(kagent-adk): Use new mcp session for a2a requests #1220 / v0.7.10)
  • Python ADK version: latest (confirmed timeout: float = 5.0 default in StreamableHTTPConnectionParams)
  • Kubernetes: EKS 1.34
  • MCP servers affected: Any stdio-based MCP server deployed via MCPServer CRD, especially those using npx or uvx
  • agentgateway version: 0.10.2

🔧 CLI Bug Report

No response

🔍 Additional Context

📋 Logs

📷 Screenshots

No response

🙋 Are you willing to contribute?

  • I am willing to submit a PR to fix this issue

Activity

  1. added theissue type on Feb 9, 2026
  2. EItanya commented on Feb 9, 2026

    @EItanya
    Contributor

    This is a great point! Good catch

  3. added a commit that references this issue on Feb 11, 2026
    9c56216
  4. added a commit that references this issue on Apr 30, 2026
    b4e26df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions