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. 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 to help support stateless Streamable HTTP servers that encode this knowledge in the mcp-session-id header.

public Implementation? KnownClientInfo { get; set; }

Property Value

Implementation

Remarks

When not specified, this information is sourced from the client's initialize request.

MaxSamplingOutputTokens

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

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. This uses a date-based versioning scheme in the format "YYYY-MM-DD". If null, the server will advertise to the client the version requested by the client if that version is known to be supported, and otherwise will advertise the latest version supported by the server.

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.

SendTaskStatusNotifications

Gets or sets whether to send task status notifications to clients.

[Experimental("MCPEXP001", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp001")]
public bool SendTaskStatusNotifications { get; set; }

Property Value

bool

true to send optional notifications/tasks/status notifications when task status changes; false to not send notifications. The default is false.

Remarks

When enabled, the server will send notifications/tasks/status notifications to inform clients of task state changes. According to the MCP specification, these notifications are optional and receivers MAY send them but are not required to.

Clients must not rely on receiving these notifications and should continue polling via tasks/get requests to ensure they receive status updates.

Even when this is set to true, notifications are only sent when TaskStore is configured, as task-augmented requests require a task store.

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 to the client during initialization to identify the server. 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.

TaskStore

Gets or sets the task store for managing asynchronous task execution.

[Experimental("MCPEXP001", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp001")]
public IMcpTaskStore? TaskStore { get; set; }

Property Value

IMcpTaskStore

Remarks

When non-null, enables explicit task support with persistence, allowing clients to:

  • Execute operations asynchronously by augmenting requests with task metadata
  • Poll for task status via tasks/get requests
  • Retrieve task results via tasks/result requests
  • List all tasks via tasks/list requests
  • Cancel tasks via tasks/cancel requests

When null, implicit task support may still be available for async methods (returning Task or ValueTask), but tasks will be ephemeral and not persisted. Use InMemoryMcpTaskStore for development/testing or implement IMcpTaskStore for production scenarios.

The server will automatically advertise task capabilities based on the presence of a task store and the detection of async server primitives (tools, prompts, resources).

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.