|
8 | 8 | using ModelContextProtocol.Protocol; |
9 | 9 | using ModelContextProtocol.Server; |
10 | 10 | using System.Collections.Concurrent; |
| 11 | +using System.Diagnostics.CodeAnalysis; |
11 | 12 | using System.Security.Claims; |
12 | 13 | using System.Security.Cryptography; |
13 | 14 | using System.Text.Json.Serialization.Metadata; |
@@ -82,7 +83,7 @@ await WriteJsonRpcErrorAsync(context, |
82 | 83 |
|
83 | 84 | if (!ValidateMcpHeaders(context, message, mcpServerOptionsSnapshot.Value.ToolCollection, out errorMessage)) |
84 | 85 | { |
85 | | - await WriteJsonRpcErrorAsync(context, errorMessage!, StatusCodes.Status400BadRequest, (int)McpErrorCode.HeaderMismatch); |
| 86 | + await WriteJsonRpcErrorAsync(context, errorMessage, StatusCodes.Status400BadRequest, (int)McpErrorCode.HeaderMismatch); |
86 | 87 | return; |
87 | 88 | } |
88 | 89 |
|
@@ -557,7 +558,7 @@ private static bool ValidateProtocolVersionHeader(HttpContext context, out strin |
557 | 558 | /// <param name="toolCollection">The tool collection to look up tool schemas for parameter header validation.</param> |
558 | 559 | /// <param name="errorMessage">Set to the error message if validation fails; null otherwise.</param> |
559 | 560 | /// <returns>True if validation passes; false otherwise.</returns> |
560 | | - internal static bool ValidateMcpHeaders(HttpContext context, JsonRpcMessage message, McpServerPrimitiveCollection<McpServerTool>? toolCollection, out string? errorMessage) |
| 561 | + internal static bool ValidateMcpHeaders(HttpContext context, JsonRpcMessage message, McpServerPrimitiveCollection<McpServerTool>? toolCollection, [NotNullWhen(false)] out string? errorMessage) |
561 | 562 | { |
562 | 563 | // Only validate for protocol versions that support standard headers. |
563 | 564 | var protocolVersion = context.Request.Headers[McpProtocolVersionHeaderName].ToString(); |
@@ -653,7 +654,7 @@ private static bool ValidateCustomParamHeaders( |
653 | 654 | HttpContext context, |
654 | 655 | JsonRpcMessage message, |
655 | 656 | McpServerPrimitiveCollection<McpServerTool>? toolCollection, |
656 | | - out string? errorMessage) |
| 657 | + [NotNullWhen(false)] out string? errorMessage) |
657 | 658 | { |
658 | 659 | // Custom param headers are only relevant for tools/call requests |
659 | 660 | if (message is not JsonRpcRequest { Method: RequestMethods.ToolsCall, Params: { } bodyParams }) |
|
0 commit comments