类 McpClientWrapper
java.lang.Object
io.agentscope.core.tool.mcp.McpClientWrapper
- 所有已实现的接口:
AutoCloseable
Abstract wrapper for MCP (Model Context Protocol) clients.
This class manages the lifecycle of MCP client connections and provides
a unified interface for both asynchronous and synchronous client implementations.
The wrapper handles:
- Client initialization and connection management
- Tool discovery and caching
- Tool invocation through the MCP protocol
- Resource cleanup on close
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明Cache of tools available from this MCP serverprotected booleanFlag indicating whether the client has been initializedprotected final StringUnique identifier for this MCP client -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明abstract reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> Invokes a tool on the MCP server.abstract voidclose()Closes this MCP client and releases all resources.io.modelcontextprotocol.spec.McpSchema.ToolgetCachedTool(String toolName) Gets a cached tool definition by name.getName()Gets the unique name of this MCP client.abstract reactor.core.publisher.Mono<Void> Initializes the MCP client connection and caches available tools.booleanChecks if this client has been initialized.abstract reactor.core.publisher.Mono<List<io.modelcontextprotocol.spec.McpSchema.Tool>> Lists all tools available from this MCP server.
-
字段详细资料
-
name
Unique identifier for this MCP client -
cachedTools
Cache of tools available from this MCP server -
initialized
protected volatile boolean initializedFlag indicating whether the client has been initialized
-
-
构造器详细资料
-
McpClientWrapper
Constructs a new MCP client wrapper.- 参数:
name- unique identifier for this client
-
-
方法详细资料
-
getName
Gets the unique name of this MCP client.- 返回:
- the client name
-
isInitialized
public boolean isInitialized()Checks if this client has been initialized.- 返回:
- true if initialized, false otherwise
-
initialize
Initializes the MCP client connection and caches available tools. This method must be called before any tool operations.- 返回:
- a Mono that completes when initialization is finished
-
listTools
public abstract reactor.core.publisher.Mono<List<io.modelcontextprotocol.spec.McpSchema.Tool>> listTools()Lists all tools available from this MCP server.- 返回:
- a Mono emitting the list of available tools
-
callTool
public abstract reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments) Invokes a tool on the MCP server.- 参数:
toolName- the name of the tool to callarguments- the arguments to pass to the tool- 返回:
- a Mono emitting the tool call result
-
getCachedTool
Gets a cached tool definition by name.- 参数:
toolName- the name of the tool- 返回:
- the tool definition, or null if not found
-
close
public abstract void close()Closes this MCP client and releases all resources. This method is idempotent and can be called multiple times safely.- 指定者:
close在接口中AutoCloseable
-