namespace ModelContextProtocol; /// /// Represents an exception that is thrown when a Model Context Protocol (MCP) error occurs. /// public class McpException : Exception { /// /// Initializes a new instance of the class. /// public McpException() { } /// /// Initializes a new instance of the class with a specified error message. /// /// The message that describes the error. public McpException(string message) : base(message) { } /// /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. /// /// The message that describes the error. /// The exception that is the cause of the current exception, or a null reference if no inner exception is specified. public McpException(string message, Exception? innerException) : base(message, innerException) { } /// /// Initializes a new instance of the class with a specified error message and JSON-RPC error code. /// /// The message that describes the error. /// A JSON-RPC error code from class. public McpException(string message, int? errorCode) : this(message, null, errorCode) { } /// /// Initializes a new instance of the class with a specified error message, inner exception, and JSON-RPC error code. /// /// The message that describes the error. /// The exception that is the cause of the current exception, or a null reference if no inner exception is specified. /// A JSON-RPC error code from class. public McpException(string message, Exception? innerException, int? errorCode) : base(message, innerException) { ErrorCode = errorCode; } /// /// Gets the JSON-RPC error code associated with this exception. /// /// /// A standard JSON-RPC error code, or if the exception wasn't caused by a JSON-RPC error. /// /// /// This property contains a standard JSON-RPC error code as defined in the MCP specification. Common error codes include: /// /// -32700: Parse error - Invalid JSON received /// -32600: Invalid request - The JSON is not a valid Request object /// -32601: Method not found - The method does not exist or is not available /// -32602: Invalid params - Invalid method parameters /// -32603: Internal error - Internal JSON-RPC error /// /// public int? ErrorCode { get; } }