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 requests; the authoritative value is the one declared on each request.
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.
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, the server MUST NOT emit log notifications for the request.
ProtocolVersion
Gets or sets the protocol version from the transport-level header (e.g. Mcp-Protocol-Version)
that accompanied this JSON-RPC message.
public string? ProtocolVersion { get; set; }
Property Value
Remarks
In stateless Streamable HTTP mode, the protocol version cannot be negotiated via the initialize
handshake because each request creates a new server instance. This property allows the transport layer
to flow the protocol version header so the server can determine client capabilities.
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.