Class McpProtocolException
- Namespace
- ModelContextProtocol
- Assembly
- ModelContextProtocol.Core.dll
Represents an exception that is thrown when a Model Context Protocol (MCP) protocol-level error occurs.
public class McpProtocolException : McpException, ISerializable
- Inheritance
-
McpProtocolException
- Implements
- Derived
- Inherited Members
Remarks
This exception is used to represent failures related to protocol-level concerns, such as malformed JSON-RPC requests, unknown methods, unknown primitive names (tools/prompts/resources), or internal server errors. It is not intended to be used for tool execution errors, including input validation failures.
Tool execution errors (including input validation errors, API failures, and business logic errors)
should be returned in the result object with IsError set to true, allowing
language models to see error details and self-correct. Only protocol-level issues should throw
McpProtocolException.
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
messagestringThe 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
messagestringThe message that describes the error.
errorCodeMcpErrorCodeAn 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
messagestringThe message that describes the error.
innerExceptionExceptionThe 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
messagestringThe message that describes the error.
innerExceptionExceptionThe exception that is the cause of the current exception, or a null reference if no inner exception is specified.
errorCodeMcpErrorCodeAn McpErrorCode.
Properties
ErrorCode
Gets the error code associated with this exception.
public McpErrorCode ErrorCode { get; }
Property Value
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 - Malformed request or unknown primitive name (tool/prompt/resource)
- -32603: Internal error - Internal JSON-RPC error