Class McpException

All Implemented Interfaces:
Serializable

Runtime exception carrying JSON-RPC error fields for mapping to JsonRpcError.
See Also:
  • Constructor Details

    • McpException

      public McpException(int code, String message)
      Constructor.
      Parameters:
      code - JSON-RPC error code.
      message - Error message. Can be null to leave the exception message unset.
    • McpException

      public McpException(int code, String message, Object data)
      Constructor.
      Parameters:
      code - JSON-RPC error code.
      message - Error message. Can be null to leave the exception message unset.
      data - Optional structured error data. Can be null to leave the property unset.
  • Method Details

    • getCode

      public int getCode()
      JSON-RPC error code.
      Returns:
      The code.
    • setCode

      public McpException setCode(int value)
      Sets the JSON-RPC error code.
      Parameters:
      value - The new value.
      Returns:
      This object (for method chaining).
    • getData

      public Object getData()
      Optional structured error data.
      Returns:
      The data, or null if not set.
    • setData

      public McpException setData(Object value)
      Sets optional structured error data.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object (for method chaining).
    • toJsonRpcError

      Converts this exception to a JsonRpcError.
      Returns:
      A new error object. Never null.
    • fromJsonRpcError

      Creates an McpException from a JsonRpcError.
      Parameters:
      e - The source error. Must not be null.
      Returns:
      A new exception containing the same code, message, and data.