Class RequestContext<TParams>
- 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
Remarks
The RequestContext<TParams> encapsulates all contextual information for handling an MCP request. This type is typically received as a parameter in handler delegates registered with IMcpServerBuilder, and can be injected as parameters into McpServerTools.
Constructors
RequestContext(McpServer, JsonRpcRequest)
Initializes a new instance of the RequestContext<TParams> class with the specified server and JSON-RPC request.
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.
Properties
JsonRpcRequest
Gets the JSON-RPC request associated with this context.
public JsonRpcRequest JsonRpcRequest { get; set; }
Property Value
Remarks
This property provides access to the complete JSON-RPC request that initiated this handler invocation, including the method name, parameters, request ID, and associated transport and user information.
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.