McpAsyncClientWrapper
public class McpAsyncClientWrapper extends McpClientWrapper
io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:40–198MCP 异步客户端包装器,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool.mcp 包,继承自 McpClientWrapper。核心成员包括 initialize、listTools、callTool、close、McpAsyncClientWrapper。
Wrapper for asynchronous MCP clients using Project Reactor.
This implementation delegates to McpAsyncClient and provides
reactive operations that return Mono types.
Example usage:
`McpAsyncClient client = ... // created via McpClient.async()
McpAsyncClientWrapper wrapper = new McpAsyncClientWrapper("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 McpAsyncClientWrapper(String name, McpAsyncClient client) | 初始化 `McpAsyncClientWrapper` 实例。 Constructs a new asynchronous MCP client wrapper. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Mono<Void> initialize() | 初始化 `McpAsyncClientWrapper` 实例。 Initializes the async 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 asynchronously. |
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta) | 调用工具。 Invokes a tool on the MCP server asynchronously with additional metadata. |
public void close() | 关闭连接并释放相关资源。 Closes the MCP client connection and releases all resources. |
构造器详情Constructor Detail
McpAsyncClientWrapper
public McpAsyncClientWrapper(String name, McpAsyncClient client)
初始化 McpAsyncClientWrapper 实例。
Constructs a new asynchronous MCP client wrapper.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。unique identifier for this client |
client | McpAsyncClient | 客户端(类型 `McpAsyncClient`)。the underlying async MCP client |
io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:52–55方法详情Method Detail
initialize
public Mono<Void> initialize()
初始化 McpAsyncClientWrapper 实例。
Initializes the async MCP client connection and caches available tools.
Mono<Void>io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:65–93listTools
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/McpAsyncClientWrapper.java:104–112callTool
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments)
调用工具。
Invokes a tool on the MCP server asynchronously.
| 名称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/McpAsyncClientWrapper.java:125–128callTool
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta)
调用工具。
Invokes a tool on the MCP server asynchronously with additional metadata.
| 名称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 include in the request |
Mono<McpSchema.CallToolResult>IllegalStateException当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:142–173close
public void close()
关闭连接并释放相关资源。
Closes the MCP client connection and releases all resources.
io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:181–197