docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class McpToolAttribute

    Marks a static method or class as an MCP tool that can be invoked by MCP clients. Tools are automatically discovered at editor startup using Unity's TypeCache system.

    Inheritance
    object
    Attribute
    McpToolAttribute
    Implements
    _Attribute
    Inherited Members
    Attribute.Equals(object)
    Attribute.GetCustomAttribute(Assembly, Type)
    Attribute.GetCustomAttribute(Assembly, Type, bool)
    Attribute.GetCustomAttribute(MemberInfo, Type)
    Attribute.GetCustomAttribute(MemberInfo, Type, bool)
    Attribute.GetCustomAttribute(Module, Type)
    Attribute.GetCustomAttribute(Module, Type, bool)
    Attribute.GetCustomAttribute(ParameterInfo, Type)
    Attribute.GetCustomAttribute(ParameterInfo, Type, bool)
    Attribute.GetCustomAttributes(Assembly)
    Attribute.GetCustomAttributes(Assembly, bool)
    Attribute.GetCustomAttributes(Assembly, Type)
    Attribute.GetCustomAttributes(Assembly, Type, bool)
    Attribute.GetCustomAttributes(MemberInfo)
    Attribute.GetCustomAttributes(MemberInfo, bool)
    Attribute.GetCustomAttributes(MemberInfo, Type)
    Attribute.GetCustomAttributes(MemberInfo, Type, bool)
    Attribute.GetCustomAttributes(Module)
    Attribute.GetCustomAttributes(Module, bool)
    Attribute.GetCustomAttributes(Module, Type)
    Attribute.GetCustomAttributes(Module, Type, bool)
    Attribute.GetCustomAttributes(ParameterInfo)
    Attribute.GetCustomAttributes(ParameterInfo, bool)
    Attribute.GetCustomAttributes(ParameterInfo, Type)
    Attribute.GetCustomAttributes(ParameterInfo, Type, bool)
    Attribute.GetHashCode()
    Attribute.IsDefaultAttribute()
    Attribute.IsDefined(Assembly, Type)
    Attribute.IsDefined(Assembly, Type, bool)
    Attribute.IsDefined(MemberInfo, Type)
    Attribute.IsDefined(MemberInfo, Type, bool)
    Attribute.IsDefined(Module, Type)
    Attribute.IsDefined(Module, Type, bool)
    Attribute.IsDefined(ParameterInfo, Type)
    Attribute.IsDefined(ParameterInfo, Type, bool)
    Attribute.Match(object)
    Attribute.TypeId
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.AI.MCP.Editor.ToolRegistry
    Assembly: Unity.AI.MCP.Editor.dll
    Syntax
    [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = false)]
    public class McpToolAttribute : Attribute, _Attribute
    Remarks

    This attribute can be applied to:

    1. Static methods with 0-1 parameters (method-based tools)
    2. Classes implementing IUnityMcpTool or IUnityMcpTool<TParams> (class-based tools)

    Method-based tools:

    • Must be public static
    • Can have 0 parameters, 1 typed parameter, or 1 JObject parameter
    • Schemas auto-generated for typed parameters
    • Use [McpSchema] attribute for custom schemas with JObject parameters

    Class-based tools:

    • Must have a public parameterless constructor
    • Instantiated once at discovery time
    • Useful when tools need state or complex initialization

    Tool names must be unique across the project. Duplicate names will generate warnings.

    Examples

    Method-based tool with typed parameters:

    public class MyParams
    {
        public string Name { get; set; }
    }
    

    [McpTool("my_tool", "Does something useful")] public static object MyTool(MyParams params) { return new { result = $"Hello " }; }

    Class-based tool:

    [McpTool("stateful_tool", "Tool with state")]
    public class StatefulTool : IUnityMcpTool<MyParams>
    {
        private int callCount = 0;
    
    public object Execute(MyParams parameters)
    {
        callCount++;
        return new { calls = callCount };
    }
    

    }

    Constructors

    McpToolAttribute(string, string, string, object)

    Creates an MCP tool attribute to mark a method or class as a discoverable tool.

    Declaration
    public McpToolAttribute(string name, string description = null, string title = null, object annotations = null)
    Parameters
    Type Name Description
    string name

    The unique name of the tool as exposed to MCP clients (use snake_case)

    string description

    Human-readable description of what the tool does. If null, defaults to the tool name

    string title

    Optional display title. If null, defaults to the description

    object annotations

    Optional MCP annotations object describing tool characteristics

    Exceptions
    Type Condition
    ArgumentException

    Thrown if name is null or empty

    Properties

    Annotations

    Gets or sets optional MCP annotations describing tool behavior. Annotations can provide hints to clients about tool characteristics (e.g., side effects, cost).

    Declaration
    public object Annotations { get; set; }
    Property Value
    Type Description
    object

    Description

    Gets the description of what the tool does. This description is sent to MCP clients and may be used by AI models to understand tool purpose.

    Declaration
    public string Description { get; }
    Property Value
    Type Description
    string

    EnabledByDefault

    Gets or sets whether this tool is enabled by default when no user override exists. Tools with this set to true are part of the curated default set shown as enabled in the settings UI. New or unvalidated tools should leave this as false.

    Declaration
    public bool EnabledByDefault { get; set; }
    Property Value
    Type Description
    bool

    Groups

    Gets or sets category tags for organizing and filtering tools. Use string identifiers from ToolCategory enum (e.g., "scripting", "scene", "assets").

    Declaration
    public string[] Groups { get; set; }
    Property Value
    Type Description
    string[]

    Name

    Gets the unique name of the tool as exposed to MCP clients. Tool names should use snake_case convention (e.g., "my_tool", "read_file").

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    string

    Title

    Gets the display title of the tool (optional). If not specified, the Description is used as the title.

    Declaration
    public string Title { get; }
    Property Value
    Type Description
    string

    Implements

    _Attribute
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)