类 McpAsyncClientWrapper
java.lang.Object
io.agentscope.core.tool.mcp.McpClientWrapper
io.agentscope.core.tool.mcp.McpAsyncClientWrapper
- 所有已实现的接口:
AutoCloseable
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));
-
字段概要
从类继承的字段 io.agentscope.core.tool.mcp.McpClientWrapper
cachedTools, initialized, name -
构造器概要
构造器构造器说明McpAsyncClientWrapper(String name, io.modelcontextprotocol.client.McpAsyncClient client) Constructs a new asynchronous MCP client wrapper. -
方法概要
修饰符和类型方法说明reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> Invokes a tool on the MCP server asynchronously.voidclose()Closes the MCP client connection and releases all resources.reactor.core.publisher.Mono<Void> Initializes the async MCP client connection and caches available tools.reactor.core.publisher.Mono<List<io.modelcontextprotocol.spec.McpSchema.Tool>> Lists all tools available from the MCP server.从类继承的方法 io.agentscope.core.tool.mcp.McpClientWrapper
getCachedTool, getName, isInitialized
-
构造器详细资料
-
McpAsyncClientWrapper
Constructs a new asynchronous MCP client wrapper.- 参数:
name- unique identifier for this clientclient- the underlying async MCP client
-
-
方法详细资料
-
initialize
Initializes the async MCP client connection and caches available tools.This method connects to the MCP server, discovers available tools, and caches them for later use. If already initialized, this method returns immediately without re-initializing.
- 指定者:
initialize在类中McpClientWrapper- 返回:
- a Mono that completes when initialization is finished
-
listTools
Lists all tools available from the MCP server.This method queries the MCP server for its current list of tools. The client must be initialized before calling this method.
- 指定者:
listTools在类中McpClientWrapper- 返回:
- a Mono emitting the list of available tools
- 抛出:
IllegalStateException- if the client is not initialized
-
callTool
public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments) Invokes a tool on the MCP server asynchronously.This method sends a tool call request to the MCP server and returns the result asynchronously. The client must be initialized before calling this method.
- 指定者:
callTool在类中McpClientWrapper- 参数:
toolName- the name of the tool to callarguments- the arguments to pass to the tool- 返回:
- a Mono emitting the tool call result (may contain error information)
- 抛出:
IllegalStateException- if the client is not initialized
-
close
public void close()Closes the MCP client connection and releases all resources.This method attempts to close the client gracefully, falling back to forceful closure if graceful closure fails. This method is idempotent and can be called multiple times safely.
- 指定者:
close在接口中AutoCloseable- 指定者:
close在类中McpClientWrapper
-