Table of Contents

Class McpServerOptions

Namespace
ModelContextProtocol.Server
Assembly
ModelContextProtocol.Core.dll

Provides configuration options for the MCP server.

public sealed class McpServerOptions
Inheritance
McpServerOptions
Inherited Members

Properties

Capabilities

Gets or sets server capabilities to advertise to the client.

public ServerCapabilities? Capabilities { get; set; }

Property Value

ServerCapabilities

Remarks

These determine which features will be available when a client connects. Capabilities can include "tools", "prompts", "resources", "logging", and other protocol-specific functionality.

Filters

Gets or sets the filter collections for MCP server handlers.

public McpServerFilters Filters { get; set; }

Property Value

McpServerFilters

Remarks

This property provides access to filter collections that can be used to modify the behavior of various MCP server handlers. The first filter added is the outermost (first to execute), and each subsequent filter wraps closer to the handler.

Handlers

Gets or sets the container of handlers used by the server for processing protocol messages.

public McpServerHandlers Handlers { get; set; }

Property Value

McpServerHandlers

InitializationTimeout

Gets or sets a timeout used for the client-server initialization handshake sequence.

public TimeSpan InitializationTimeout { get; set; }

Property Value

TimeSpan

Remarks

This timeout determines how long the server will wait for client responses during the initialization protocol handshake. If the client doesn't respond within this timeframe, the initialization process will be aborted.

KnownClientCapabilities

Gets or sets preexisting knowledge about the client's capabilities to support session migration scenarios where the client will not re-send the initialize request.

public ClientCapabilities? KnownClientCapabilities { get; set; }

Property Value

ClientCapabilities

Remarks

When not specified, this information is sourced from the client's initialize request or, for protocol versions that use per-request metadata, from the current request's _meta field. This is typically set during session migration in conjunction with KnownClientInfo.

KnownClientInfo

Gets or sets preexisting knowledge about the client including its name and version.

public Implementation? KnownClientInfo { get; set; }

Property Value

Implementation

Remarks

When not specified, this information is sourced from the client's initialize request or, for protocol versions that use per-request metadata, from the current request's _meta field. This is typically set during session migration in conjunction with KnownClientCapabilities.

MaxSamplingOutputTokens

Gets or sets the default maximum number of tokens to use for sampling requests when not explicitly specified.

[Obsolete("The Sampling 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 int MaxSamplingOutputTokens { get; set; }

Property Value

int

The default maximum number of tokens to use for sampling requests. The default value is 1000 tokens.

Remarks

This value is used in SampleAsync(IEnumerable<ChatMessage>, ChatOptions?, JsonSerializerOptions?, CancellationToken) when Microsoft.Extensions.AI.ChatOptions.MaxOutputTokens is not set in the request options.

PromptCollection

Gets or sets a collection of prompts that will be served by the server.

public McpServerPrimitiveCollection<McpServerPrompt>? PromptCollection { get; set; }

Property Value

McpServerPrimitiveCollection<McpServerPrompt>

Remarks

The PromptCollection contains the predefined prompts that clients can request from the server. This collection works in conjunction with ListPromptsHandler and GetPromptHandler when those are provided:

- For PromptsList requests: The server returns all prompts from this collection plus any additional prompts provided by the ListPromptsHandler if it's set.

- For PromptsGet requests: The server first checks this collection for the requested prompt. If not found, it will invoke the GetPromptHandler as a fallback if one is set.

ProtocolVersion

Gets or sets the protocol version supported by this server, using a date-based versioning scheme.

public string? ProtocolVersion { get; set; }

Property Value

string

Remarks

The protocol version defines which features and message formats this server supports. Supported values are 2024-11-05, 2025-03-26, 2025-06-18, 2025-11-25, and 2026-07-28.

If null, the server supports all of the versions listed above. For clients using the initialize handshake, the server returns the requested initialize-capable version when it is supported and otherwise returns 2025-11-25. For clients using server/discover and per-request metadata, the server advertises the supported per-request metadata versions; currently this is 2026-07-28.

Set this property to a specific supported value to pin the server to that version. Setting it to 2026-07-28 makes the server reject initialize handshakes; setting it to an earlier value makes the server reject 2026-07-28 per-request metadata.

RequestHandlers

Gets or sets custom request handlers to register with the server.

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

Property Value

IList<McpServerRequestHandler>

Remarks

Each McpServerRequestHandler registers a raw JSON-RPC method handler that bypasses the typed handler infrastructure. This enables extensions to register handlers for methods not known to Core at compile time.

Handlers registered here take precedence over built-in handlers for the same method.

ResourceCollection

Gets or sets a collection of resources served by the server.

public McpServerResourceCollection? ResourceCollection { get; set; }

Property Value

McpServerResourceCollection

Remarks

Resources specified via ResourceCollection augment the ListResourcesHandler, ListResourceTemplatesHandler and ReadResourceHandler handlers, if provided. Resources with template expressions in their URI templates are considered resource templates and are listed via ListResourceTemplate, whereas resources without template parameters are considered static resources and are listed with ListResources.

ReadResource requests will first check the ResourceCollection for the exact resource being requested. If no match is found, they'll proceed to try to match the resource against each resource template in ResourceCollection. If no match is still found, the request will fall back to any handler registered for ReadResourceHandler.

ScopeRequests

Gets or sets a value that indicates whether to create a new service provider scope for each handled request.

public bool ScopeRequests { get; set; }

Property Value

bool

true if each invocation of a request handler is invoked within a new service scope. The default is true.

ServerInfo

Gets or sets information about this server implementation, including its name and version.

public Implementation? ServerInfo { get; set; }

Property Value

Implementation

Remarks

This information is sent in the initialization result on handshake-based protocol revisions and in every successful result's metadata on per-request-metadata revisions. It's displayed in client logs and can be used for debugging and compatibility checks.

ServerInstructions

Gets or sets optional server instructions to send to clients.

public string? ServerInstructions { get; set; }

Property Value

string

Remarks

These instructions are sent to clients during the initialization handshake and provide guidance on how to effectively use the server's capabilities. They should focus on information that helps models use the server effectively and should not duplicate tool, prompt, or resource descriptions already exposed elsewhere. Client applications typically use these instructions as system messages for LLM interactions to provide context about available functionality.

ToolCollection

Gets or sets a collection of tools served by the server.

public McpServerPrimitiveCollection<McpServerTool>? ToolCollection { get; set; }

Property Value

McpServerPrimitiveCollection<McpServerTool>

Remarks

Tools specified via ToolCollection augment the ListToolsHandler and CallToolHandler, if provided. ListTools requests will output information about every tool in ToolCollection and then also any tools output by ListToolsHandler, if it's non-null. CallTool requests will first check ToolCollection for the tool being requested, and if the tool is not found in the ToolCollection, any specified CallToolHandler will be invoked as a fallback.