Class McpException
- Namespace
- ModelContextProtocol
- Assembly
- ModelContextProtocol.Core.dll
Represents an exception that is thrown when a Model Context Protocol (MCP) error occurs.
public class McpException : Exception, ISerializable
- Inheritance
-
McpException
- Implements
- Derived
- Inherited Members
Remarks
The Message from a McpException might be propagated to the remote endpoint; sensitive information should not be included. If sensitive details need to be included, a different exception type should be used.
This exception type can be thrown by MCP tools or tool call filters to propagate detailed error messages from Message when a tool execution fails via a CallToolResult. This includes input validation errors, business logic errors, or any other failure that the model should be informed about. For example, if a required field is missing or a value is out of range, throwing an McpException with a descriptive message allows the model to understand the issue and potentially self-correct in a subsequent request.
For non-tool calls, this exception controls the message propagated via a JsonRpcError.
McpProtocolException is a derived type that can be used to also specify the McpErrorCode that should be used for the resulting JsonRpcError.
Constructors
McpException()
Initializes a new instance of the McpException class.
public McpException()
McpException(string)
Initializes a new instance of the McpException class with a specified error message.
public McpException(string message)
Parameters
messagestringThe message that describes the error.
McpException(string, Exception?)
Initializes a new instance of the McpException class with a specified error message and a reference to the inner exception that is the cause of this exception.
public McpException(string message, Exception? innerException)