You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Unity-MCP-Plugin/.claude/skills/unity-skill-create/SKILL.md
+1-137Lines changed: 1 addition & 137 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,143 +5,7 @@ description: |-
5
5
6
6
It must be a partial class decorated with [McpPluginToolType]. Each tool method must be decorated with [McpPluginTool]. The class name should match the file name. All Unity API calls must use com.IvanMurzak.ReflectorNet.Utils.MainThread.Instance.Run(). Return a data model for structured output, or void for side-effect-only operations.
7
7
8
-
Full sample:
9
-
```csharp
10
-
#nullable enable
11
-
using System;
12
-
using System.ComponentModel;
13
-
using com.IvanMurzak.McpPlugin;
14
-
using com.IvanMurzak.ReflectorNet.Utils;
15
-
using com.IvanMurzak.Unity.MCP.Editor.Utils;
16
-
using AIGD;
17
-
using UnityEditor;
18
-
using UnityEngine;
19
-
20
-
namespace com.IvanMurzak.Unity.MCP.Editor.API
21
-
{
22
-
[McpPluginToolType]
23
-
public partial class Tool_Sample
24
-
{
25
-
[McpPluginTool("sample-get", Title = "Sample / Get")]
26
-
[Description("Finds a GameObject and returns its ref data.")]
27
-
public GameObjectRef Get
28
-
(
29
-
[Description("Name of the GameObject to find.")]
30
-
string name
31
-
)
32
-
{
33
-
return MainThread.Instance.Run(() =>
34
-
{
35
-
var go = GameObject.Find(name)
36
-
?? throw new ArgumentException($"GameObject '{name}' not found.", nameof(name));
37
-
38
-
return new GameObjectRef(go);
39
-
});
40
-
}
41
-
42
-
[McpPluginTool("sample-rename", Title = "Sample / Rename")]
43
-
[Description("Renames a GameObject.")]
44
-
public void Rename
45
-
(
46
-
[Description("Current name of the GameObject.")]
47
-
string name,
48
-
[Description("New name to assign.")]
49
-
string newName
50
-
)
51
-
{
52
-
MainThread.Instance.Run(() =>
53
-
{
54
-
var go = GameObject.Find(name)
55
-
?? throw new ArgumentException($"GameObject '{name}' not found.", nameof(name));
If the skill modifies anything visually in the Unity Editor (GameObjects, components, materials, etc.), call these two lines at the end of the tool method to apply changes to the UI immediately:
### Refresh AssetDatabase after asset or script changes
76
-
If the skill creates, modifies, or deletes any asset file or .cs script on disk outside of Unity API, call this inside a `MainThread.Instance.Run()` block to ensure Unity picks up the changes:
### Use processing mechanic for long-running or domain-reload operations
85
-
Some operations take time to complete and may trigger a Unity domain reload (e.g. writing a .cs script, switching play mode, running tests, adding a package). In these cases the tool must NOT block and wait — instead it must:
86
-
1. Accept a `[RequestID] string? requestId` parameter.
Result = ResponseCallTool.Success("Operation completed.").SetRequestID(requestId)
95
-
});
96
-
```
97
-
If the operation may survive a domain reload (e.g. a .cs file was saved and Unity will recompile), use `ScriptUtils.SchedulePostCompilationNotification(requestId, filePath, operationType)` instead of calling `NotifyToolRequestCompleted` directly — it persists the pending notification to `SessionState` and sends it automatically after the domain reload completes. For package install/removal or other non-compilation domain reloads use `PackageUtils.SchedulePostDomainReloadNotification(requestId, label, action, expectedResult)` the same way.
98
-
99
-
### Return structured data with a typed response
100
-
Prefer returning a structured data model over a plain string so the AI can parse individual fields. Data models for MCP tools MUST be declared as TOP-LEVEL types in the `AIGD` namespace - never nested inside the tool class. Place each data model in its own `.cs` file (one type per file) and use `ResponseCallValueTool<T>` as the return type. The flat `AIGD` namespace keeps the auto-generated JSON Schema `$defs` keys short and intuitive for AI agents.
101
-
```csharp
102
-
// Tool file (Tool/MyTool.cs) - references the data model from AIGD:
103
-
using AIGD;
104
-
105
-
namespace com.IvanMurzak.Unity.MCP.Editor.API
106
-
{
107
-
[McpPluginToolType]
108
-
public partial class Tool_Sample
109
-
{
110
-
public ResponseCallValueTool<MyResult> MyTool(...)
// Data model (Tool/Data/MyResult.cs) - top-level, in AIGD namespace, NOT nested:
122
-
namespace AIGD
123
-
{
124
-
public class MyResult
125
-
{
126
-
[Description("Name of the GameObject.")]
127
-
public string? Name { get; set; }
128
-
129
-
[Description("Unity instance ID of the GameObject.")]
130
-
public int InstanceID { get; set; }
131
-
}
132
-
}
133
-
```
134
-
For simpler cases that do not need async/processing, you may return the model directly (without `ResponseCallValueTool<T>`) and Unity-MCP will wrap it automatically. The data model itself MUST still live as a top-level type in the `AIGD` namespace.
135
-
136
-
### Validate inputs early and throw clearly
137
-
Always validate required parameters at the top of the method before any Unity API calls. Throw `ArgumentException` or `InvalidOperationException` with descriptive messages so the AI knows exactly what went wrong and can self-correct:
138
-
```csharp
139
-
if (string.IsNullOrEmpty(name))
140
-
throw new ArgumentException("Name cannot be null or empty.", nameof(name));
141
-
```
142
-
143
-
### Always use MainThread for Unity API calls
144
-
All Unity API calls (including `GameObject.Find`, `AssetDatabase`, `EditorUtility`, etc.) MUST run on the main thread. Wrap them in `MainThread.Instance.Run(() => { ... })` for synchronous operations, or `MainThread.Instance.RunAsync(async () => { ... })` when you need to await inside.
0 commit comments