Table of Contents

Class McpException

Namespace
ModelContextProtocol
Assembly
ModelContextProtocol.dll

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

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

Remarks

This exception is used to represent failures to do with protocol-level concerns, such as invalid JSON-RPC requests, invalid parameters, or internal errors. It is not intended to be used for application-level errors. Message or ErrorCode 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.

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, McpErrorCode)

Initializes a new instance of the McpException class with a specified error message and JSON-RPC error code.

public McpException(string message, McpErrorCode errorCode)

Parameters

message string

The message that describes the error.

errorCode McpErrorCode

A McpErrorCode.

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.

McpException(string, Exception?, McpErrorCode)

Initializes a new instance of the McpException class with a specified error message, inner exception, and JSON-RPC error code.

public McpException(string message, Exception? innerException, McpErrorCode errorCode)

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.

errorCode McpErrorCode

A McpErrorCode.

Properties

ErrorCode

Gets the error code associated with this exception.

public McpErrorCode ErrorCode { get; }

Property Value

McpErrorCode

Remarks

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