on main help sign in
feat(mcp): configurable MCP timeout
bc52493Carlos Alexandro Becker
internal/config/config.go+1
@@ -110,6 +110,7 @@ type MCPConfig struct {
110 Type MCPType `json:"type" jsonschema:"required,description=Type of MCP connection,enum=stdio,enum=sse,enum=http,default=stdio"`
110 Type MCPType `json:"type" jsonschema:"required,description=Type of MCP connection,enum=stdio,enum=sse,enum=http,default=stdio"`
111 URL string `json:"url,omitempty" jsonschema:"description=URL for HTTP or SSE MCP servers,format=uri,example=http://localhost:3000/mcp"`
111 URL string `json:"url,omitempty" jsonschema:"description=URL for HTTP or SSE MCP servers,format=uri,example=http://localhost:3000/mcp"`
112 Disabled bool `json:"disabled,omitempty" jsonschema:"description=Whether this MCP server is disabled,default=false"`
112 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"`
113
114
114 // TODO: maybe make it possible to get the value from the env
115 // TODO: maybe make it possible to get the value from the env
115 Headers map[string]string `json:"headers,omitempty" jsonschema:"description=HTTP headers for HTTP/SSE MCP servers"`
116 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 @@
1package agent
1package agent
2
2
3import (
3import (
4+ "cmp"
4 "context"
5 "context"
5 "encoding/json"
6 "encoding/json"
6 "fmt"
7 "fmt"
@@ -274,7 +275,8 @@ func doGetMCPTools(ctx context.Context, permissions permission.Service, cfg *con
274 }
275 }
275 }()
276 }()
276
277
278+ timeout := time.Duration(cmp.Or(m.Timeout, 15)) * time.Second
277− ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
279+ ctx, cancel := context.WithTimeout(ctx, timeout)
278 defer cancel()
280 defer cancel()
279 c, err := createMcpClient(m)
281 c, err := createMcpClient(m)
280 if err != nil {
282 if err != nil {
schema.json+10
@@ -125,6 +125,16 @@
125 "description": "Whether this MCP server is disabled",
125 "description": "Whether this MCP server is disabled",
126 "default": false
126 "default": false
127 },
127 },
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+ },
128 "headers": {
138 "headers": {
129 "additionalProperties": {
139 "additionalProperties": {
130 "type": "string"
140 "type": "string"