Table of Contents

Class McpProtocolException

Namespace
ModelContextProtocol
Assembly
ModelContextProtocol.Core.dll

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

public sealed class McpProtocolException : McpException, ISerializable
Inheritance
McpProtocolException
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 McpProtocolException 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

McpProtocolException()

Initializes a new instance of the McpProtocolException class.

public McpProtocolException()

McpProtocolException(string)

Initializes a new instance of the McpProtocolException class with a specified error message.

public McpProtocolException(string message)

Parameters

message string

The message that describes the error.

McpProtocolException(string, McpErrorCode)

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

public McpProtocolException(string message, McpErrorCode errorCode)

Parameters

message string

The message that describes the error.

errorCode McpErrorCode

A McpErrorCode.

McpProtocolException(string, Exception?)

Initializes a new instance of the McpProtocolException class with a specified error message and a reference to the inner exception that is the cause of this exception.

public McpProtocolException(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.

McpProtocolException(string, Exception?, McpErrorCode)

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

public McpProtocolException(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