Skip to content

Commit f972af3

Browse files
committed
feat(editor): Add config buttons for Claude Code and GitHub Copilot to MCP Inspector
refactor(editor): Abstract and unify config button logic in Inspector window
1 parent edf7b75 commit f972af3

File tree

3 files changed

+92
-42
lines changed

3 files changed

+92
-42
lines changed

Editor/UnityBridge/McpUnityEditorWindow.cs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using McpUnity.Utils;
23
using UnityEngine;
34
using UnityEditor;
@@ -55,7 +56,7 @@ private void OnGUI()
5556
DrawHelpTab();
5657
break;
5758
}
58-
59+
5960
// Version info at the bottom
6061
GUILayout.FlexibleSpace();
6162
WrappedLabel($"MCP Unity v{McpUnitySettings.ServerVersion}", EditorStyles.miniLabel, GUILayout.Width(150));
@@ -247,49 +248,24 @@ private void DrawServerTab()
247248

248249
EditorGUILayout.Space();
249250

250-
if (GUILayout.Button("Configure Windsurf IDE", GUILayout.Height(30)))
251-
{
252-
bool added = McpUtils.AddToWindsurfIdeConfig(_tabsIndentationJson);
253-
if (added)
254-
{
255-
EditorUtility.DisplayDialog("Success", "The MCP configuration was successfully added to the Windsurf config file.", "OK");
256-
}
257-
else
258-
{
259-
EditorUtility.DisplayDialog("Error", "The MCP configuration could not be added to the Windsurf config file.", "OK");
260-
}
261-
}
251+
ShowConfigButton("Windsurf", McpUtils.AddToWindsurfIdeConfig);
262252

263253
EditorGUILayout.Space();
264254

265-
if (GUILayout.Button("Configure Claude Desktop", GUILayout.Height(30)))
266-
{
267-
bool added = McpUtils.AddToClaudeDesktopConfig(_tabsIndentationJson);
268-
if (added)
269-
{
270-
EditorUtility.DisplayDialog("Success", "The MCP configuration was successfully added to the Claude Desktop config file.", "OK");
271-
}
272-
else
273-
{
274-
EditorUtility.DisplayDialog("Error", "The MCP configuration could not be added to the Claude Desktop config file.", "OK");
275-
}
276-
}
255+
ShowConfigButton("Claude Desktop", McpUtils.AddToClaudeDesktopConfig);
277256

278257
EditorGUILayout.Space();
279258

280-
if (GUILayout.Button("Configure Cursor", GUILayout.Height(30)))
281-
{
282-
bool added = McpUtils.AddToCursorConfig(_tabsIndentationJson);
283-
if (added)
284-
{
285-
EditorUtility.DisplayDialog("Success", "The MCP configuration was successfully added to the Cursor config file.", "OK");
286-
}
287-
else
288-
{
289-
EditorUtility.DisplayDialog("Error", "The MCP configuration could not be added to the Cursor Desktop config file.", "OK");
290-
}
291-
}
292-
259+
ShowConfigButton("Cursor", McpUtils.AddToCursorConfig);
260+
261+
EditorGUILayout.Space();
262+
263+
ShowConfigButton("Claude Code", McpUtils.AddToClaudeCodeConfig);
264+
265+
EditorGUILayout.Space();
266+
267+
ShowConfigButton("GitHub Copilot", McpUtils.AddToGitHubCopilotConfig);
268+
293269
EditorGUILayout.Separator();
294270
EditorGUILayout.Separator();
295271

@@ -618,6 +594,26 @@ private void WrappedLabel(string text, GUIStyle style = null, params GUILayoutOp
618594

619595
EditorGUILayout.LabelField(text, wrappedStyle, options);
620596
}
597+
598+
599+
600+
// Helper to show a config button with unified logic
601+
private void ShowConfigButton(string configLabel, Func<bool, bool> configAction)
602+
{
603+
if (GUILayout.Button($"Configure {configLabel}", GUILayout.Height(30)))
604+
{
605+
bool added = configAction(_tabsIndentationJson);
606+
if (added)
607+
{
608+
EditorUtility.DisplayDialog("Success", $"The MCP configuration was successfully added to the {configLabel} config file.", "OK");
609+
}
610+
else
611+
{
612+
EditorUtility.DisplayDialog("Error", $"The MCP configuration could not be added to the {configLabel} config file.", "OK");
613+
}
614+
}
615+
}
616+
621617

622618
#endregion
623619
}

Editor/UnityBridge/McpUnitySettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace McpUnity.Unity
1313
public class McpUnitySettings
1414
{
1515
// Constants
16-
public const string ServerVersion = "1.1.1";
16+
public const string ServerVersion = "1.1.2";
1717
public const string PackageName = "com.gamelovers.mcp-unity";
1818
public const int RequestTimeoutMinimum = 10;
1919

Editor/Utils/McpUtils.cs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ public static bool AddToCursorConfig(bool useTabsIndentation)
150150
string configFilePath = GetCursorConfigPath();
151151
return AddToConfigFile(configFilePath, useTabsIndentation, "Cursor");
152152
}
153+
154+
/// <summary>
155+
/// Adds the MCP configuration to the Claude Code config file
156+
/// </summary>
157+
public static bool AddToClaudeCodeConfig(bool useTabsIndentation)
158+
{
159+
string configFilePath = GetClaudeCodeConfigPath();
160+
return AddToConfigFile(configFilePath, useTabsIndentation, "Claude Code");
161+
}
162+
163+
/// <summary>
164+
/// Adds the MCP configuration to the GitHub Copilot config file
165+
/// </summary>
166+
public static bool AddToGitHubCopilotConfig(bool useTabsIndentation)
167+
{
168+
string configFilePath = GetGitHubCopilotConfigPath();
169+
return AddToConfigFile(configFilePath, useTabsIndentation, "GitHub Copilot");
170+
}
153171

154172
/// <summary>
155173
/// Common method to add MCP configuration to a specified config file
@@ -281,9 +299,7 @@ private static string GetClaudeDesktopConfigPath()
281299
// Return the path to the claude_desktop_config.json file
282300
return Path.Combine(basePath, "claude_desktop_config.json");
283301
}
284-
285-
286-
302+
287303
/// <summary>
288304
/// Gets the path to the Cursor config file based on the current OS
289305
/// </summary>
@@ -315,6 +331,44 @@ private static string GetCursorConfigPath()
315331
return Path.Combine(basePath, "mcp.json");
316332
}
317333

334+
/// <summary>
335+
/// Gets the path to the Claude Code config file based on the current OS
336+
/// </summary>
337+
/// <returns>The path to the Claude Code config file</returns>
338+
private static string GetClaudeCodeConfigPath()
339+
{
340+
string basePath;
341+
if (Application.platform == RuntimePlatform.WindowsEditor)
342+
{
343+
// Windows: %USERPROFILE%\.claude-code\mcp.json
344+
basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".claude-code");
345+
}
346+
else if (Application.platform == RuntimePlatform.OSXEditor)
347+
{
348+
// macOS: ~/.claude-code/mcp.json
349+
string homeDir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
350+
basePath = Path.Combine(homeDir, ".claude-code");
351+
}
352+
else
353+
{
354+
Debug.LogError("Unsupported platform for Claude Code MCP config");
355+
return null;
356+
}
357+
return Path.Combine(basePath, "mcp.json");
358+
}
359+
360+
/// <summary>
361+
/// Gets the path to the GitHub Copilot config file (workspace .vscode/mcp.json)
362+
/// </summary>
363+
/// <returns>The path to the GitHub Copilot config file</returns>
364+
private static string GetGitHubCopilotConfigPath()
365+
{
366+
// Default to current Unity project root/.vscode/mcp.json
367+
string projectRoot = Directory.GetParent(Application.dataPath).FullName;
368+
string vscodeDir = Path.Combine(projectRoot, ".vscode");
369+
return Path.Combine(vscodeDir, "mcp.json");
370+
}
371+
318372
/// <summary>
319373
/// Runs an npm command (such as install or build) in the specified working directory.
320374
/// Handles cross-platform compatibility (Windows/macOS/Linux) for invoking npm.

0 commit comments

Comments
 (0)