on main help sign in
feat(mcp): configurable MCP timeout

closes #604 closes https://github.com/charmbracelet/crush/discussions/754 Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commitbc52493640ce98e9ed34717731ab43b754e5b82c authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateWed 13 Aug 2025, 16:06 (1 year ago) parent09fca23
3 files changed+14−1
internal/config/config.go+1 internal/llm/agent/mcp-tools.go+3−1 schema.json+10
internal/config/config.go+1
@@ -110,6 +110,7 @@ type MCPConfig struct {
110110 Type MCPType `json:"type" jsonschema:"required,description=Type of MCP connection,enum=stdio,enum=sse,enum=http,default=stdio"`
111111 URL string `json:"url,omitempty" jsonschema:"description=URL for HTTP or SSE MCP servers,format=uri,example=http://localhost:3000/mcp"`
112112 Disabled bool `json:"disabled,omitempty" jsonschema:"description=Whether this MCP server is disabled,default=false"`
113+ Timeout int `json:"timeout,omitempty" jsonschema:"description=Timeout in seconds for MCP server connections,default=15,example=30,example=60,example=120"`
113114
114115 // TODO: maybe make it possible to get the value from the env
115116 Headers map[string]string `json:"headers,omitempty" jsonschema:"description=HTTP headers for HTTP/SSE MCP servers"`
internal/llm/agent/mcp-tools.go+3−1
@@ -1,6 +1,7 @@
11package agent
22
33import (
4+ "cmp"
45 "context"
56 "encoding/json"
67 "fmt"
@@ -274,7 +275,8 @@ func doGetMCPTools(ctx context.Context, permissions permission.Service, cfg *con
274275 }
275276 }()
276277
277− ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
278+ timeout := time.Duration(cmp.Or(m.Timeout, 15)) * time.Second
279+ ctx, cancel := context.WithTimeout(ctx, timeout)
278280 defer cancel()
279281 c, err := createMcpClient(m)
280282 if err != nil {
schema.json+10
@@ -125,6 +125,16 @@
125125 "description": "Whether this MCP server is disabled",
126126 "default": false
127127 },
128+ "timeout": {
129+ "type": "integer",
130+ "description": "Timeout in seconds for MCP server connections",
131+ "default": 15,
132+ "examples": [
133+ 30,
134+ 60,
135+ 120
136+ ]
137+ },
128138 "headers": {
129139 "additionalProperties": {
130140 "type": "string"