Class McpJson
java.lang.Object
dev.langchain4j.mcp.client.transport.McpJson
Reads and writes MCP payloads through the pluggable JSON codec.
-
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(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 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.
-
toValue
- Throws:
IllegalArgumentException- if the text is not valid JSON, orJsonExceptionfrom a codec that reports the typed exceptions.
-
toMap
-
convert
-
convertList
-
serialize
-
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.
-