Class HigressMcpClientBuilder
HigressMcpClientWrapper instances.
This builder follows the same pattern as McpClientBuilder in agentscope-core,
providing a fluent API for configuring and building Higress MCP clients.
Supports two transport types:
- SSE (Server-Sent Events) - for stateful connections with server push
- StreamableHTTP - for stateless HTTP streaming
Example usage with SSE transport:
HigressMcpClientWrapper client = HigressMcpClientBuilder
.create("higress-mcp")
.sseEndpoint("http://higress-gateway/mcp-servers/union-tools-search/sse")
.build();
Example usage with StreamableHTTP transport:
HigressMcpClientWrapper client = HigressMcpClientBuilder
.create("higress-mcp")
.streamableHttpEndpoint("http://higress-gateway/mcp-servers/union-tools-search")
.build();
Example with authentication:
HigressMcpClientWrapper client = HigressMcpClientBuilder
.create("higress-mcp")
.sseEndpoint("http://higress-gateway/mcp-servers/union-tools-search/sse")
.header("Authorization", "Bearer " + token)
.header("X-Api-Key", apiKey)
.timeout(Duration.ofSeconds(60))
.buildAsync()
.block();
- See Also:
-
HigressMcpClientWrapperMcpClientBuilder
-
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<HigressMcpClientWrapper>Builds an asynchronousHigressMcpClientWrapperinstance.Builds a synchronousHigressMcpClientWrapperinstance (blocking operation).static HigressMcpClientBuilderCreates a new builder with the specified client name.Adds an HTTP header to be sent with each request.Sets multiple HTTP headers at once.initializationTimeout(Duration timeout) Sets the initialization timeout duration.queryParam(String key, String value) Adds a query parameter to the URL.queryParams(Map<String, String> queryParams) Sets multiple query parameters at once.sseEndpoint(String endpoint) Configures SSE (Server-Sent Events) transport endpoint.streamableHttpEndpoint(String endpoint) Configures StreamableHTTP transport endpoint.Sets the request timeout duration.toolSearch(String query) Enables tool search with the specified query.toolSearch(String query, int topK) Enables tool search with the specified query and topK.
-
Method Details
-
create
Creates a new builder with the specified client name.- Parameters:
clientName- unique identifier for the MCP client- Returns:
- new builder instance
- Throws:
IllegalArgumentException- if clientName is null or empty
-
sseEndpoint
Configures SSE (Server-Sent Events) transport endpoint.SSE transport is recommended for scenarios requiring real-time server push and stateful connections.
- Parameters:
endpoint- the SSE endpoint URL (e.g., "http://higress-gateway/mcp-servers/union-tools-search/sse")- Returns:
- this builder for method chaining
-
streamableHttpEndpoint
Configures StreamableHTTP transport endpoint.StreamableHTTP transport is suitable for stateless HTTP streaming scenarios.
- Parameters:
endpoint- the StreamableHTTP endpoint URL (e.g., "http://higress-gateway/mcp-servers/union-tools-search")- Returns:
- this builder for method chaining
-
header
Adds an HTTP header to be sent with each request.Common use cases include authentication headers:
header("Authorization", "Bearer " + token)header("X-Api-Key", apiKey)
- Parameters:
key- header namevalue- header value- Returns:
- this builder for method chaining
-
headers
Sets multiple HTTP headers at once.- Parameters:
headers- map of header name-value pairs- Returns:
- this builder for method chaining
-
queryParam
Adds a query parameter to the URL.Query parameters added via this method will be merged with any existing query parameters in the URL.
Example:
HigressMcpClientWrapper client = HigressMcpClientBuilder .create("higress") .streamableHttpEndpoint("http://gateway/mcp") .queryParam("token", "abc123") .queryParam("env", "prod") .build();- Parameters:
key- query parameter namevalue- query parameter value- Returns:
- this builder for method chaining
-
queryParams
Sets multiple query parameters at once.- Parameters:
queryParams- map of query parameter name-value pairs- Returns:
- this builder for method chaining
-
timeout
Sets the request timeout duration.This timeout applies to individual MCP requests (tool calls, list tools, etc.). Default is 120 seconds.
- Parameters:
timeout- timeout duration- Returns:
- this builder for method chaining
-
initializationTimeout
Sets the initialization timeout duration.This timeout applies to the client initialization process. Default is 30 seconds.
- Parameters:
timeout- timeout duration- Returns:
- this builder for method chaining
-
toolSearch
Enables tool search with the specified query.When enabled, listTools() will call x_higress_tool_search with the query, and return only the semantically relevant tools (default top 10).
Example:
HigressMcpClientWrapper client = HigressMcpClientBuilder .create("higress") .streamableHttpEndpoint(endpoint) .toolSearch("查询天气") .build();- Parameters:
query- the search query describing what tools are needed- Returns:
- this builder for method chaining
-
toolSearch
Enables tool search with the specified query and topK.Example:
HigressMcpClientWrapper client = HigressMcpClientBuilder .create("higress") .streamableHttpEndpoint(endpoint) .toolSearch("查询天气", 5) .build();- Parameters:
query- the search query describing what tools are neededtopK- the maximum number of tools to return (must be positive)- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if topK is not positive
-
buildAsync
Builds an asynchronousHigressMcpClientWrapperinstance.This method returns a
Monothat, when subscribed:- Validates the configuration
- Creates the underlying MCP client using
McpClientBuilder - Wraps it in a
HigressMcpClientWrapper - Initializes the client
Example usage:
HigressMcpClientWrapper client = HigressMcpClientBuilder .create("higress-mcp") .streamableHttpEndpoint(endpoint) .buildAsync() .block();- Returns:
- Mono emitting the configured HigressMcpClientWrapper instance
- Throws:
IllegalArgumentException- if endpoint is not configuredIllegalStateException- if transport type is not configured
-
buildSync
Builds a synchronousHigressMcpClientWrapperinstance (blocking operation).This method:
- Validates the configuration
- Creates the underlying synchronous MCP client using
McpClientBuilder - Wraps it in a
HigressMcpClientWrapper - Initializes the client
Example usage:
HigressMcpClientWrapper client = HigressMcpClientBuilder .create("higress-mcp") .streamableHttpEndpoint(endpoint) .buildSync();- Returns:
- configured and initialized HigressMcpClientWrapper instance
- Throws:
IllegalArgumentException- if endpoint is not configuredIllegalStateException- if transport type is not configured
-