Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/Common/McpHttpHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@ namespace ModelContextProtocol.Protocol;
internal static class McpHttpHeaders
{
/// <summary>
/// The minimum protocol version that requires standard MCP request headers.
/// The draft MCP protocol version string used to gate behaviors that are only enabled
/// for clients negotiating the in-progress draft specification.
/// </summary>
/// <remarks>
/// Servers enforce missing <c>Mcp-Method</c> and <c>Mcp-Name</c> headers as errors only when
/// the client's <c>MCP-Protocol-Version</c> header indicates this version or later.
/// Clients using older versions are not required to send these headers.
/// Behaviors currently gated on this version include:
/// <list type="bullet">
/// <item><description>
/// Requiring the standard MCP request headers (<c>Mcp-Method</c> and <c>Mcp-Name</c>)
/// on Streamable HTTP POST requests; servers treat missing headers as errors only when
/// the client's <c>MCP-Protocol-Version</c> header matches this value.
/// </description></item>
Comment on lines +17 to +23
/// <item><description>
/// Reporting unresolvable resource URIs from <c>resources/read</c> with the standard
/// JSON-RPC <see cref="McpErrorCode.InvalidParams"/> (-32602) code rather than the
/// legacy <see cref="McpErrorCode.ResourceNotFound"/> (-32002) code.
/// </description></item>
/// </list>
/// The associated helpers perform exact ordinal matches against this single value rather
/// than any ordered comparison.
/// </remarks>
public static readonly string MinVersionForStandardHeaders = "DRAFT-2026-v1";
public const string DraftProtocolVersion = "DRAFT-2026-v1";

/// <summary>The session identifier header.</summary>
public const string SessionId = "Mcp-Session-Id";
Expand Down Expand Up @@ -67,7 +80,7 @@ internal static class McpHttpHeaders
/// </summary>
private static readonly HashSet<string> s_versionsWithStandardHeaders = new(StringComparer.Ordinal)
{
MinVersionForStandardHeaders,
DraftProtocolVersion,
};

/// <summary>
Expand All @@ -82,5 +95,5 @@ public static bool SupportsStandardHeaders(string? protocolVersion)
/// rather than the legacy <see cref="McpErrorCode.ResourceNotFound"/> (-32002).
/// </summary>
internal static bool UseInvalidParamsForMissingResource(string? protocolVersion)
=> string.Equals(protocolVersion, MinVersionForStandardHeaders, StringComparison.Ordinal);
=> string.Equals(protocolVersion, DraftProtocolVersion, StringComparison.Ordinal);
}
Loading