类 McpSyncClientWrapper
java.lang.Object
io.agentscope.core.tool.mcp.McpClientWrapper
io.agentscope.core.tool.mcp.McpSyncClientWrapper
- 所有已实现的接口:
AutoCloseable
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));
-
字段概要
从类继承的字段 io.agentscope.core.tool.mcp.McpClientWrapper
cachedTools, initialized, name -
构造器概要
构造器构造器说明McpSyncClientWrapper(String name, io.modelcontextprotocol.client.McpSyncClient client) Constructs a new synchronous MCP client wrapper. -
方法概要
修饰符和类型方法说明reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono.voidclose()Closes the MCP client connection and releases all resources.reactor.core.publisher.Mono<Void> Initializes the sync 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
-
构造器详细资料
-
McpSyncClientWrapper
Constructs a new synchronous MCP client wrapper.- 参数:
name- unique identifier for this clientclient- the underlying sync MCP client
-
-
方法详细资料
-
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
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 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
-