- Namespace
- ModelContextProtocol.Server
- Assembly
- ModelContextProtocol.Core.dll
Provides a context container that provides access to the client request parameters and resources for the request.
public sealed class RequestContext<TParams> : MessageContext
Type Parameters
TParamsType of the request parameters specific to each MCP operation.
- Inheritance
-
RequestContext<TParams>
- Inherited Members
Constructors
RequestContext(McpServer, JsonRpcRequest)
Initializes a new instance of the RequestContext<TParams> class with the specified server and JSON-RPC request.
[Obsolete("Use the constructor overload that accepts a parameters argument.", DiagnosticId = "MCP9003", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcp9003")]
public RequestContext(McpServer server, JsonRpcRequest jsonRpcRequest)
Parameters
serverMcpServerThe server with which this instance is associated.
jsonRpcRequestJsonRpcRequestThe JSON-RPC request associated with this context.
Exceptions
- ArgumentNullException
serverorjsonRpcRequestis null.
RequestContext(McpServer, JsonRpcRequest, TParams)
Initializes a new instance of the RequestContext<TParams> class with the specified server, JSON-RPC request, and request parameters.
public RequestContext(McpServer server, JsonRpcRequest jsonRpcRequest, TParams parameters)
Parameters
serverMcpServerThe server with which this instance is associated.
jsonRpcRequestJsonRpcRequestThe JSON-RPC request associated with this context.
parametersTParamsThe parameters associated with this request.
Exceptions
- ArgumentNullException
serverorjsonRpcRequestis null.
Properties
JsonRpcRequest
Gets the JSON-RPC request associated with this context.
public JsonRpcRequest JsonRpcRequest { get; set; }
Property Value
MatchedPrimitive
Gets or sets the primitive that matched the request.
public IMcpServerPrimitive? MatchedPrimitive { get; set; }
Property Value
Params
Gets or sets the parameters associated with this request.
public TParams Params { get; set; }
Property Value
- TParams
Methods
EnablePollingAsync(TimeSpan, CancellationToken)
Ends the current response and enables polling for updates from the server.
public ValueTask EnablePollingAsync(TimeSpan retryInterval, CancellationToken cancellationToken = default)
Parameters
retryIntervalTimeSpanThe interval at which the client should poll for updates.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Exceptions
- InvalidOperationException
Thrown when the transport does not support polling.