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 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
ExecutionContext
Gets or sets the ExecutionContext that should be used to run any handlers
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 McpServer 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.
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 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.
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 may be null.
This property is particularly useful in the Streamable HTTP transport where JSON-RPC messages may outlive the original HTTP request context, allowing user identity to be preserved throughout the message processing pipeline.