Class McpException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
dev.langchain4j.exception.LangChain4jException
dev.langchain4j.mcp.client.McpException
- All Implemented Interfaces:
Serializable
A business exception raised over the MCP protocol
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMcpException(int errorCode, String errorMessage) McpException(int errorCode, String errorMessage, @Nullable com.fasterxml.jackson.databind.JsonNode errorData) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionint@Nullable com.fasterxml.jackson.databind.JsonNodeDeprecated, for removal: This API element is subject to removal in a future version.useerrorDataAsMap()orerrorDataAsJson().@Nullable StringReturns the JSON-RPCerror.datamember as JSON text.Returns the JSON-RPCerror.datamember as plain values, so callers do not need a JSON library.@Nullable Objectstatic McpExceptionwithErrorData(int errorCode, String errorMessage, @Nullable String errorDataAsJson) Creates an exception carrying the JSON-RPCerror.datamember as JSON text.Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
McpException
-
McpException
@Deprecated(since="1.20.0", forRemoval=true) public McpException(int errorCode, String errorMessage, @Nullable com.fasterxml.jackson.databind.JsonNode errorData) Deprecated, for removal: This API element is subject to removal in a future version.usewithErrorData(int, String, String), which does not expose Jackson types.
-
-
Method Details
-
withErrorData
public static McpException withErrorData(int errorCode, String errorMessage, @Nullable String errorDataAsJson) Creates an exception carrying the JSON-RPCerror.datamember as JSON text.This is a factory rather than a constructor so that
new McpException(code, message, null)keeps resolving to a single constructor and continues to compile. -
errorCode
public int errorCode() -
errorMessage
-
errorDataAsJson
Returns the JSON-RPCerror.datamember as JSON text. -
errorDataAsMap
Returns the JSON-RPCerror.datamember as plain values, so callers do not need a JSON library.- Returns:
- null when there is no
error.data, and also when it is not a JSON object - JSON-RPC allows any value there. UseerrorDataAsObject()to read those.
-
errorDataAsObject
-
errorData
@Deprecated(since="1.20.0", forRemoval=true) public @Nullable com.fasterxml.jackson.databind.JsonNode errorData()Deprecated, for removal: This API element is subject to removal in a future version.useerrorDataAsMap()orerrorDataAsJson().
-
withErrorData(int, String, String), which does not expose Jackson types.