AS AgentScopeAPI 手册 / API Reference

McpSyncClientWrapper

public class McpSyncClientWrapper extends McpClientWrapper
源码Source io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:41–206

MCP 同步客户端包装器,让智能体以受控方式调用外部能力。位于 io.agentscope.core.tool.mcp 包,继承自 McpClientWrapper。核心成员包括 initialize、listTools、callTool、close、McpSyncClientWrapper。

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));
`

构造器摘要Constructor Summary

构造器Constructor说明Description
public McpSyncClientWrapper(String name, McpSyncClient client)
初始化 `McpSyncClientWrapper` 实例。
Constructs a new synchronous MCP client wrapper.

方法摘要Method Summary

方法Method说明Description
public Mono<Void> initialize()
初始化 `McpSyncClientWrapper` 实例。
Initializes the sync MCP client connection and caches available tools.
public Mono<List<McpSchema.Tool>> listTools()
列出工具。
Lists all tools available from the MCP server.
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments)
调用工具。
Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono.
public Mono<McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta)
调用工具。
Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono.
public void close()
关闭连接并释放相关资源。
Closes the MCP client connection and releases all resources.

构造器详情Constructor Detail

McpSyncClientWrapper

public McpSyncClientWrapper(String name, McpSyncClient client)

初始化 McpSyncClientWrapper 实例。

Constructs a new synchronous MCP client wrapper.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。unique identifier for this client
clientMcpSyncClient客户端(类型 `McpSyncClient`)。the underlying sync MCP client
源码Source io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:53–56

方法详情Method Detail

initialize

public Mono<Void> initialize()

初始化 McpSyncClientWrapper 实例。

Initializes the sync 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/McpSyncClientWrapper.java:67–99

listTools

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

列出工具。

Lists all tools available from the MCP server.

返回Returns Mono<List<McpSchema.Tool>>
返回Mono>。a Mono emitting the list of available tools
抛出Throws
  • IllegalStateException 当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
源码Source io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:110–119

callTool

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

调用工具。

Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono.

参数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 (may contain error information)
抛出Throws
  • IllegalStateException 当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
源码Source io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:132–135

callTool

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

调用工具。

Invokes a tool on the MCP server, wrapping the blocking call in a reactive Mono.

参数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`)。additional metadata to pass to the tool
返回Returns Mono<McpSchema.CallToolResult>
返回Mono。a Mono emitting the tool call result (may contain error information)
抛出Throws
  • IllegalStateException 当if 客户端是不已初始化时抛出 `IllegalStateException`。if the client is not initialized
源码Source io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:149–183

close

public void close()

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

Closes the MCP client connection and releases all resources.

源码Source io/agentscope/core/tool/mcp/McpSyncClientWrapper.java:191–205

继承成员Inherited Members

基于官方固定版本源码静态生成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.