Skip to content

Commit adfcd82

Browse files
Copilotstephentoub
andcommitted
Make McpServerOptions.Filters and McpServerFilters sub-properties settable
- McpServerOptions.Filters is now get+set with null validation - McpServerFilters.Message and McpServerFilters.Request are now get+set with null validation - No other get-only/get-init properties found that should be get/set (IList<T> filter collections and internal McpServerImpl properties are correctly get-only) Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent b1741f7 commit adfcd82

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/ModelContextProtocol.Core/Server/McpServerFilters.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@ namespace ModelContextProtocol.Server;
1212
public sealed class McpServerFilters
1313
{
1414
/// <summary>
15-
/// Gets the filters for incoming and outgoing JSON-RPC messages.
15+
/// Gets or sets the filters for incoming and outgoing JSON-RPC messages.
1616
/// </summary>
17-
public McpMessageFilters Message { get; } = new();
17+
public McpMessageFilters Message
18+
{
19+
get => field ??= new();
20+
set
21+
{
22+
Throw.IfNull(value);
23+
field = value;
24+
}
25+
}
1826

1927
/// <summary>
20-
/// Gets the filters for request-specific MCP handler pipelines.
28+
/// Gets or sets the filters for request-specific MCP handler pipelines.
2129
/// </summary>
22-
public McpRequestFilters Request { get; } = new();
30+
public McpRequestFilters Request
31+
{
32+
get => field ??= new();
33+
set
34+
{
35+
Throw.IfNull(value);
36+
field = value;
37+
}
38+
}
2339
}

src/ModelContextProtocol.Core/Server/McpServerOptions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,22 @@ public McpServerHandlers Handlers
108108
}
109109

110110
/// <summary>
111-
/// Gets the filter collections for MCP server handlers.
111+
/// Gets or sets the filter collections for MCP server handlers.
112112
/// </summary>
113113
/// <remarks>
114114
/// This property provides access to filter collections that can be used to modify the behavior
115115
/// of various MCP server handlers. The first filter added is the outermost (first to execute),
116116
/// and each subsequent filter wraps closer to the handler.
117117
/// </remarks>
118-
public McpServerFilters Filters { get; } = new();
118+
public McpServerFilters Filters
119+
{
120+
get => field ??= new();
121+
set
122+
{
123+
Throw.IfNull(value);
124+
field = value;
125+
}
126+
}
119127

120128
/// <summary>
121129
/// Gets or sets a collection of tools served by the server.

0 commit comments

Comments
 (0)