Class HigressMcpClientWrapper
- All Implemented Interfaces:
AutoCloseable
This wrapper extends McpClientWrapper to connect to Higress's unified MCP service
endpoint (union-tools-search). When semantic search is enabled in Higress, the gateway provides
a special tool x_higress_tool_search that can automatically select the most suitable
MCP tools based on user requests.
The wrapper delegates all MCP operations to an underlying McpClientWrapper instance
(either async or sync), providing a consistent interface for Higress-specific functionality.
Example usage:
HigressMcpClientWrapper client = HigressMcpClientBuilder
.create("higress-mcp")
.sseEndpoint("http://higress-gateway/mcp-servers/union-tools-search/sse")
.build();
// Initialize and list tools
client.initialize().block();
List<McpSchema.Tool> tools = client.listTools().block();
// Call x_higress_tool_search to get recommended tools
McpSchema.CallToolResult result = client.callTool("x_higress_tool_search",
Map.of("query", "查询北京天气")).block();
- See Also:
-
HigressMcpClientBuilderMcpClientWrapper
-
Field Summary
FieldsFields inherited from class io.agentscope.core.tool.mcp.McpClientWrapper
cachedTools, initialized, name, propagateMeta -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>Invokes a tool on the Higress gateway.reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>voidclose()Closes the Higress MCP client and releases all resources.reactor.core.publisher.Mono<Void>Initializes the Higress MCP client connection.booleanChecks if x_higress_tool_search mode is enabled in this client.reactor.core.publisher.Mono<List<io.modelcontextprotocol.spec.McpSchema.Tool>>Lists tools available from the Higress gateway.reactor.core.publisher.Mono<HigressToolSearchResult>searchTools(String query) Searches for tools matching the query and returns parsed result.reactor.core.publisher.Mono<HigressToolSearchResult>searchTools(String query, int topK) Searches for tools matching the query with topK limit.Methods inherited from class io.agentscope.core.tool.mcp.McpClientWrapper
getCachedTool, getName, isInitialized, isPropagateMeta, setPropagateMeta
-
Field Details
-
TOOL_SEARCH_NAME
The name of the Higress tool search tool.- See Also:
-
-
Method Details
-
initialize
Initializes the Higress MCP client connection.This method delegates to the underlying MCP client to establish connection with the Higress gateway and discover available tools.
- Specified by:
initializein classio.agentscope.core.tool.mcp.McpClientWrapper- Returns:
- a Mono that completes when initialization is finished
-
listTools
Lists tools available from the Higress gateway.If
enableToolSearchis true, this method will:- Call x_higress_tool_search with the configured query
- Parse the result to get recommended tools
- Convert and return these tools
If
enableToolSearchis false, this method returns all tools from the MCP server.- Specified by:
listToolsin classio.agentscope.core.tool.mcp.McpClientWrapper- Returns:
- a Mono emitting the list of available tools
-
callTool
public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments) Invokes a tool on the Higress gateway.This method can be used to call any tool available on the gateway, including the
x_higress_tool_searchtool for intelligent tool selection.- Specified by:
callToolin classio.agentscope.core.tool.mcp.McpClientWrapper- Parameters:
toolName- the name of the tool to callarguments- the arguments to pass to the tool- Returns:
- a Mono emitting the tool call result
-
callTool
public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> callTool(String toolName, Map<String, Object> arguments, Map<String, Object> meta) - Specified by:
callToolin classio.agentscope.core.tool.mcp.McpClientWrapper
-
close
public void close()Closes the Higress MCP client and releases all resources.This method closes the underlying delegate client and clears all cached data.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classio.agentscope.core.tool.mcp.McpClientWrapper
-
isToolSearchEnabled
public boolean isToolSearchEnabled()Checks if x_higress_tool_search mode is enabled in this client.When enabled, listTools() will call x_higress_tool_search to get semantically relevant tools instead of returning all tools.
- Returns:
- true if tool search mode is enabled
-
searchTools
Searches for tools matching the query and returns parsed result.This method calls x_higress_tool_search and parses the response into a structured
HigressToolSearchResult.- Parameters:
query- the user query to find matching tools (required)- Returns:
- a Mono emitting the parsed tool search result
-
searchTools
Searches for tools matching the query with topK limit.- Parameters:
query- the user query to find matching tools (required)topK- the maximum number of tools to return- Returns:
- a Mono emitting the parsed tool search result
-