|
6 | 6 |
|
7 | 7 | package modelengine.fel.tool.mcp.client.support; |
8 | 8 |
|
9 | | -import static modelengine.fitframework.inspection.Validation.notNull; |
10 | | - |
11 | 9 | import modelengine.fel.tool.mcp.client.McpClient; |
12 | 10 | import modelengine.fel.tool.mcp.client.McpClientFactory; |
13 | | -import modelengine.fit.http.client.HttpClassicClient; |
14 | | -import modelengine.fit.http.client.HttpClassicClientFactory; |
15 | 11 | import modelengine.fitframework.annotation.Component; |
16 | | -import modelengine.fitframework.annotation.Fit; |
17 | 12 | import modelengine.fitframework.annotation.Value; |
18 | | -import modelengine.fitframework.serialization.ObjectSerializer; |
19 | 13 |
|
20 | 14 | /** |
21 | | - * Represents a factory for creating instances of the DefaultMcpClient. |
22 | | - * This class is responsible for initializing and configuring the HTTP client and JSON serializer |
23 | | - * required by the DefaultMcpClient. |
| 15 | + * Represents a factory for creating instances of the {@link DefaultMcpStreamableClient}. |
| 16 | + * This class is responsible for initializing and configuring. |
24 | 17 | * |
25 | 18 | * @author 季聿阶 |
26 | 19 | * @since 2025-05-21 |
27 | 20 | */ |
28 | 21 | @Component |
29 | 22 | public class DefaultMcpClientFactory implements McpClientFactory { |
30 | | - private final HttpClassicClient client; |
31 | | - private final ObjectSerializer jsonSerializer; |
32 | | - private final long pingInterval; |
| 23 | + private final int requestTimeoutSeconds; |
33 | 24 |
|
34 | 25 | /** |
35 | 26 | * Constructs a new instance of the DefaultMcpClientFactory. |
36 | 27 | * |
37 | | - * @param clientFactory The factory used to create the HTTP client. |
38 | | - * @param jsonSerializer The JSON serializer used for serialization and deserialization. |
39 | | - * @param pingInterval The interval between ping requests. Units: milliseconds. |
| 28 | + * @param requestTimeoutSeconds The timeout duration of requests. Units: seconds. |
40 | 29 | */ |
41 | | - public DefaultMcpClientFactory(HttpClassicClientFactory clientFactory, |
42 | | - @Fit(alias = "json") ObjectSerializer jsonSerializer, |
43 | | - @Value("${mcp.client.ping-interval}") long pingInterval) { |
44 | | - this.client = clientFactory.create(HttpClassicClientFactory.Config.builder() |
45 | | - .connectTimeout(30_000) |
46 | | - .socketTimeout(60_000) |
47 | | - .connectionRequestTimeout(60_000) |
48 | | - .build()); |
49 | | - this.jsonSerializer = notNull(jsonSerializer, "The json serializer cannot be null."); |
50 | | - this.pingInterval = pingInterval; |
| 30 | + public DefaultMcpClientFactory(@Value("${mcp.client.request.timeout-seconds}") int requestTimeoutSeconds) { |
| 31 | + this.requestTimeoutSeconds = requestTimeoutSeconds > 0 ? requestTimeoutSeconds : 180; |
51 | 32 | } |
52 | 33 |
|
53 | 34 | @Override |
54 | 35 | public McpClient create(String baseUri, String sseEndpoint) { |
55 | | - return new DefaultMcpClient(this.jsonSerializer, this.client, baseUri, sseEndpoint, this.pingInterval); |
| 36 | + return new DefaultMcpStreamableClient(baseUri, sseEndpoint, requestTimeoutSeconds); |
56 | 37 | } |
57 | 38 | } |
0 commit comments