Table of Contents

Class McpRequestFilters

Namespace
ModelContextProtocol.Server
Assembly
ModelContextProtocol.Core.dll

Provides grouped request-specific filter collections.

public sealed class McpRequestFilters
Inheritance
McpRequestFilters
Inherited Members

Properties

CallToolFilters

Gets or sets the filters for the call-tool handler pipeline.

public IList<McpRequestFilter<CallToolRequestParams, CallToolResult>> CallToolFilters { get; set; }

Property Value

IList<McpRequestFilter<CallToolRequestParams, CallToolResult>>

Remarks

These filters wrap handlers that are invoked when a client makes a call to a tool that isn't found in the McpServerTool collection. The filters can modify, log, or perform additional operations on requests and responses for ToolsCall requests. The handler should implement logic to execute the requested tool and return appropriate results.

These filters run inside CallToolWithAlternateFilters. Each ordinary filter runs exactly once when an alternate-result filter invokes the ordinary tool pipeline. For task-backed calls, that invocation occurs in the background after the task record is created and before the matched tool is executed. Filters that must run before task creation should use the alternate-result pipeline instead.

These filters cannot be used with an explicit CallToolWithAlternateHandler, which replaces the ordinary tool-call pipeline rather than augmenting it.

CallToolWithAlternateFilters

Gets or sets the filters for the call-tool handler pipeline with alternate result support.

[Experimental("MCPEXP002", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp002")]
public IList<McpRequestInvocationFilter<CallToolRequestParams, ResultOrAlternate<CallToolResult>>> CallToolWithAlternateFilters { get; set; }

Property Value

IList<McpRequestInvocationFilter<CallToolRequestParams, ResultOrAlternate<CallToolResult>>>

Remarks

These filters wrap the alternate-result call-tool handler whose return type is ResultOrAlternate<TResult>. Use these filters when the server's tool pipeline supports returning either an immediate CallToolResult or an alternate Result subtype for asynchronous execution.

When no explicit CallToolWithAlternateHandler is configured, these filters compose outside CallToolFilters. Primitive matching occurs before either filter family runs, then the ordinary pipeline is adapted to ResultOrAlternate<TResult> before these filters are applied. Alternate-result filters run in registration order. If one filter dispatches the remainder of the pipeline asynchronously, filters registered after it execute as part of that asynchronous operation.

CompleteFilters

Gets or sets the filters for the complete-handler pipeline.

public IList<McpRequestFilter<CompleteRequestParams, CompleteResult>> CompleteFilters { get; set; }

Property Value

IList<McpRequestFilter<CompleteRequestParams, CompleteResult>>

Remarks

These filters wrap handlers that provide auto-completion suggestions for prompt arguments or resource references in the Model Context Protocol. The filters can modify, log, or perform additional operations on requests and responses for CompletionComplete requests. The handler processes auto-completion requests, returning a list of suggestions based on the reference type and current argument value.

GetPromptFilters

Gets or sets the filters for the get-prompt handler pipeline.

public IList<McpRequestFilter<GetPromptRequestParams, GetPromptResult>> GetPromptFilters { get; set; }

Property Value

IList<McpRequestFilter<GetPromptRequestParams, GetPromptResult>>

Remarks

These filters wrap handlers that are invoked when a client requests details for a specific prompt that isn't found in the McpServerPrompt collection. The filters can modify, log, or perform additional operations on requests and responses for PromptsGet requests. The handler should implement logic to fetch or generate the requested prompt and return appropriate results.

ListPromptsFilters

Gets or sets the filters for the list-prompts handler pipeline.

public IList<McpRequestFilter<ListPromptsRequestParams, ListPromptsResult>> ListPromptsFilters { get; set; }

Property Value

IList<McpRequestFilter<ListPromptsRequestParams, ListPromptsResult>>

Remarks

These filters wrap handlers that return a list of available prompts when requested by a client. The filters can modify, log, or perform additional operations on requests and responses for PromptsList requests. It supports pagination through the cursor mechanism, where the client can make repeated calls with the cursor returned by the previous call to retrieve more prompts.

These filters work alongside any prompts defined in the McpServerPrompt collection. Prompts from both sources will be combined when returning results to clients.

ListResourceTemplatesFilters

Gets or sets the filters for the list-resource-templates handler pipeline.

public IList<McpRequestFilter<ListResourceTemplatesRequestParams, ListResourceTemplatesResult>> ListResourceTemplatesFilters { get; set; }

Property Value

IList<McpRequestFilter<ListResourceTemplatesRequestParams, ListResourceTemplatesResult>>

Remarks

These filters wrap handlers that return a list of available resource templates when requested by a client. The filters can modify, log, or perform additional operations on requests and responses for ResourcesTemplatesList requests. It supports pagination through the cursor mechanism, where the client can make repeated calls with the cursor returned by the previous call to retrieve more resource templates.

ListResourcesFilters

Gets or sets the filters for the list-resources handler pipeline.

public IList<McpRequestFilter<ListResourcesRequestParams, ListResourcesResult>> ListResourcesFilters { get; set; }

Property Value

IList<McpRequestFilter<ListResourcesRequestParams, ListResourcesResult>>

Remarks

These filters wrap handlers that return a list of available resources when requested by a client. The filters can modify, log, or perform additional operations on requests and responses for ResourcesList requests. It supports pagination through the cursor mechanism, where the client can make repeated calls with the cursor returned by the previous call to retrieve more resources.

ListToolsFilters

Gets or sets the filters for the list-tools handler pipeline.

public IList<McpRequestFilter<ListToolsRequestParams, ListToolsResult>> ListToolsFilters { get; set; }

Property Value

IList<McpRequestFilter<ListToolsRequestParams, ListToolsResult>>

Remarks

These filters wrap handlers that return a list of available tools when requested by a client. The filters can modify, log, or perform additional operations on requests and responses for ToolsList requests. It supports pagination through the cursor mechanism, where the client can make repeated calls with the cursor returned by the previous call to retrieve more tools.

These filters work alongside any tools defined in the McpServerTool collection. Tools from both sources will be combined when returning results to clients.

ReadResourceFilters

Gets or sets the filters for the read-resource handler pipeline.

public IList<McpRequestFilter<ReadResourceRequestParams, ReadResourceResult>> ReadResourceFilters { get; set; }

Property Value

IList<McpRequestFilter<ReadResourceRequestParams, ReadResourceResult>>

Remarks

These filters wrap handlers that are invoked when a client requests the content of a specific resource identified by its URI. The filters can modify, log, or perform additional operations on requests and responses for ResourcesRead requests. The handler should implement logic to locate and retrieve the requested resource.

SetLoggingLevelFilters

Gets or sets the filters for the set-logging-level handler pipeline.

[Obsolete("The Logging feature is deprecated as of specification version 2026-07-28 and may be removed in a future version. See SEP-2577 for more information.", DiagnosticId = "MCP9005", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#obsolete-apis")]
public IList<McpRequestFilter<SetLevelRequestParams, EmptyResult>> SetLoggingLevelFilters { get; set; }

Property Value

IList<McpRequestFilter<SetLevelRequestParams, EmptyResult>>

Remarks

These filters wrap handlers that process LoggingSetLevel requests from clients. When set, it enables clients to control which log messages they receive by specifying a minimum severity threshold. The filters can modify, log, or perform additional operations on requests and responses for LoggingSetLevel requests.

After handling a level change request, the server typically begins sending log messages at or above the specified level to the client as notifications/message notifications.

SubscribeToResourcesFilters

Gets or sets the filters for the subscribe-to-resources handler pipeline.

public IList<McpRequestFilter<SubscribeRequestParams, EmptyResult>> SubscribeToResourcesFilters { get; set; }

Property Value

IList<McpRequestFilter<SubscribeRequestParams, EmptyResult>>

Remarks

These filters wrap handlers that are invoked when a client wants to receive notifications about changes to specific resources or resource patterns. The filters can modify, log, or perform additional operations on requests and responses for ResourcesSubscribe requests. The handler should implement logic to register the client's interest in the specified resources and set up the necessary infrastructure to send notifications when those resources change.

After a successful subscription, the server should send resource change notifications to the client whenever a relevant resource is created, updated, or deleted.

UnsubscribeFromResourcesFilters

Gets or sets the filters for the unsubscribe-from-resources handler pipeline.

public IList<McpRequestFilter<UnsubscribeRequestParams, EmptyResult>> UnsubscribeFromResourcesFilters { get; set; }

Property Value

IList<McpRequestFilter<UnsubscribeRequestParams, EmptyResult>>

Remarks

These filters wrap handlers that are invoked when a client wants to stop receiving notifications about previously subscribed resources. The filters can modify, log, or perform additional operations on requests and responses for ResourcesUnsubscribe requests. The handler should implement logic to remove the client's subscriptions to the specified resources and clean up any associated resources.

After a successful unsubscription, the server should no longer send resource change notifications to the client for the specified resources.