Class StreamableHttpMcpTransport
java.lang.Object
dev.langchain4j.mcp.client.transport.http.StreamableHttpMcpTransport
- All Implemented Interfaces:
McpTransport, Closeable, AutoCloseable
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidPerforms transport-specific health checks, if applicable.voidclose()voidSends a message that does not expect a response from the server - either a client-initiated notification or a response to a server-initiated request.voidexecuteOperationWithoutResponse(McpClientMessage operation) Sends a message that does not expect a response from the server - either a client-initiated notification or a response to a server-initiated request.CompletableFuture<com.fasterxml.jackson.databind.JsonNode> Executes an operation that expects a response from the server.CompletableFuture<com.fasterxml.jackson.databind.JsonNode> executeOperationWithResponse(McpClientMessage operation) Executes an operation that expects a response from the server.Returns the MCP session ID assigned by the server, ornullif no session has been established yet (or the server does not use sessions).CompletableFuture<com.fasterxml.jackson.databind.JsonNode> initialize(McpInitializeRequest operation) Sends the "initialize" message to the MCP server to negotiate capabilities, supported protocol version etc.voidvoidsetMcpSessionId(String mcpSessionId) Sets the MCP session ID to be sent on subsequent requests via theMcp-Session-Idheader.voidstart(McpOperationHandler operationHandler) Creates a connection to the MCP server (runs the server as a subprocess if needed).
-
Constructor Details
-
StreamableHttpMcpTransport
-
-
Method Details
-
start
Description copied from interface:McpTransportCreates a connection to the MCP server (runs the server as a subprocess if needed). This does NOT yet send the "initialize" message to negotiate capabilities.- Specified by:
startin interfaceMcpTransport
-
initialize
public CompletableFuture<com.fasterxml.jackson.databind.JsonNode> initialize(McpInitializeRequest operation) Description copied from interface:McpTransportSends the "initialize" message to the MCP server to negotiate capabilities, supported protocol version etc. When this method returns successfully, the transport is fully initialized and ready to be used. This has to be called AFTER the "start" method.- Specified by:
initializein interfaceMcpTransport
-
executeOperationWithResponse
public CompletableFuture<com.fasterxml.jackson.databind.JsonNode> executeOperationWithResponse(McpClientMessage operation) Description copied from interface:McpTransportExecutes an operation that expects a response from the server.- Specified by:
executeOperationWithResponsein interfaceMcpTransport
-
executeOperationWithResponse
public CompletableFuture<com.fasterxml.jackson.databind.JsonNode> executeOperationWithResponse(McpCallContext context) Description copied from interface:McpTransportExecutes an operation that expects a response from the server.- Specified by:
executeOperationWithResponsein interfaceMcpTransport
-
executeOperationWithoutResponse
Description copied from interface:McpTransportSends a message that does not expect a response from the server - either a client-initiated notification or a response to a server-initiated request.- Specified by:
executeOperationWithoutResponsein interfaceMcpTransport
-
executeOperationWithoutResponse
Description copied from interface:McpTransportSends a message that does not expect a response from the server - either a client-initiated notification or a response to a server-initiated request.- Specified by:
executeOperationWithoutResponsein interfaceMcpTransport
-
checkHealth
public void checkHealth()Description copied from interface:McpTransportPerforms transport-specific health checks, if applicable. This is called by `McpClient.checkHealth()` as the first check before performing a check by sending a 'ping' over the MCP protocol. The purpose is that the transport may have some specific and faster ways to detect that it is broken, like for example, the STDIO transport can fail the check if it detects that the server subprocess isn't alive anymore.- Specified by:
checkHealthin interfaceMcpTransport
-
onFailure
- Specified by:
onFailurein interfaceMcpTransport
-
getMcpSessionId
Returns the MCP session ID assigned by the server, ornullif no session has been established yet (or the server does not use sessions). The session ID is captured from theMcp-Session-Idresponse header during initialization and reused on subsequent requests via the same header. -
setMcpSessionId
Sets the MCP session ID to be sent on subsequent requests via theMcp-Session-Idheader. This is intended for scenarios where a session obtained elsewhere (for example, in another process or pod) needs to be resumed by this transport, allowing stateless deployments without sticky sessions. -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
builder
-