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>
Type Parameters
TParams
Type 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 may 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
server
McpServerThe server with which this instance is associated.
jsonRpcRequest
JsonRpcRequestThe JSON-RPC request 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 request.
public IDictionary<string, object?> Items { get; set; }
Property Value
JsonRpcRequest
Gets the JSON-RPC request associated with this context.
public JsonRpcRequest JsonRpcRequest { get; }
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
Server
Gets or sets the server with which this instance is associated.
public McpServer Server { get; set; }
Property Value
Services
Gets or sets the services associated with this request.
public IServiceProvider? Services { get; set; }
Property Value
Remarks
This may not be the same instance stored in Services if ScopeRequests was true, in which case this might be a scoped IServiceProvider derived from the server's Services.
User
Gets or sets the user associated with this request.
public ClaimsPrincipal? User { get; set; }