Consolidate McpClientException/McpServerException into McpException (#209)

This commit is contained in:
Stephen Toub 2025-04-03 21:10:57 -04:00 • committed by GitHub
commit 8fcdf95785
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,56 @@
namespace ModelContextProtocol;
/// <summary>
/// An exception that is thrown when an MCP configuration or protocol error occurs.
/// </summary>
public class McpException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="McpException"/> class.
/// </summary>
public McpException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="McpException"/> class with a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public McpException(string message) : base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="McpException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
public McpException(string message, Exception? innerException) : base(message, innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="McpException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="errorCode">A JSON-RPC error code, if this exception represents a JSON-RPC error.</param>
public McpException(string message, int? errorCode) : this(message, null, errorCode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="McpException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
/// <param name="errorCode">A JSON-RPC error code, if this exception represents a JSON-RPC error.</param>
public McpException(string message, Exception? innerException, int? errorCode) : base(message, innerException)
{
ErrorCode = errorCode;
}
/// <summary>
/// Gets the error code if this exception was caused by a JSON-RPC error response.
/// </summary>
public int? ErrorCode { get; }
}