类 McpSyncClientWrapper

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

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

    • McpSyncClientWrapper

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

    • initialize

      public reactor.core.publisher.Mono<Void> initialize()
      Initializes the sync MCP client connection and caches available tools.

      This method wraps the blocking synchronous client operations in a reactive Mono that runs on the boundedElastic scheduler to avoid blocking the event loop. 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 wraps the blocking synchronous listTools call in a reactive Mono. 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, wrapping the blocking call in a reactive Mono.

      This method wraps the blocking synchronous callTool operation in a Mono that runs on the boundedElastic scheduler. 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