Skip to content

Commit 76f7297

Browse files
committed
Fix failing Windows build
- filters.md cleanup
1 parent 58dc73a commit 76f7297

2 files changed

Lines changed: 17 additions & 20 deletions

File tree

docs/concepts/filters.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ uid: filters
77

88
# MCP Server Handler Filters
99

10-
This document describes the filter functionality in the MCP Server, which allows you to add middleware-style filters to handler pipelines.
11-
12-
## Overview
13-
1410
For each handler type in the MCP Server, there are corresponding `AddXXXFilter` methods in `McpServerBuilderExtensions.cs` that allow you to add filters to the handler pipeline. The filters are stored in `McpServerOptions.Filters` and applied during server configuration.
1511

1612
## Available Filter Methods
@@ -173,12 +169,12 @@ You can apply authorization at the class level, which affects all tools in the c
173169
```csharp
174170
[McpServerToolType]
175171
[Authorize] // All tools require authentication
176-
public class AdminTools
172+
public class RestrictedTools
177173
{
178-
[McpServerTool, Description("Admin-only tool")]
179-
public static string AdminOperation()
174+
[McpServerTool, Description("Restricted tool accessible to authenticated users")]
175+
public static string RestrictedOperation()
180176
{
181-
return "Admin operation completed";
177+
return "Restricted operation completed";
182178
}
183179

184180
[McpServerTool, Description("Public tool accessible to anonymous users")]
@@ -211,23 +207,22 @@ To use authorization features, you must configure authentication and authorizati
211207
```csharp
212208
var builder = WebApplication.CreateBuilder(args);
213209

214-
// Add authentication
215210
builder.Services.AddAuthentication("Bearer")
216-
.AddJwtBearer("Bearer", options => { /* JWT configuration */ });
217-
218-
// Add authorization (required for [Authorize] attributes to work)
211+
.AddJwtBearer(options => { /* JWT configuration */ })
212+
.AddMcp(options => { /* Resource metadata configuration */ });
219213
builder.Services.AddAuthorization();
220214

221-
// Add MCP server
222215
builder.Services.AddMcpServer()
223-
.WithTools<WeatherTools>();
216+
.WithHttpTransport()
217+
.WithTools<WeatherTools>()
218+
.AddCallToolFilter(next => async (context, cancellationToken) =>
219+
{
220+
// Custom call tool logic
221+
return await next(context, cancellationToken);
222+
});
224223

225224
var app = builder.Build();
226225

227-
// Use authentication and authorization middleware
228-
app.UseAuthentication();
229-
app.UseAuthorization();
230-
231226
app.MapMcp();
232227
app.Run();
233228
```

src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,11 @@ internal static string MakeNewSessionId()
279279
// Implementation for reading a JSON-RPC message from the request body
280280
var message = await context.Request.ReadFromJsonAsync(s_messageTypeInfo, context.RequestAborted);
281281

282-
if (context.User?.Identity?.IsAuthenticated ?? false)
282+
if (context.User?.Identity?.IsAuthenticated ?? false && message is not null)
283283
{
284-
message?.Context = new()
284+
// We get weird CS0131 errors only on the Windows build GitHub Action if we use "message?.Context = ..."
285+
// https://productionresultssa0.blob.core.windows.net/actions-results/f2218319-0fdd-473b-891d-06e5a4a0f826/workflow-job-run-98901492-cf7c-5406-85d9-0f7057e0516f/logs/job/job-logs.txt?rsct=text%2Fplain&se=2025-08-26T16%3A06%3A31Z&sig=RvEQo6DgrpDUW9mnbgDvf6FVDAAoHKzk9rsDdcPxOhw%3D&ske=2025-08-27T03%3A39%3A43Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2025-08-26T15%3A39%3A43Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2025-05-05&sp=r&spr=https&sr=b&st=2025-08-26T15%3A56%3A26Z&sv=2025-05-05
286+
message!.Context = new()
285287
{
286288
User = context.User,
287289
};

0 commit comments

Comments
 (0)