Class JsonRpcMessage
- Namespace
- ModelContextProtocol.Protocol
- Assembly
- ModelContextProtocol.Core.dll
Represents any JSON-RPC message used in the Model Context Protocol (MCP).
[JsonConverter(typeof(JsonRpcMessage.Converter))]
public abstract class JsonRpcMessage
- Inheritance
-
JsonRpcMessage
- Derived
- Inherited Members
Remarks
This interface serves as the foundation for all message types in the JSON-RPC 2.0 protocol used by MCP, including requests, responses, notifications, and errors. JSON-RPC is a stateless, lightweight remote procedure call (RPC) protocol that uses JSON as its data format.
Properties
ExecutionContext
Gets or sets the ExecutionContext that should be used to run any handlers
[JsonIgnore]
public ExecutionContext? ExecutionContext { get; set; }
Property Value
Remarks
This is used to support the Streamable HTTP transport in its default stateful mode. In this mode, the IMcpServer outlives the initial HTTP request context it was created on, and new JSON-RPC messages can originate from future HTTP requests. This allows the transport to flow the context with the JSON-RPC message. This is particularly useful for enabling IHttpContextAccessor in tool calls.
JsonRpc
Gets the JSON-RPC protocol version used.
[JsonPropertyName("jsonrpc")]
public string JsonRpc { get; init; }
Property Value
RelatedTransport
Gets or sets the transport the JsonRpcMessage was received on or should be sent over.
[JsonIgnore]
public ITransport? RelatedTransport { get; set; }
Property Value
Remarks
This is used to support the Streamable HTTP transport where the specification states that the server SHOULD include JSON-RPC responses in the HTTP response body for the POST request containing the corresponding JSON-RPC request. It may be null for other transports.