Class McpException

All Implemented Interfaces:
Serializable

public class McpException extends LangChain4jException
A business exception raised over the MCP protocol
See Also:
  • Constructor Details

    • McpException

      public McpException(int errorCode, String errorMessage)
    • 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.
      use withErrorData(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-RPC error.data member 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

      public String errorMessage()
    • errorDataAsJson

      public @Nullable String errorDataAsJson()
      Returns the JSON-RPC error.data member as JSON text.
    • errorDataAsMap

      public @Nullable Map<String,Object> errorDataAsMap()
      Returns the JSON-RPC error.data member 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. Use errorDataAsObject() to read those.
    • errorDataAsObject

      public @Nullable Object errorDataAsObject()
      Returns the JSON-RPC error.data member as a plain JDK value: a Map, a List, a boxed primitive, or null. JSON-RPC allows error.data to be any value, so this is the accessor that can represent all of them.
    • 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.