Package dev.langchain4j.mcp.client
Class DefaultMcpClient.Builder
java.lang.Object
dev.langchain4j.mcp.client.DefaultMcpClient.Builder
- Enclosing class:
DefaultMcpClient
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionautoHealthCheck
(boolean autoHealthCheck) Enables or disables the automatic health check feature.autoHealthCheckInterval
(Duration interval) Sets the interval for the automatic health checks.build()
clientName
(String clientName) Sets the name that the client will use to identify itself to the MCP server in the initialization message.clientVersion
(String clientVersion) Sets the version string that the client will use to identify itself to the MCP server in the initialization message.initializationTimeout
(Duration initializationTimeout) Sets the timeout for initializing the client.Sets a unique identifier for the client.logHandler
(McpLogMessageHandler logHandler) Sets the log message handler for the client.pingTimeout
(Duration pingTimeout) The timeout to apply when waiting for a ping response.promptsTimeout
(Duration promptsTimeout) Sets the timeout for prompt-related operations (listing prompts as well as rendering the contents of a prompt).protocolVersion
(String protocolVersion) Sets the protocol version that the client will advertise in the initialization message.reconnectInterval
(Duration reconnectInterval) The delay before attempting to reconnect after a failed connection.resourcesTimeout
(Duration resourcesTimeout) Sets the timeout for resource-related operations (listing resources as well as reading the contents of a resource).Specify the initial set of roots that are available to the server upon its request.toolExecutionTimeout
(Duration toolExecutionTimeout) Sets the timeout for tool execution.toolExecutionTimeoutErrorMessage
(String toolExecutionTimeoutErrorMessage) Sets the error message to return when a tool execution times out.transport
(McpTransport transport) Sets the transport protocol to use for communicating with the MCP server.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
transport
Sets the transport protocol to use for communicating with the MCP server. This is a mandatory parameter. A successfully constructed DefaultMcpClient takes over the resource ownership of this transport and will close it when it itself is closed. -
key
Sets a unique identifier for the client. If none is provided, a UUID will be automatically generated. -
clientName
Sets the name that the client will use to identify itself to the MCP server in the initialization message. The default value is "langchain4j". -
clientVersion
Sets the version string that the client will use to identify itself to the MCP server in the initialization message. The default value is "1.0". -
protocolVersion
Sets the protocol version that the client will advertise in the initialization message. The default value right now is "2024-11-05", but will change over time in later langchain4j versions. -
initializationTimeout
Sets the timeout for initializing the client. The default value is 30 seconds. -
toolExecutionTimeout
Sets the timeout for tool execution. This value applies to each tool execution individually. The default value is 60 seconds. A value of zero means no timeout. -
resourcesTimeout
Sets the timeout for resource-related operations (listing resources as well as reading the contents of a resource). The default value is 60 seconds. A value of zero means no timeout. -
promptsTimeout
Sets the timeout for prompt-related operations (listing prompts as well as rendering the contents of a prompt). The default value is 60 seconds. A value of zero means no timeout. -
toolExecutionTimeoutErrorMessage
public DefaultMcpClient.Builder toolExecutionTimeoutErrorMessage(String toolExecutionTimeoutErrorMessage) Sets the error message to return when a tool execution times out. The default value is "There was a timeout executing the tool". -
logHandler
Sets the log message handler for the client. -
pingTimeout
The timeout to apply when waiting for a ping response. Currently, this is only used in the health check - if the server does not send a pong within this timeframe, the health check will fail. The timeout is 10 seconds. -
reconnectInterval
The delay before attempting to reconnect after a failed connection. The default is 5 seconds. -
autoHealthCheck
Enables or disables the automatic health check feature. When enabled, the client will periodically send ping messages to the server to ensure the connection is alive, and will attempt to reconnect if it's not. The default is enabled -
autoHealthCheckInterval
Sets the interval for the automatic health checks. This is only used when the auto health check feature is enabled. The default is 30 seconds -
roots
Specify the initial set of roots that are available to the server upon its request. -
build
-