Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions Editor/MCPEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,31 +354,54 @@ private void ConfigureClaudeDesktop()
UnityEngine.Debug.Log($"Using server.py at: {serverPath}");
UnityEngine.Debug.Log($"Python directory: {pythonDir}");

// Create configuration object
var config = new MCPConfig
// Load existing configuration if it exists
dynamic existingConfig = null;
if (File.Exists(configPath))
{
mcpServers = new MCPConfigServers
try
{
unityMCP = new MCPConfigServer
{
command = "uv",
args = new[]
{
"--directory",
pythonDir,
"run",
"server.py"
}
}
string existingJson = File.ReadAllText(configPath);
existingConfig = JsonConvert.DeserializeObject(existingJson);
}
};
catch (Exception ex)
{
UnityEngine.Debug.LogWarning($"Failed to parse existing Claude config: {ex.Message}. Creating new config.");
}
}

// If no existing config or parsing failed, create a new one
if (existingConfig == null)
{
existingConfig = new
{
mcpServers = new Dictionary<string, object>()
};
}

// Create the Unity MCP server configuration
var unityMCPConfig = new MCPConfigServer
{
command = "uv",
args = new[]
{
"--directory",
pythonDir,
"run",
"server.py"
}
};
// Add or update the Unity MCP configuration while preserving the rest
var mcpServers = existingConfig.mcpServers as Newtonsoft.Json.Linq.JObject
?? new Newtonsoft.Json.Linq.JObject();

mcpServers["unityMCP"] = Newtonsoft.Json.Linq.JToken.FromObject(unityMCPConfig);
existingConfig.mcpServers = mcpServers;
// Serialize and write to file with proper formatting
var jsonSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented
};
string jsonConfig = JsonConvert.SerializeObject(config, jsonSettings);
string jsonConfig = JsonConvert.SerializeObject(existingConfig, jsonSettings);
File.WriteAllText(configPath, jsonConfig);

claudeConfigStatus = "Configured successfully";
Expand Down