Class JsonRpcMessageContext
- Namespace
- ModelContextProtocol.Protocol
- Assembly
- ModelContextProtocol.Core.dll
Contains contextual information for JSON-RPC messages that is not part of the JSON-RPC protocol specification.
public sealed class JsonRpcMessageContext
- Inheritance
-
JsonRpcMessageContext
- Inherited Members
Remarks
This class holds transport-specific and runtime context information that accompanies JSON-RPC messages but is not serialized as part of the JSON-RPC payload. This includes transport references, execution context, and authenticated user information.
Properties
ClientCapabilities
Gets or sets the client capabilities derived from the per-request
_meta/io.modelcontextprotocol/clientCapabilities field.
public ClientCapabilities? ClientCapabilities { get; set; }
Property Value
Remarks
Introduced by the 2026-07-28 protocol revision (SEP-2575). Per the spec, the server MUST NOT infer client capabilities from previous modern requests; the authoritative value is the one declared on each request. Future reserved metadata remains opaque under legacy revisions, which continue to use the capabilities negotiated during initialization.
ClientInfo
Gets or sets the client info derived from the per-request
_meta/io.modelcontextprotocol/clientInfo field.
public Implementation? ClientInfo { get; set; }
Property Value
Remarks
Introduced by the 2026-07-28 protocol revision (SEP-2575). When the request was made under the 2026-07-28 or later revision,
the server uses this in lieu of the value previously captured during the initialize handshake. Future reserved
metadata remains opaque under legacy revisions, which continue to use their initialized identity.
ExecutionContext
Gets or sets the ExecutionContext that should be used to run any handlers.
public ExecutionContext? ExecutionContext { get; set; }
Property Value
Remarks
This property is used to support the Streamable HTTP transport in its default stateful mode. In this mode, the McpServer outlives the initial HTTP request context it was created on, and new JSON-RPC messages can originate from future HTTP requests. This behavior allows the transport to flow the context with the JSON-RPC message. This is particularly useful for enabling IHttpContextAccessor in tool calls.
Items
Gets or sets a key/value collection that can be used to share data within the scope of this message.
public IDictionary<string, object?>? Items { get; set; }
Property Value
Remarks
This property allows data to be flowed throughout the message processing pipeline, including from incoming message filters to request-specific filters and handlers.
When creating a MessageContext or RequestContext<TParams> for server-side processing, the Items dictionary from this context will be used, ensuring data set in message filters is available in request filters and handlers.
LogLevel
Gets or sets the per-request log level derived from the
_meta/io.modelcontextprotocol/logLevel field.
public LoggingLevel? LogLevel { get; set; }
Property Value
Remarks
Introduced by the 2026-07-28 protocol revision (SEP-2575). Replaces the legacy LoggingSetLevel RPC. When absent from a modern request, the server MUST NOT emit log notifications for the request. Legacy requests continue to use their negotiated logging behavior.
ProtocolVersion
Gets or sets the authoritative protocol version for this JSON-RPC message.
public string? ProtocolVersion { get; set; }
Property Value
Remarks
The transport may populate this from a header such as Mcp-Protocol-Version. For modern revisions,
the server validates and projects the matching per-request _meta value. Under an established legacy
revision, future reserved metadata remains opaque and does not establish or change the negotiated session version.
RelatedTransport
Gets or sets the transport the JsonRpcMessage was received on or should be sent over.
public ITransport? RelatedTransport { get; set; }
Property Value
Remarks
This property 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 can be null for other transports.
RoutingName
Gets or sets the routing name for this message.
[Experimental("MCPEXP002", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp002")]
[JsonIgnore]
public string? RoutingName { get; set; }
Property Value
Remarks
Streamable HTTP transports emit this value in the Mcp-Name header. This enables
extension methods to identify the named resource targeted by a request.
User
Gets or sets the authenticated user associated with this JSON-RPC message.
public ClaimsPrincipal? User { get; set; }
Property Value
Remarks
This property contains the ClaimsPrincipal representing the authenticated user who initiated this JSON-RPC message. This enables request handlers to access user identity and authorization information without requiring dependency on HTTP context accessors or other HTTP-specific abstractions.
The user information is automatically populated by the transport layer when processing incoming HTTP requests in ASP.NET Core scenarios. For other transport types or scenarios where user authentication is not applicable, this property can be null.
This property is particularly useful in the Streamable HTTP transport where JSON-RPC messages might outlive the original HTTP request context, allowing user identity to be preserved throughout the message processing pipeline.