Table of Contents

Class McpMetaAttribute

Namespace
ModelContextProtocol.Server
Assembly
ModelContextProtocol.Core.dll

Used to specify metadata for an MCP server primitive (tool, prompt, or resource).

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class McpMetaAttribute : Attribute
Inheritance
McpMetaAttribute
Inherited Members

Examples

[McpServerTool]
[McpMeta("model", "gpt-4o")]
[McpMeta("version", "1.0")]
[McpMeta("priority", 5.0)]
[McpMeta("isBeta", true)]
[McpMeta("tags", JsonValue = """["a","b"]""")]
public string MyTool(string input) => $"Processed: {input}";

Remarks

The metadata is used to populate the Meta, Meta, or Meta property of the corresponding primitive.

This attribute can be applied multiple times to a method to specify multiple key/value pairs of metadata. However, the same key should not be used more than once; doing so will result in undefined behavior.

Metadata can be used to attach additional information to primitives, such as model preferences, version information, or other custom data that should be communicated to MCP clients.

Constructors

McpMetaAttribute(string, bool)

Initializes a new instance of the McpMetaAttribute class with a boolean value.

public McpMetaAttribute(string name, bool value)

Parameters

name string

The name (key) of the metadata entry.

value bool

The boolean value of the metadata entry.

McpMetaAttribute(string, double)

Initializes a new instance of the McpMetaAttribute class with a double value.

public McpMetaAttribute(string name, double value)

Parameters

name string

The name (key) of the metadata entry.

value double

The double value of the metadata entry.

McpMetaAttribute(string, string?)

Initializes a new instance of the McpMetaAttribute class with a string value.

public McpMetaAttribute(string name, string? value = null)

Parameters

name string

The name (key) of the metadata entry.

value string

The string value of the metadata entry. If null, the value will be serialized as JSON null.

Properties

JsonValue

Gets or sets the value of the metadata entry as a JSON string.

public string JsonValue { get; set; }

Property Value

string

Remarks

This value must be well-formed JSON. It will be parsed and added to the metadata JsonObject. Simple values can be represented as JSON literals like "\"my-string\"", "123", "true", etc. Complex structures can be represented as JSON objects or arrays.

Setting this property will override any value provided via the constructor.

For programmatic scenarios where you want to construct complex metadata without dealing with JSON strings, use the Meta, Meta, or Meta property to provide a JsonObject directly.

Name

Gets the name (key) of the metadata entry.

public string Name { get; }

Property Value

string

Remarks

This value is used as the key in the metadata object. It should be a unique identifier for this piece of metadata within the context of the primitive.