Class StreamableHttpMcpTransport.Builder

java.lang.Object
dev.langchain4j.mcp.client.transport.http.StreamableHttpMcpTransport.Builder
Enclosing class:
StreamableHttpMcpTransport

public static class StreamableHttpMcpTransport.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • url

      The URL of the MCP server.
    • customHeaders

      public StreamableHttpMcpTransport.Builder customHeaders(Map<String,String> customHeaders)
      The request headers of the MCP server.
    • customHeaders

      public StreamableHttpMcpTransport.Builder customHeaders(Supplier<Map<String,String>> customHeadersSupplier)
      A supplier for dynamic request headers of the MCP server. The supplier is called for each request, allowing headers to be updated dynamically.
    • customHeaders

      public StreamableHttpMcpTransport.Builder customHeaders(McpHeadersSupplier customHeadersSupplier)
      A supplier for dynamic request headers of the MCP server. The supplier is called for each request, allowing headers to be updated dynamically.
    • timeout

      public StreamableHttpMcpTransport.Builder timeout(Duration timeout)
      The connection timeout (applied on the http client level). Application-level timeouts are handled by the MCP client itself.
    • logRequests

      public StreamableHttpMcpTransport.Builder logRequests(boolean logRequests)
      Whether to log all requests that are sent over this transport.
    • logResponses

      public StreamableHttpMcpTransport.Builder logResponses(boolean logResponses)
      Whether to log all responses received over this transport.
    • logger

      public StreamableHttpMcpTransport.Builder logger(org.slf4j.Logger logger)
      Sets a custom Logger to be used for traffic logging (both requests and responses). This logger will be used for both regular HTTP responses and Server-Sent Events (SSE) traffic. If not specified, a default logger will be used.
      Parameters:
      logger - an alternate Logger to be used instead of the default one provided by Langchain4J for traffic logging.
      Returns:
      this.
    • executor

      public StreamableHttpMcpTransport.Builder executor(Executor executor)
      An optional Executor that will be used for executing requests and handling responses. It will also be used for scheduling auto-reconnect attempts of the subsidiary SSE channel if that is enabled. If not provided, a default shared executor will be used.
    • sslContext

      public StreamableHttpMcpTransport.Builder sslContext(SSLContext sslContext)
      Supplies a custom SSLContext used when establishing HTTPS connections to the MCP server, allowing private CAs or certificates.
    • setHttpVersion1_1

      public StreamableHttpMcpTransport.Builder setHttpVersion1_1()
      Forces the transport to use HTTP/1.1 instead of the default HTTP/2.
    • subsidiaryChannel

      public StreamableHttpMcpTransport.Builder subsidiaryChannel(boolean subsidiaryChannelEnabled)
      Enables or disables the subsidiary SSE channel. When enabled, the transport will open an HTTP GET-based SSE stream after initialization, allowing the server to send notifications and requests to the client without the client first sending data via HTTP POST. If the server does not support the subsidiary channel (returns 405), the transport will log a warning and continue without it. If the stream breaks after being successfully established, the transport will automatically attempt to reconnect. Defaults to false.
    • build