McpClientWrapper
public abstract class McpClientWrapper implements AutoCloseable
io/agentscope/core/tool/mcp/McpClientWrapper.java:40–171用于MCP(模型上下文协议)客户端的抽象包装器。位于 io.agentscope.core.tool.mcp 包,实现 AutoCloseable。核心成员包括 getName、isInitialized、isPropagateMeta、setPropagateMeta、initialize、listTools。
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
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
namefinal | String | 名称字段。 Unique identifier for this MCP client |
cachedToolsfinal | Map<String, McpSchema.Tool> | 工具可用来自此 MCP 服务端的缓存。 Cache of tools available from this MCP server |
initializedvolatile | boolean | 已初始化字段。 Flag indicating whether the client has been initialized |
propagateMetavolatile | boolean | `propagateMeta` 字段。 Whether request metadata (user `McpMeta` entries and the framework tool-call id) is
propagated to the MCP server behind this connection. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
protected McpClientWrapper(String name) | 初始化 `McpClientWrapper` 实例。 Constructs a new MCP client wrapper. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String getName() | 获取名称。 Gets the unique name of this MCP client. |
public boolean isInitialized() | 判断是否已初始化。 Checks if this client has been initialized. |
public boolean isPropagateMeta() | 判断是否 `isPropagateMeta`。 Checks whether request metadata is propagated to this MCP server. |
public void setPropagateMeta(boolean propagateMeta) | 设置 `setPropagateMeta`。 Configures whether request metadata is propagated to this MCP server. |
public abstract Mono<Void> initialize()abstract | 初始化 `McpClientWrapper` 实例。 Initializes the MCP client connection and caches available tools. |
public abstract Mono<List<McpSchema.Tool>> listTools()abstract | 列出工具。 Lists all tools available from this MCP server. |
public abstract Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments)abstract | 调用工具。 Invokes a tool on the MCP server. |
public abstract Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta)abstract | 调用工具。 Invokes a tool on the MCP server. |
public McpSchema.Tool getCachedTool(String toolName) | 获取已缓存工具定义通过名称。 Gets a cached tool definition by name. |
public abstract void close()abstract | 关闭连接并释放相关资源。 Closes this MCP client and releases all resources. |
字段详情Field Detail
name
protected final String name
名称字段。声明为 protected final String name。
Unique identifier for this MCP client
io/agentscope/core/tool/mcp/McpClientWrapper.java:43cachedTools
protected final Map<String, McpSchema.Tool> cachedTools
工具可用来自此 MCP 服务端的缓存。
Cache of tools available from this MCP server
io/agentscope/core/tool/mcp/McpClientWrapper.java:46initialized
protected volatile boolean initialized
已初始化字段。声明为 protected volatile boolean initialized。
Flag indicating whether the client has been initialized
io/agentscope/core/tool/mcp/McpClientWrapper.java:49propagateMeta
protected volatile boolean propagateMeta
propagateMeta 字段。声明为 protected volatile boolean propagateMeta。
Whether request metadata (user McpMeta entries and the framework tool-call id) is propagated to the MCP server behind this connection.
io/agentscope/core/tool/mcp/McpClientWrapper.java:61构造器详情Constructor Detail
McpClientWrapper
protected McpClientWrapper(String name)
初始化 McpClientWrapper 实例。
Constructs a new MCP client wrapper.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。unique identifier for this client |
io/agentscope/core/tool/mcp/McpClientWrapper.java:68–71方法详情Method Detail
getName
public String getName()
获取名称。
Gets the unique name of this MCP client.
Stringio/agentscope/core/tool/mcp/McpClientWrapper.java:78–80isInitialized
public boolean isInitialized()
判断是否已初始化。
Checks if this client has been initialized.
booleanio/agentscope/core/tool/mcp/McpClientWrapper.java:87–89isPropagateMeta
public boolean isPropagateMeta()
判断是否 isPropagateMeta。
Checks whether request metadata is propagated to this MCP server.
booleanio/agentscope/core/tool/mcp/McpClientWrapper.java:101–103setPropagateMeta
public void setPropagateMeta(boolean propagateMeta)
设置 setPropagateMeta。
Configures whether request metadata is propagated to this MCP server.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
propagateMeta | boolean | propagate 元数据(类型 `boolean`)。true to propagate metadata (default), false to omit the `meta` field entirely from tool call requests |
io/agentscope/core/tool/mcp/McpClientWrapper.java:115–117initialize
public abstract Mono<Void> initialize()
初始化 McpClientWrapper 实例。
Initializes the MCP client connection and caches available tools.
Mono<Void>io/agentscope/core/tool/mcp/McpClientWrapper.java:125listTools
public abstract Mono<List<McpSchema.Tool>> listTools()
列出工具。
Lists all tools available from this MCP server.
Mono<List<McpSchema.Tool>>io/agentscope/core/tool/mcp/McpClientWrapper.java:132callTool
public abstract Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments)
调用工具。
Invokes a tool on the MCP server.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolName | String | 工具到调用的名称。the name of the tool to call |
arguments | Map<String, Object> | 参数(类型 `Map`)。the arguments to pass to the tool |
Mono<McpSchema.CallToolResult>io/agentscope/core/tool/mcp/McpClientWrapper.java:141–142callTool
public abstract Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta)
调用工具。
Invokes a tool on the MCP server.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolName | String | 工具到调用的名称。the name of the tool to call |
arguments | Map<String, Object> | 参数(类型 `Map`)。the arguments to pass to the tool |
meta | Map<String, Object> | 元数据(类型 `Map`)。the metadata to pass to the tool |
Mono<McpSchema.CallToolResult>io/agentscope/core/tool/mcp/McpClientWrapper.java:152–153getCachedTool
public McpSchema.Tool getCachedTool(String toolName)
获取已缓存工具定义通过名称。
Gets a cached tool definition by name.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolName | String | 工具的名称。the name of the tool |
McpSchema.Toolio/agentscope/core/tool/mcp/McpClientWrapper.java:161–163close
public abstract void close()
关闭连接并释放相关资源。
Closes this MCP client and releases all resources.
io/agentscope/core/tool/mcp/McpClientWrapper.java:169–170