Class MessageContext | MCP C# SDK

Namespace
ModelContextProtocol.Server
Assembly
ModelContextProtocol.Core.dll

Provides a context container that provides access to the server and resources for processing a JSON-RPC message.

public class MessageContext
Inheritance

MessageContext

Derived
Inherited Members

Constructors

MessageContext(McpServer, JsonRpcMessage)

Initializes a new instance of the MessageContext class with the specified server and JSON-RPC message.

public MessageContext(McpServer server, JsonRpcMessage jsonRpcMessage)

Parameters

server McpServer

The server with which this instance is associated.

jsonRpcMessage JsonRpcMessage

The JSON-RPC message associated with this context.

Properties

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

IDictionary<string, object>

JsonRpcMessage

Gets the JSON-RPC message associated with this context.

public JsonRpcMessage JsonRpcMessage { get; set; }

Property Value

JsonRpcMessage

Server

Gets or sets the server with which this instance is associated.

public McpServer Server { get; set; }

Property Value

McpServer

Services

Gets or sets the services associated with this message.

public IServiceProvider? Services { get; set; }

Property Value

IServiceProvider

User

Gets or sets the user associated with this message.

public ClaimsPrincipal? User { get; set; }

Property Value

ClaimsPrincipal