@@ -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 客户端。
2428type Client struct {
@@ -58,10 +62,9 @@ func NewClient() *Client {
5862
5963// NewClientWithEnv 创建带运行环境的 MCP 客户端。
6064func 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+
224230func (c * Client ) nextRequestID () int64 {
225231 return c .nextID .Add (1 )
226232}
0 commit comments