类 McpClientWrapper

java.lang.Object
io.agentscope.core.tool.mcp.McpClientWrapper
所有已实现的接口:
AutoCloseable
直接已知子类:
McpAsyncClientWrapper, McpSyncClientWrapper

public abstract class McpClientWrapper extends Object implements 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
另请参阅:
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    protected final Map<String,io.modelcontextprotocol.spec.McpSchema.Tool>
    Cache of tools available from this MCP server
    protected boolean
    Flag indicating whether the client has been initialized
    protected final String
    Unique identifier for this MCP client
  • 构造器概要

    构造器
    限定符
    构造器
    说明
    protected
    Constructs a new MCP client wrapper.
  • 方法概要

    修饰符和类型
    方法
    说明
    abstract reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>
    callTool(String toolName, Map<String,Object> arguments)
    Invokes a tool on the MCP server.
    abstract void
    Closes this MCP client and releases all resources.
    io.modelcontextprotocol.spec.McpSchema.Tool
    Gets a cached tool definition by name.
    Gets the unique name of this MCP client.
    abstract reactor.core.publisher.Mono<Void>
    Initializes the MCP client connection and caches available tools.
    boolean
    Checks 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.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • name

      protected final String name
      Unique identifier for this MCP client
    • cachedTools

      protected final Map<String,io.modelcontextprotocol.spec.McpSchema.Tool> cachedTools
      Cache of tools available from this MCP server
    • initialized

      protected volatile boolean initialized
      Flag indicating whether the client has been initialized
  • 构造器详细资料

    • McpClientWrapper

      protected McpClientWrapper(String name)
      Constructs a new MCP client wrapper.
      参数:
      name - unique identifier for this client
  • 方法详细资料

    • getName

      public String 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

      public abstract reactor.core.publisher.Mono<Void> 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 call
      arguments - the arguments to pass to the tool
      返回:
      a Mono emitting the tool call result
    • getCachedTool

      public io.modelcontextprotocol.spec.McpSchema.Tool getCachedTool(String toolName)
      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