Table of Contents

Class McpServerFilters

Namespace
ModelContextProtocol.Server
Assembly
ModelContextProtocol.Core.dll

Provides filter collections for MCP server handlers.

public sealed class McpServerFilters
Inheritance
McpServerFilters
Inherited Members

Remarks

This class contains collections of filters that can be applied to various MCP server handlers. This allows for middleware-style composition where filters can perform actions before and after the inner handler.

Properties

CallToolFilters

Gets the filters for the call tool handler pipeline.

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

Property Value

List<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.

CompleteFilters

Gets the filters for the complete handler pipeline.

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

Property Value

List<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 the filters for the get prompt handler pipeline.

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

Property Value

List<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 the filters for the list prompts handler pipeline.

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

Property Value

List<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 the filters for the list resource templates handler pipeline.

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

Property Value

List<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 the filters for the list resources handler pipeline.

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

Property Value

List<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 the filters for the list tools handler pipeline.

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

Property Value

List<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 the filters for the read resource handler pipeline.

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

Property Value

List<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 the filters for the set logging level handler pipeline.

public List<McpRequestFilter<SetLevelRequestParams, EmptyResult>> SetLoggingLevelFilters { get; }

Property Value

List<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 the filters for the subscribe to resources handler pipeline.

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

Property Value

List<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 the filters for the unsubscribe from resources handler pipeline.

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

Property Value

List<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.