Skip to content

Commit 5976d0d

Browse files
authored
Merge branch 'dev' into loading
2 parents 0c4f6bf + c6dfd19 commit 5976d0d

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

backend/internal/application/settings/runtime_settings.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111
"github.com/DEEIX-AI/DEEIX-Chat/backend/internal/repository"
1212
)
1313

14+
const (
15+
defaultMCPToolTimeoutSeconds = 10
16+
maxMCPToolTimeoutSeconds = 1800
17+
)
18+
1419
// RuntimeSettings 负责把数据库中的动态配置应用到运行时配置,并维护配置缓存。
1520
type RuntimeSettings struct {
1621
repo repository.SettingsRepository
@@ -399,6 +404,12 @@ func (r *RuntimeSettings) normalizeConfig(cfg *config.Config) {
399404
if cfg.MCPMaxSelectedToolsPerMessage > config.MaxMCPSelectedToolsPerMessage {
400405
cfg.MCPMaxSelectedToolsPerMessage = config.MaxMCPSelectedToolsPerMessage
401406
}
407+
if cfg.MCPToolTimeoutSeconds <= 0 {
408+
cfg.MCPToolTimeoutSeconds = defaultMCPToolTimeoutSeconds
409+
}
410+
if cfg.MCPToolTimeoutSeconds > maxMCPToolTimeoutSeconds {
411+
cfg.MCPToolTimeoutSeconds = maxMCPToolTimeoutSeconds
412+
}
402413
if !cfg.FileFullContextLimitEnabled {
403414
cfg.FileFullContextMaxBytes = 0
404415
cfg.FileFullContextMaxTokens = 0

backend/internal/application/settings/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func validatePatchItem(item PatchItem) error {
475475
case "mcp:mcp_max_selected_tools_per_message":
476476
return validateIntMinMax(value, 1, config.MaxMCPSelectedToolsPerMessage, key)
477477
case "mcp:mcp_tool_timeout_seconds":
478-
return validateIntMinMax(value, 1, 120, key)
478+
return validateIntMinMax(value, 0, maxMCPToolTimeoutSeconds, key)
479479
case "mcp:mcp_tool_retry_count":
480480
return validateIntMinMax(value, 0, 5, key)
481481
case "mcp:mcp_tool_prompt":

backend/internal/infra/mcp/client.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import (
1818
"github.com/DEEIX-AI/DEEIX-Chat/backend/internal/shared/security"
1919
)
2020

21-
const protocolVersion = "2025-06-18"
21+
const (
22+
protocolVersion = "2025-06-18"
23+
defaultRequestTimeoutMS = 10000
24+
defaultConnectTimeout = 10 * time.Second
25+
)
2226

2327
// Client 封装 MCP Streamable HTTP JSON-RPC 客户端。
2428
type Client struct {
@@ -58,10 +62,9 @@ func NewClient() *Client {
5862

5963
// NewClientWithEnv 创建带运行环境的 MCP 客户端。
6064
func NewClientWithEnv(env string, ssrfProtectionEnabled bool) *Client {
61-
transport := security.NewOutboundHTTPTransport(env, ssrfProtectionEnabled, 10*time.Second)
65+
transport := security.NewOutboundHTTPTransport(env, ssrfProtectionEnabled, defaultConnectTimeout)
6266
return &Client{
6367
httpClient: &http.Client{
64-
Timeout: 30 * time.Second,
6568
Transport: platformtracing.NewHTTPTransport(transport),
6669
},
6770
}
@@ -168,11 +171,7 @@ func (c *Client) rpcWithSession(
168171
return nil, sessionID, err
169172
}
170173

171-
timeoutMS := cfg.TimeoutMS
172-
if timeoutMS <= 0 {
173-
timeoutMS = 10000
174-
}
175-
requestCtx, cancel := context.WithTimeout(ctx, time.Duration(timeoutMS)*time.Millisecond)
174+
requestCtx, cancel := context.WithTimeout(ctx, time.Duration(resolveRequestTimeoutMS(cfg.TimeoutMS))*time.Millisecond)
176175
defer cancel()
177176

178177
req, err := http.NewRequestWithContext(requestCtx, http.MethodPost, endpoint, bytes.NewReader(raw))
@@ -221,6 +220,13 @@ func (c *Client) rpcWithSession(
221220
return result, sessionID, nil
222221
}
223222

223+
func resolveRequestTimeoutMS(timeoutMS int) int {
224+
if timeoutMS <= 0 {
225+
return defaultRequestTimeoutMS
226+
}
227+
return timeoutMS
228+
}
229+
224230
func (c *Client) nextRequestID() int64 {
225231
return c.nextID.Add(1)
226232
}

0 commit comments

Comments
 (0)