类 McpAsyncClientWrapper

java.lang.Object
io.agentscope.core.tool.mcp.McpClientWrapper
io.agentscope.core.tool.mcp.McpAsyncClientWrapper
所有已实现的接口:
AutoCloseable

public class McpAsyncClientWrapper extends McpClientWrapper
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));
 
  • 构造器详细资料

    • McpAsyncClientWrapper

      public McpAsyncClientWrapper(String name, io.modelcontextprotocol.client.McpAsyncClient client)
      Constructs a new asynchronous MCP client wrapper.
      参数:
      name - unique identifier for this client
      client - the underlying async MCP client
  • 方法详细资料

    • initialize

      public reactor.core.publisher.Mono<Void> 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

      public reactor.core.publisher.Mono<List<io.modelcontextprotocol.spec.McpSchema.Tool>> 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 call
      arguments - 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