@@ -106,19 +106,28 @@ public static string GetServerPath()
106
106
/// <summary>
107
107
/// Adds the MCP configuration to the Windsurf MCP config file
108
108
/// </summary>
109
- public static void AddToWindsurfIdeConfig ( bool useTabsIndentation )
109
+ public static bool AddToWindsurfIdeConfig ( bool useTabsIndentation )
110
110
{
111
111
string configFilePath = GetWindsurfMcpConfigPath ( ) ;
112
- AddToConfigFile ( configFilePath , useTabsIndentation , "Windsurf" ) ;
112
+ return AddToConfigFile ( configFilePath , useTabsIndentation , "Windsurf" ) ;
113
113
}
114
114
115
115
/// <summary>
116
116
/// Adds the MCP configuration to the Claude Desktop config file
117
117
/// </summary>
118
- public static void AddToClaudeDesktopConfig ( bool useTabsIndentation )
118
+ public static bool AddToClaudeDesktopConfig ( bool useTabsIndentation )
119
119
{
120
120
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" ) ;
122
131
}
123
132
124
133
/// <summary>
@@ -127,14 +136,15 @@ public static void AddToClaudeDesktopConfig(bool useTabsIndentation)
127
136
/// <param name="configFilePath">Path to the config file</param>
128
137
/// <param name="useTabsIndentation">Whether to use tabs for indentation</param>
129
138
/// <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 )
131
141
{
132
142
try
133
143
{
134
144
if ( string . IsNullOrEmpty ( configFilePath ) )
135
145
{
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 ;
138
148
}
139
149
140
150
// Generate fresh MCP config JSON
@@ -148,17 +158,7 @@ private static void AddToConfigFile(string configFilePath, bool useTabsIndentati
148
158
{
149
159
// Read the existing config
150
160
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 ) ;
162
162
163
163
// Merge the mcpServers from our config into the existing config
164
164
if ( mcpConfig [ "mcpServers" ] != null && mcpConfig [ "mcpServers" ] is JObject mcpServers )
@@ -177,26 +177,26 @@ private static void AddToConfigFile(string configFilePath, bool useTabsIndentati
177
177
178
178
// Write the updated config back to the file
179
179
File . WriteAllText ( configFilePath , existingConfig . ToString ( Formatting . Indented ) ) ;
180
-
181
- EditorUtility . DisplayDialog ( "Success" , $ "MCP Unity configuration added to { productName } .", "OK" ) ;
180
+ return true ;
182
181
}
183
182
}
184
183
else if ( Directory . Exists ( Path . GetDirectoryName ( configFilePath ) ) )
185
184
{
186
185
// Create a new config file with just our config
187
186
File . WriteAllText ( configFilePath , mcpConfigJson ) ;
188
- EditorUtility . DisplayDialog ( "Success" , $ "Created new { productName } config file with MCP Unity configuration." , "OK" ) ;
187
+ return true ;
189
188
}
190
189
else
191
190
{
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") ;
193
192
}
194
193
}
195
194
catch ( Exception ex )
196
195
{
197
- EditorUtility . DisplayDialog ( "Error" , $ "Failed to add MCP configuration to { productName } : { ex . Message } ", "OK" ) ;
198
196
Debug . LogError ( $ "Failed to add MCP configuration to { productName } : { ex } ") ;
199
197
}
198
+
199
+ return false ;
200
200
}
201
201
202
202
/// <summary>
@@ -262,37 +262,38 @@ private static string GetClaudeDesktopConfigPath()
262
262
return Path . Combine ( basePath , "claude_desktop_config.json" ) ;
263
263
}
264
264
265
+
266
+
265
267
/// <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
267
269
/// </summary>
268
- public static void AddToCursorIdeConfig ( )
270
+ /// <returns>The path to the Cursor config file</returns>
271
+ private static string GetCursorConfigPath ( )
269
272
{
270
- try
273
+ // Base path depends on the OS
274
+ string basePath ;
275
+
276
+ if ( Application . platform == RuntimePlatform . WindowsEditor )
271
277
{
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 ) ;
290
281
}
291
- catch ( Exception ex )
282
+ else if ( Application . platform == RuntimePlatform . OSXEditor )
292
283
{
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 ;
295
293
}
294
+
295
+ // Return the path to the mcp_config.json file
296
+ return Path . Combine ( basePath , "mcp.json" ) ;
296
297
}
297
298
}
298
299
}
0 commit comments