Class McpHeaderAttribute
- Namespace
- ModelContextProtocol.Server
- Assembly
- ModelContextProtocol.Core.dll
Indicates that a tool parameter should be mirrored as an HTTP header in client requests.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Parameter)]
public sealed class McpHeaderAttribute : Attribute
- Inheritance
-
McpHeaderAttribute
- Inherited Members
Examples
[McpServerTool]
public static string ExecuteSql(
[McpHeader("Region")] string region,
string query)
{
// The client will add header: Mcp-Param-Region: {region value}
}
Remarks
When applied to a parameter, the SDK will include an x-mcp-header extension property
in the parameter's JSON schema. Clients will then mirror this parameter's value into an
HTTP header named Mcp-Param-{Name}.
Only parameters with primitive types (integer, string, boolean) may use this attribute. The header name must match HTTP field-name token syntax (tchar per RFC 9110 Section 5.6.2) and must be case-insensitively unique within the tool's input schema.
This enables network infrastructure such as load balancers, proxies, and gateways to make routing decisions based on tool parameter values without parsing the JSON-RPC request body.
Constructors
McpHeaderAttribute(string)
Initializes a new instance of the McpHeaderAttribute class.
public McpHeaderAttribute(string name)
Parameters
namestringThe name portion of the header. The full header name will be
Mcp-Param-{name}. Must match HTTP field-name token syntax (tchar per RFC 9110 Section 5.6.2).
Exceptions
- ArgumentException
The name is null, empty, or contains invalid characters.
Properties
Name
Gets the name portion of the header.
public string Name { get; }
Property Value
Remarks
The full header name sent by clients will be Mcp-Param-{Name}.