McpSyncClientWrapper
public class McpSyncClientWrapper extends McpClientWrapper
io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:41–206MCP 同步客户端包装器,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool.mcp 包,继承自 McpClientWrapper。核心成员包括 initialize、listTools、callTool、close、McpSyncClientWrapper。
Wrapper for synchronous MCP clients that converts blocking calls to reactive Mono types.
This implementation delegates to McpSyncClient and wraps blocking operations
in Reactor's boundedElastic scheduler to avoid blocking the event loop.
Example usage:
`McpSyncClient client = ... // created via McpClient.sync()
McpSyncClientWrapper wrapper = new McpSyncClientWrapper("my-mcp", client);
wrapper.initialize()
.then(wrapper.callTool("tool_name", Map.of("arg1", "value1")))
.subscribe(result -> System.out.println(result));
`
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public McpSyncClientWrapper(String name, McpSyncClient client) | 初始化 `McpSyncClientWrapper` 实例。 Constructs a new synchronous MCP client wrapper. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<Void> initialize() | 初始化 `McpSyncClientWrapper` 实例。 Initializes the sync MCP client connection and caches available tools. |
public Mono<List<McpSchema.Tool>> listTools() | 列出工具。 Lists all tools available from the MCP server. |
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments) | 调用工具。 Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono. |
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta) | 调用工具。 Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono. |
public void close() | 关闭连接并释放相关资源。 Closes the MCP client connection and releases all resources. |
构造器详情Constructor Detail
McpSyncClientWrapper
public McpSyncClientWrapper(String name, McpSyncClient client)
初始化 McpSyncClientWrapper 实例。
Constructs a new synchronous MCP client wrapper.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。unique identifier for this client |
client | McpSyncClient | 客户端(类型 `McpSyncClient`)。the underlying sync MCP client |
io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:53–56方法详情Method Detail
initialize
public Mono<Void> initialize()
初始化 McpSyncClientWrapper 实例。
Initializes the sync MCP client connection and caches available tools.
Mono<Void>io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:67–99listTools
public Mono<List<McpSchema.Tool>> listTools()
列出工具。
Lists all tools available from the MCP server.
Mono<List<McpSchema.Tool>>IllegalStateException当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:110–119callTool
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments)
调用工具。
Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolName | String | 工具到调用的名称。the name of the tool to call |
arguments | Map<String, Object> | 参数(类型 `Map`)。the arguments to pass to the tool |
Mono<McpSchema.CallToolResult>IllegalStateException当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:132–135callTool
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta)
调用工具。
Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolName | String | 工具到调用的名称。the name of the tool to call |
arguments | Map<String, Object> | 参数(类型 `Map`)。the arguments to pass to the tool |
meta | Map<String, Object> | 元数据(类型 `Map`)。additional metadata to pass to the tool |
Mono<McpSchema.CallToolResult>IllegalStateException当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:149–183close
public void close()
关闭连接并释放相关资源。
Closes the MCP client connection and releases all resources.
io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:191–205