Class HttpMcpTransport
java.lang.Object
dev.langchain4j.mcp.client.transport.http.HttpMcpTransport
- All Implemented Interfaces:
McpTransport
,Closeable
,AutoCloseable
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancelOperation
(long operationId) Cancels a running operation on the server (sends a 'notifications/cancelled' message to the server).void
close()
CompletableFuture
<com.fasterxml.jackson.databind.JsonNode> executeTool
(McpCallToolRequest operation) Executes a tool on the MCP server.CompletableFuture
<com.fasterxml.jackson.databind.JsonNode> initialize
(McpInitializeRequest operation) Sends the "initialize" message to the MCP server to negotiate capabilities, supported protocol version etc.CompletableFuture
<com.fasterxml.jackson.databind.JsonNode> listTools
(McpListToolsRequest operation) Requests a list of available tools from the MCP server.void
start
(McpOperationHandler messageHandler) Creates a connection to the MCP server (runs the server as a subprocess if needed).
-
Constructor Details
-
HttpMcpTransport
-
-
Method Details
-
start
Description copied from interface:McpTransport
Creates 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:
start
in interfaceMcpTransport
-
initialize
public CompletableFuture<com.fasterxml.jackson.databind.JsonNode> initialize(McpInitializeRequest operation) Description copied from interface:McpTransport
Sends 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:
initialize
in interfaceMcpTransport
-
listTools
public CompletableFuture<com.fasterxml.jackson.databind.JsonNode> listTools(McpListToolsRequest operation) Description copied from interface:McpTransport
Requests a list of available tools from the MCP server.- Specified by:
listTools
in interfaceMcpTransport
-
executeTool
public CompletableFuture<com.fasterxml.jackson.databind.JsonNode> executeTool(McpCallToolRequest operation) Description copied from interface:McpTransport
Executes a tool on the MCP server.- Specified by:
executeTool
in interfaceMcpTransport
- Parameters:
operation
- the tool execution request
-
cancelOperation
public void cancelOperation(long operationId) Description copied from interface:McpTransport
Cancels a running operation on the server (sends a 'notifications/cancelled' message to the server). This does not expect any response from the server.- Specified by:
cancelOperation
in interfaceMcpTransport
- Parameters:
operationId
- The ID of the operation to be cancelled.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-