Table of Contents

Class McpException

Namespace
ModelContextProtocol
Assembly
ModelContextProtocol.Core.dll

Represents an exception that is thrown when an Model Context Protocol (MCP) error occurs.

public class McpException : Exception, ISerializable
Inheritance
McpException
Implements
Derived
Inherited Members

Remarks

The Message from a McpException may 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. 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

message string

The 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)

Parameters

message string

The message that describes the error.

innerException Exception

The exception that is the cause of the current exception, or a null reference if no inner exception is specified.