Class McpOperationHandler
java.lang.Object
dev.langchain4j.mcp.client.transport.McpOperationHandler
Handles incoming messages from the MCP server.
A transport calls onMessage(String) for every message it receives, and
expectResponse(Long, java.util.concurrent.CompletableFuture) before sending a request,
to register the id whose response it is waiting for.
The handle and startOperation methods do the same through Jackson's
JsonNode and are deprecated.
-
Constructor Summary
ConstructorsConstructorDescriptionMcpOperationHandler(Map<Long, CompletableFuture<String>> pendingOperations, Supplier<List<McpRoot>> roots, McpTransport transport, Consumer<McpLogMessage> logMessageConsumer, Runnable onToolListUpdate, Runnable onResourceListUpdate, Runnable onPromptListUpdate, Consumer<String> onResourceUpdate, McpProgressHandler progressHandler, Runnable onServerPing, Runnable onServerRootsList, BiConsumer<Long, String> onServerCancelled, BiConsumer<Long, Map<String, Object>> onSubscriptionAcknowledged) -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelAllPendingOperations(String reason) voidexpectResponse(Long id, CompletableFuture<String> future) Registers a client-initiated request whose response is awaited; the future is completed with the response as unparsed JSON text.voidhandle(com.fasterxml.jackson.databind.JsonNode message) Deprecated, for removal: This API element is subject to removal in a future version.voidHandles an inbound message from the server, taken exactly as it arrived on the wire, so that a transport does not have to parse it first.voidstartOperation(Long id, CompletableFuture<com.fasterxml.jackson.databind.JsonNode> future) Deprecated, for removal: This API element is subject to removal in a future version.useexpectResponse(Long, CompletableFuture)instead, which does not expose Jackson types.
-
Constructor Details
-
McpOperationHandler
public McpOperationHandler(Map<Long, CompletableFuture<String>> pendingOperations, Supplier<List<McpRoot>> roots, McpTransport transport, Consumer<McpLogMessage> logMessageConsumer, Runnable onToolListUpdate, Runnable onResourceListUpdate, Runnable onPromptListUpdate, Consumer<String> onResourceUpdate, McpProgressHandler progressHandler, Runnable onServerPing, Runnable onServerRootsList, BiConsumer<Long, String> onServerCancelled, BiConsumer<Long, Map<String, Object>> onSubscriptionAcknowledged)
-
-
Method Details
-
handle
@Deprecated(since="1.20.0", forRemoval=true) public void handle(com.fasterxml.jackson.databind.JsonNode message) Deprecated, for removal: This API element is subject to removal in a future version.useonMessage(String)instead, which does not expose Jackson types.Handles an inbound message from the server. -
onMessage
Handles an inbound message from the server, taken exactly as it arrived on the wire, so that a transport does not have to parse it first.Valid JSON that is not a JSON-RPC object - a batch array, a scalar, a bare null - is ignored. Text that is not valid JSON at all throws, so that the transport can decide: fail the pending operation, or log and keep reading.
- Throws:
IllegalArgumentException- if the message is not valid JSON, orJsonExceptionfrom a codec that reports the typed exceptions.
-
startOperation
@Deprecated(since="1.20.0", forRemoval=true) public void startOperation(Long id, CompletableFuture<com.fasterxml.jackson.databind.JsonNode> future) Deprecated, for removal: This API element is subject to removal in a future version.useexpectResponse(Long, CompletableFuture)instead, which does not expose Jackson types.Registers a client-initiated request whose response is awaited. -
expectResponse
Registers a client-initiated request whose response is awaited; the future is completed with the response as unparsed JSON text. -
cancelAllPendingOperations
-
onMessage(String)instead, which does not expose Jackson types.