AS AgentScopeAPI 手册 / API Reference

McpClientWrapper

public abstract class McpClientWrapper implements AutoCloseable
源码Source 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
name
final
String
名称字段。
Unique identifier for this MCP client
cachedTools
final
Map<String, McpSchema.Tool>
工具可用来自此 MCP 服务端的缓存。
Cache of tools available from this MCP server
initialized
volatile
boolean
已初始化字段。
Flag indicating whether the client has been initialized
propagateMeta
volatile
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
final

名称字段。声明为 protected final String name。

Unique identifier for this MCP client

源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:43

cachedTools

protected final Map<String, McpSchema.Tool> cachedTools
final

工具可用来自此 MCP 服务端的缓存。

Cache of tools available from this MCP server

源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:46

initialized

protected volatile boolean initialized
volatile

已初始化字段。声明为 protected volatile boolean initialized。

Flag indicating whether the client has been initialized

源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:49

propagateMeta

protected volatile boolean propagateMeta
volatile

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.

源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:61

构造器详情Constructor Detail

McpClientWrapper

protected McpClientWrapper(String name)

初始化 McpClientWrapper 实例。

Constructs a new MCP client wrapper.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。unique identifier for this client
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:68–71

方法详情Method Detail

getName

public String getName()

获取名称。

Gets the unique name of this MCP client.

返回Returns String
客户端名称。the client name
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:78–80

isInitialized

public boolean isInitialized()

判断是否已初始化。

Checks if this client has been initialized.

返回Returns boolean
返回布尔值,表示判断结果。true if initialized, false otherwise
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:87–89

isPropagateMeta

public boolean isPropagateMeta()

判断是否 isPropagateMeta。

Checks whether request metadata is propagated to this MCP server.

返回Returns boolean
返回布尔值,表示判断结果。true if metadata (`McpMeta` entries and the tool-call id) may be included in tool call requests over this connection, false otherwise
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:101–103

setPropagateMeta

public void setPropagateMeta(boolean propagateMeta)

设置 setPropagateMeta。

Configures whether request metadata is propagated to this MCP server.

参数Parameters
名称Name类型Type说明Description
propagateMetabooleanpropagate 元数据(类型 `boolean`)。true to propagate metadata (default), false to omit the `meta` field entirely from tool call requests
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:115–117

initialize

public abstract Mono<Void> initialize()
abstract

初始化 McpClientWrapper 实例。

Initializes the MCP client connection and caches available tools.

返回Returns Mono<Void>
返回Mono。a Mono that completes when initialization is finished
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:125

listTools

public abstract Mono<List<McpSchema.Tool>> listTools()
abstract

列出工具。

Lists all tools available from this MCP server.

返回Returns Mono<List<McpSchema.Tool>>
返回Mono>。a Mono emitting the list of available tools
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:132

callTool

public abstract Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments)
abstract

调用工具。

Invokes a tool on the MCP server.

参数Parameters
名称Name类型Type说明Description
toolNameString工具到调用的名称。the name of the tool to call
argumentsMap<String, Object>参数(类型 `Map`)。the arguments to pass to the tool
返回Returns Mono<McpSchema.CallToolResult>
返回Mono。a Mono emitting the tool call result
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:141–142

callTool

public abstract Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta)
abstract

调用工具。

Invokes a tool on the MCP server.

参数Parameters
名称Name类型Type说明Description
toolNameString工具到调用的名称。the name of the tool to call
argumentsMap<String, Object>参数(类型 `Map`)。the arguments to pass to the tool
metaMap<String, Object>元数据(类型 `Map`)。the metadata to pass to the tool
返回Returns Mono<McpSchema.CallToolResult>
返回Mono。a Mono emitting the tool call result
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:152–153

getCachedTool

public McpSchema.Tool getCachedTool(String toolName)

获取已缓存工具定义通过名称。

Gets a cached tool definition by name.

参数Parameters
名称Name类型Type说明Description
toolNameString工具的名称。the name of the tool
返回Returns McpSchema.Tool
返回McpSchema.工具。the tool definition, or null if not found
源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:161–163

close

public abstract void close()
abstract

关闭连接并释放相关资源。

Closes this MCP client and releases all resources.

源码Source io/agentscope/core/tool/mcp/McpClientWrapper.java:169–170
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.