Class McpJson
java.lang.Object
dev.langchain4j.mcp.client.transport.McpJson
Bridges between JSON text and Jackson's tree model while both the
deprecated
JsonNode-based transport API and its replacement coexist.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TRe-reads an already-decoded JSON value as the given type.static <T> List<T> convertList(Object value, Class<T> elementType) Re-reads an already-decoded JSON array as a list of the given element type.static <T> Tdeserialize(com.fasterxml.jackson.databind.JsonNode message, Class<T> type) Deprecated, for removal: This API element is subject to removal in a future version.static <T> Tdeserialize(String message, Class<T> type) Deserializes an MCP message into a protocol type.static <T,R> CompletableFuture <R> map(CompletableFuture<T> source, Function<T, R> mapper) Maps a future's value while keeping cancellation linked to the source.static com.fasterxml.jackson.databind.JsonNodestatic StringSerializes an outbound MCP message.Reads a JSON object as plain values.static Object
-
Method Details
-
deserialize
Deserializes an MCP message into a protocol type.The message is taken as it arrived on the wire, so this is a single parse. Reading it into a tree first and then into a type costs two more passes and, for high-precision numbers, is not guaranteed to round-trip.
-
deserialize
@Deprecated(since="1.20.0", forRemoval=true) public static <T> T deserialize(com.fasterxml.jackson.databind.JsonNode message, Class<T> type) Deprecated, for removal: This API element is subject to removal in a future version.usedeserialize(String, Class), which does not expose Jackson types and avoids re-serializing the tree in order to read it.Deserializes an MCP message held as a Jackson 2 tree. -
toValue
- Throws:
IllegalArgumentException- if the text is not valid JSON, orJsonExceptionfrom a codec that reports the typed exceptions.
-
toMap
-
convert
-
convertList
-
serialize
-
parse
-
map
Maps a future's value while keeping cancellation linked to the source. A plainthenApplywould not propagate cancellation upstream, which would leave the transport's response stream open after the client cancels the operation.
-
deserialize(String, Class), which does not expose Jackson types and avoids re-serializing the tree in order to read it.