类 McpTool
java.lang.Object
io.agentscope.core.tool.mcp.McpTool
- 所有已实现的接口:
AgentTool
AgentTool implementation that wraps an MCP (Model Context Protocol) tool.
This class bridges MCP tools to the AgentScope tool system, allowing
agents to invoke remote MCP tools seamlessly.
Features:
- Converts AgentScope tool calls to MCP protocol calls
- Handles parameter merging with preset arguments
- Converts MCP results to AgentScope ToolResultBlocks
- Supports reactive execution with Mono
Example usage:
McpTool tool = new McpTool(
"get_weather",
"Get current weather for a location",
parametersSchema,
mcpClientWrapper,
Map.of("units", "celsius") // preset args
);
ToolResultBlock result = tool.callAsync(Map.of("location", "Beijing")).block();
-
构造器概要
构造器构造器说明McpTool(String name, String description, Map<String, Object> parameters, McpClientWrapper clientWrapper) Constructs a new McpTool without preset arguments.McpTool(String name, String description, Map<String, Object> parameters, McpClientWrapper clientWrapper, Map<String, Object> presetArguments) Constructs a new McpTool with preset arguments.McpTool(String name, String description, Map<String, Object> parameters, Map<String, Object> outputSchema, McpClientWrapper clientWrapper, Map<String, Object> presetArguments) Constructs a new McpTool with an optional output schema and preset arguments. -
方法概要
修饰符和类型方法说明reactor.core.publisher.Mono<ToolResultBlock> callAsync(ToolCallParam param) Executes this MCP tool asynchronously with the given parameters.convertMcpSchemaToParameters(io.modelcontextprotocol.spec.McpSchema.JsonSchema inputSchema, Set<String> excludeParams) Converts MCP JsonSchema to AgentScope parameters format.Gets the name of the MCP client that provides this tool.Returns the description of this MCP tool.getName()Returns the name of this MCP tool.Gets the optional output schema for this tool in JSON Schema format.Returns the JSON schema parameters for this MCP tool.Gets the preset arguments configured for this tool.
-
构造器详细资料
-
McpTool
public McpTool(String name, String description, Map<String, Object> parameters, McpClientWrapper clientWrapper) Constructs a new McpTool without preset arguments.- 参数:
name- the tool namedescription- the tool descriptionparameters- the JSON schema for tool parametersclientWrapper- the MCP client wrapper
-
McpTool
public McpTool(String name, String description, Map<String, Object> parameters, McpClientWrapper clientWrapper, Map<String, Object> presetArguments) Constructs a new McpTool with preset arguments.- 参数:
name- the tool namedescription- the tool descriptionparameters- the JSON schema for tool parametersclientWrapper- the MCP client wrapperpresetArguments- preset arguments to merge with each call (can be null)
-
McpTool
public McpTool(String name, String description, Map<String, Object> parameters, Map<String, Object> outputSchema, McpClientWrapper clientWrapper, Map<String, Object> presetArguments) Constructs a new McpTool with an optional output schema and preset arguments.- 参数:
name- the tool namedescription- the tool descriptionparameters- the JSON schema for tool parametersoutputSchema- the JSON schema for tool outputs (can be null)clientWrapper- the MCP client wrapperpresetArguments- preset arguments to merge with each call (can be null)
-
-
方法详细资料
-
getName
Returns the name of this MCP tool. -
getDescription
Returns the description of this MCP tool.- 指定者:
getDescription在接口中AgentTool- 返回:
- the tool description
-
getParameters
Returns the JSON schema parameters for this MCP tool.- 指定者:
getParameters在接口中AgentTool- 返回:
- the parameters schema map
-
getOutputSchema
从接口复制的说明:AgentToolGets the optional output schema for this tool in JSON Schema format.Most tools do not expose a structured output schema to models, so the default implementation returns
null. MCP tools can override this to surface the server-providedoutputSchemadefinition.- 指定者:
getOutputSchema在接口中AgentTool- 返回:
- Map representing the JSON Schema for tool outputs, or null if unsupported
-
callAsync
Executes this MCP tool asynchronously with the given parameters.This method merges any preset arguments with the input arguments (input takes precedence), calls the remote MCP tool via the client wrapper, and converts the result to a
ToolResultBlock. If an error occurs, it returns an error result instead of failing. -
getClientName
Gets the name of the MCP client that provides this tool.- 返回:
- the MCP client name
-
getPresetArguments
Gets the preset arguments configured for this tool.- 返回:
- the preset arguments, or null if none configured
-
convertMcpSchemaToParameters
public static Map<String,Object> convertMcpSchemaToParameters(io.modelcontextprotocol.spec.McpSchema.JsonSchema inputSchema, Set<String> excludeParams) Converts MCP JsonSchema to AgentScope parameters format.- 参数:
inputSchema- the MCP JsonSchema- 返回:
- parameters map in AgentScope format
-