Class McpDescriptionAttribute
Provides descriptions and constraints for MCP tool parameter properties. Applied to properties in parameter classes to enhance automatically generated schemas.
Implements
Inherited Members
Namespace: Unity.AI.MCP.Editor.ToolRegistry
Assembly: Unity.AI.MCP.Editor.dll
Syntax
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]
public class McpDescriptionAttribute : Attribute, _Attribute
Remarks
This attribute enhances schema generation by providing:
- Human-readable descriptions for properties
- Required field markers
- Enum constraints for string properties
- Explicit default values (overriding property initializers)
The SchemaGenerator reads this attribute when generating input schemas for tools using typed parameters.
Examples
public class CreateObjectParams
{
[McpDescription("Name of the object to create", Required = true)]
public string Name { get; set; }
[McpDescription("Object type", EnumType = typeof(ObjectType))]
public string Type { get; set; } = "cube";
[McpDescription("Scale multiplier", Default = 1.0)]
public float Scale { get; set; }
[McpDescription("Position in world space")]
public Vector3 Position { get; set; }
}
public enum ObjectType { Cube, Sphere, Cylinder }
Constructors
McpDescriptionAttribute(string)
Creates a description attribute for an MCP tool parameter property.
Declaration
public McpDescriptionAttribute(string description)
Parameters
| Type | Name | Description |
|---|---|---|
| string | description | Human-readable description text that explains the parameter's purpose and expected values |
Properties
Default
Gets or sets an explicit default value for this parameter. Takes precedence over property initializers when generating the JSON schema.
Declaration
public object Default { get; set; }
Property Value
| Type | Description |
|---|---|
| object |
Remarks
When set, this value will be used in the JSON schema's "default" field. If not set, the schema generator will attempt to detect defaults from property initializers. For enum properties, the default will be automatically converted to its string representation.
Description
Gets the human-readable description for this parameter property. This appears in the generated JSON schema and helps MCP clients understand the parameter's purpose.
Declaration
public string Description { get; }
Property Value
| Type | Description |
|---|---|
| string |
EnumType
Gets or sets an enum type to use for constraining string property values. The enum values will be converted to string constraints in the JSON schema.
Declaration
public Type EnumType { get; set; }
Property Value
| Type | Description |
|---|---|
| Type |
Remarks
This is useful when you want to constrain a string property to specific values without changing the property type from string. If the property itself is an enum type, this is not needed.
HasDefault
Gets whether an explicit default value was set via the Default property. Used internally by SchemaGenerator to distinguish between null defaults and no defaults.
Declaration
public bool HasDefault { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Required
Gets or sets whether this parameter is required. Required parameters must be provided by the MCP client; optional parameters may be omitted.
Declaration
public bool Required { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Value types without default values are automatically considered required. Set this to true to explicitly mark reference types as required.