@@ -106,19 +106,28 @@ public static string GetServerPath()
106106 /// <summary>
107107 /// Adds the MCP configuration to the Windsurf MCP config file
108108 /// </summary>
109- public static void AddToWindsurfIdeConfig ( bool useTabsIndentation )
109+ public static bool AddToWindsurfIdeConfig ( bool useTabsIndentation )
110110 {
111111 string configFilePath = GetWindsurfMcpConfigPath ( ) ;
112- AddToConfigFile ( configFilePath , useTabsIndentation , "Windsurf" ) ;
112+ return AddToConfigFile ( configFilePath , useTabsIndentation , "Windsurf" ) ;
113113 }
114114
115115 /// <summary>
116116 /// Adds the MCP configuration to the Claude Desktop config file
117117 /// </summary>
118- public static void AddToClaudeDesktopConfig ( bool useTabsIndentation )
118+ public static bool AddToClaudeDesktopConfig ( bool useTabsIndentation )
119119 {
120120 string configFilePath = GetClaudeDesktopConfigPath ( ) ;
121- AddToConfigFile ( configFilePath , useTabsIndentation , "Claude Desktop" ) ;
121+ return AddToConfigFile ( configFilePath , useTabsIndentation , "Claude Desktop" ) ;
122+ }
123+
124+ /// <summary>
125+ /// Adds the MCP configuration to the Cursor config file
126+ /// </summary>
127+ public static bool AddToCursorConfig ( bool useTabsIndentation )
128+ {
129+ string configFilePath = GetCursorConfigPath ( ) ;
130+ return AddToConfigFile ( configFilePath , useTabsIndentation , "Cursor" ) ;
122131 }
123132
124133 /// <summary>
@@ -127,14 +136,15 @@ public static void AddToClaudeDesktopConfig(bool useTabsIndentation)
127136 /// <param name="configFilePath">Path to the config file</param>
128137 /// <param name="useTabsIndentation">Whether to use tabs for indentation</param>
129138 /// <param name="productName">Name of the product (for error messages)</param>
130- private static void AddToConfigFile ( string configFilePath , bool useTabsIndentation , string productName )
139+ /// <returns>True if successfuly added the config, false otherwise</returns>
140+ private static bool AddToConfigFile ( string configFilePath , bool useTabsIndentation , string productName )
131141 {
132142 try
133143 {
134144 if ( string . IsNullOrEmpty ( configFilePath ) )
135145 {
136- EditorUtility . DisplayDialog ( "Error" , $ "{ productName } config file not found. Please make sure { productName } is installed." , "OK ") ;
137- return ;
146+ Debug . LogError ( $ "{ productName } config file not found. Please make sure { productName } is installed.") ;
147+ return false ;
138148 }
139149
140150 // Generate fresh MCP config JSON
@@ -148,17 +158,7 @@ private static void AddToConfigFile(string configFilePath, bool useTabsIndentati
148158 {
149159 // Read the existing config
150160 string existingConfigJson = File . ReadAllText ( configFilePath ) ;
151- JObject existingConfig ;
152-
153- try
154- {
155- existingConfig = JObject . Parse ( existingConfigJson ) ;
156- }
157- catch ( JsonException )
158- {
159- // If the file exists but isn't valid JSON, create a new one
160- existingConfig = new JObject ( ) ;
161- }
161+ JObject existingConfig = JObject . Parse ( existingConfigJson ) ;
162162
163163 // Merge the mcpServers from our config into the existing config
164164 if ( mcpConfig [ "mcpServers" ] != null && mcpConfig [ "mcpServers" ] is JObject mcpServers )
@@ -177,26 +177,26 @@ private static void AddToConfigFile(string configFilePath, bool useTabsIndentati
177177
178178 // Write the updated config back to the file
179179 File . WriteAllText ( configFilePath , existingConfig . ToString ( Formatting . Indented ) ) ;
180-
181- EditorUtility . DisplayDialog ( "Success" , $ "MCP Unity configuration added to { productName } .", "OK" ) ;
180+ return true ;
182181 }
183182 }
184183 else if ( Directory . Exists ( Path . GetDirectoryName ( configFilePath ) ) )
185184 {
186185 // Create a new config file with just our config
187186 File . WriteAllText ( configFilePath , mcpConfigJson ) ;
188- EditorUtility . DisplayDialog ( "Success" , $ "Created new { productName } config file with MCP Unity configuration." , "OK" ) ;
187+ return true ;
189188 }
190189 else
191190 {
192- EditorUtility . DisplayDialog ( "Failed" , $ "Cannot find { productName } config file or { productName } is currently not installed. Expecting { productName } to be installed in the { configFilePath } path" , "OK ") ;
191+ Debug . LogError ( $ "Cannot find { productName } config file or { productName } is currently not installed. Expecting { productName } to be installed in the { configFilePath } path") ;
193192 }
194193 }
195194 catch ( Exception ex )
196195 {
197- EditorUtility . DisplayDialog ( "Error" , $ "Failed to add MCP configuration to { productName } : { ex . Message } ", "OK" ) ;
198196 Debug . LogError ( $ "Failed to add MCP configuration to { productName } : { ex } ") ;
199197 }
198+
199+ return false ;
200200 }
201201
202202 /// <summary>
@@ -262,37 +262,38 @@ private static string GetClaudeDesktopConfigPath()
262262 return Path . Combine ( basePath , "claude_desktop_config.json" ) ;
263263 }
264264
265+
266+
265267 /// <summary>
266- /// Adds the MCP configuration to Cursor IDE by generating the command-line format
268+ /// Gets the path to the Cursor config file based on the current OS
267269 /// </summary>
268- public static void AddToCursorIdeConfig ( )
270+ /// <returns>The path to the Cursor config file</returns>
271+ private static string GetCursorConfigPath ( )
269272 {
270- try
273+ // Base path depends on the OS
274+ string basePath ;
275+
276+ if ( Application . platform == RuntimePlatform . WindowsEditor )
271277 {
272- string serverPath = GetServerPath ( ) ;
273- string port = McpUnitySettings . Instance . Port . ToString ( ) ;
274-
275- // Generate the command-line format for Cursor IDE
276- string cursorCommand = $ "env UNITY_PORT={ port } node { serverPath } /build/index.js";
277-
278- // Copy to clipboard
279- EditorGUIUtility . systemCopyBuffer = cursorCommand ;
280-
281- // Show instructions to the user
282- EditorUtility . DisplayDialog (
283- "Cursor IDE Configuration" ,
284- "The Cursor IDE command has been copied to your clipboard. Please add it to Cursor IDE with these settings:\n \n " +
285- "Name: MCP Unity\n " +
286- "Type: command\n " +
287- $ "Command: { cursorCommand } \n \n " +
288- "Go to Cursor → Settings → MCP → Configure and paste this command." ,
289- "OK" ) ;
278+ // Windows: %USERPROFILE%/.cursor
279+ basePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , ".cursor" ) ;
280+ Debug . Log ( basePath ) ;
290281 }
291- catch ( Exception ex )
282+ else if ( Application . platform == RuntimePlatform . OSXEditor )
292283 {
293- EditorUtility . DisplayDialog ( "Error" , $ "Failed to generate Cursor IDE configuration: { ex . Message } ", "OK" ) ;
294- Debug . LogError ( $ "Failed to generate Cursor IDE configuration: { ex } ") ;
284+ // macOS: ~/Library/Application Support/.cursor
285+ string homeDir = Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ;
286+ basePath = Path . Combine ( homeDir , "Library" , "Application Support" , ".cursor" ) ;
287+ }
288+ else
289+ {
290+ // Unsupported platform
291+ Debug . LogError ( "Unsupported platform for Cursor MCP config" ) ;
292+ return null ;
295293 }
294+
295+ // Return the path to the mcp_config.json file
296+ return Path . Combine ( basePath , "mcp.json" ) ;
296297 }
297298 }
298299}
0 commit comments