AS AgentScopeAPI 手册 / API Reference

McpAsyncClientWrapper

public class McpAsyncClientWrapper extends McpClientWrapper
源码Source io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:40–198

MCP 异步客户端包装器,让智能体以受控方式调用外部能力。位于 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.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。unique identifier for this client
clientMcpAsyncClient客户端(类型 `McpAsyncClient`)。the underlying async MCP client
源码Source 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.

返回Returns Mono<Void>
返回Mono。a Mono that completes when initialization is finished
源码Source io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:65–93

listTools

public Mono<List<McpSchema.Tool>> listTools()

列出工具。

Lists all tools available from the MCP server.

返回Returns Mono<List<McpSchema.Tool>>
返回Mono>。a Mono emitting the list of available tools
抛出Throws
  • IllegalStateException 当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
源码Source io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:104–112

callTool

public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments)

调用工具。

Invokes a tool on the MCP server asynchronously.

参数Parameters
名称Name类型Type说明Description
toolNameString工具到调用的名称。the name of the tool to call
argumentsMap<String, Object>参数(类型 `Map`)。the arguments to pass to the tool
返回Returns Mono<McpSchema.CallToolResult>
返回Mono。a Mono emitting the tool call result (may contain error information)
抛出Throws
  • IllegalStateException 当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
源码Source io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:125–128

callTool

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.

参数Parameters
名称Name类型Type说明Description
toolNameString工具到调用的名称。the name of the tool to call
argumentsMap<String, Object>参数(类型 `Map`)。the arguments to pass to the tool
metaMap<String, Object>元数据(类型 `Map`)。additional metadata to include in the request
返回Returns Mono<McpSchema.CallToolResult>
返回Mono。a Mono emitting the tool call result (may contain error information)
抛出Throws
  • IllegalStateException 当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
源码Source io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:142–173

close

public void close()

关闭连接并释放相关资源。

Closes the MCP client connection and releases all resources.

源码Source io/agentscope/core/tool/mcp/McpAsyncClientWrapper.java:181–197

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.