Skip to content

Commit 3ba0e2e

Browse files
authored
feat(crd): add default timeout field to MCPServerSpec (#121)
### Summary Adds a `Timeout` field to `MCPServerSpec` with a kubebuilder default of `30s`. This addresses [kagent-dev/kagent#1272](kagent-dev/kagent#1272): MCP servers deployed via the MCPServer CRD use a sidecar gateway that spawns a new stdio process (e.g. via `uvx`/`npx`) for each session. Process startup can take 2–8 seconds depending on package cache state, which exceeds the default 5-second timeout used by some ADK clients (e.g. Python ADK `StreamableHTTPConnectionParams`), causing intermittent `"Failed to create MCP session"` errors. ### Context An initial fix was proposed in [kagent-dev/kagent#1275](kagent-dev/kagent#1275) by making the timeout configurable via the Helm chart (env var → controller flag → handler threading). A maintainer [correctly pointed out](kagent-dev/kagent#1275 (comment)) that the proper fix is to add this field to the MCPServer CRD itself, which: - Follows existing CRD patterns (`Port` has `+kubebuilder:default=3000`, `Replicas` has `+kubebuilder:default=1`) - Provides **per-resource granularity** (each MCPServer can specify its own timeout) - Eliminates complex threading through Helm/env/flags/handlers - Is the Kubernetes-idiomatic approach ### Changes | File | Description | |------|-------------| | `api/v1alpha1/mcpserver_types.go` | Add `Timeout *metav1.Duration` field with `+kubebuilder:default="30s"` | | `api/v1alpha1/zz_generated.deepcopy.go` | Regenerated via `make generate` | | `config/crd/bases/kagent.dev_mcpservers.yaml` | CRD manifest regenerated via `make manifests` | | `helm/kmcp-crds/templates/mcpserver-crd.yaml` | Helm CRD template updated to match | ### Backward Compatibility - The default value is `30s` — existing MCPServer resources without an explicit timeout will automatically get this default applied by the API server. - No breaking changes to existing CRs. ### Companion PR Once this is merged and released, I will create a new PR and the kagent controller will be updated to propagate this field: `ConvertMCPServerToRemoteMCPServer` propagates `MCPServer.Spec.Timeout` → `RemoteMCPServer.Spec.Timeout` Ref: [kagent-dev/kagent#1272](kagent-dev/kagent#1272) Signed-off-by: skhedim <sebastien.khedim@gmail.com>
1 parent 161b9fe commit 3ba0e2e

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

api/v1alpha1/mcpserver_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ type MCPServerSpec struct {
148148

149149
// HTTPTransport defines the configuration for a Streamable HTTP transport.
150150
HTTPTransport *HTTPTransport `json:"httpTransport,omitempty"`
151+
152+
// Timeout defines the default connection timeout for clients connecting
153+
// to this MCP server. MCP servers deployed via the MCPServer CRD use a
154+
// sidecar gateway that spawns a new stdio process (e.g. via uvx/npx)
155+
// for each session. Process startup can take 2-8 seconds depending on
156+
// package cache state, which may exceed the default timeout used by some
157+
// clients. This value is propagated to the generated RemoteMCPServer
158+
// resources when they do not specify an explicit timeout.
159+
// +optional
160+
// +kubebuilder:default="30s"
161+
Timeout *metav1.Duration `json:"timeout,omitempty"`
151162
}
152163

153164
// StdioTransport defines the configuration for a standard input/output transport.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/kagent.dev_mcpservers.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5282,6 +5282,17 @@ spec:
52825282
description: StdioTransport defines the configuration for a standard
52835283
input/output transport.
52845284
type: object
5285+
timeout:
5286+
default: 30s
5287+
description: |-
5288+
Timeout defines the default connection timeout for clients connecting
5289+
to this MCP server. MCP servers deployed via the MCPServer CRD use a
5290+
sidecar gateway that spawns a new stdio process (e.g. via uvx/npx)
5291+
for each session. Process startup can take 2-8 seconds depending on
5292+
package cache state, which may exceed the default timeout used by some
5293+
clients. This value is propagated to the generated RemoteMCPServer
5294+
resources when they do not specify an explicit timeout.
5295+
type: string
52855296
transportType:
52865297
description: TransportType defines the type of mcp server being run
52875298
enum:

helm/kmcp-crds/templates/mcpserver-crd.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,17 @@ spec:
20142014
description: StdioTransport defines the configuration for a standard
20152015
input/output transport.
20162016
type: object
2017+
timeout:
2018+
default: 30s
2019+
description: |-
2020+
Timeout defines the default connection timeout for clients connecting
2021+
to this MCP server. MCP servers deployed via the MCPServer CRD use a
2022+
sidecar gateway that spawns a new stdio process (e.g. via uvx/npx)
2023+
for each session. Process startup can take 2-8 seconds depending on
2024+
package cache state, which may exceed the default timeout used by some
2025+
clients. This value is propagated to the generated RemoteMCPServer
2026+
resources when they do not specify an explicit timeout.
2027+
type: string
20172028
transportType:
20182029
description: TransportType defines the type of mcp server being run
20192030
enum:

0 commit comments

Comments
 (0)