CoplayDev/unity-mcp · error · InvalidOperationException
OpenClaw config contains non-JSON content and cannot be safe
Error message
OpenClaw config contains non-JSON content and cannot be safely auto-edited: {ex.Message} What it means
OpenClawConfigurator.LoadConfig() reads ~/.openclaw/openclaw.json and attempts JsonConvert.DeserializeObject<JObject>. If the file content fails JSON parsing (JsonException), the method throws InvalidOperationException rather than silently overwriting the user's file. This is a deliberate data-safety guard: auto-editing a corrupt or non-JSON file could destroy the user's entire OpenClaw configuration.
Source
Thrown at MCPForUnity/Editor/Clients/Configurators/OpenClawConfigurator.cs:183
"OpenClaw exposes a proxy tool such as unityMCP__call for Unity MCP access",
"Restart OpenClaw if the plugin does not hot-reload the new config"
};
private JObject LoadConfig(string path)
{
string text = File.ReadAllText(path);
if (string.IsNullOrWhiteSpace(text))
{
return new JObject();
}
try
{
return JsonConvert.DeserializeObject<JObject>(text) ?? new JObject();
}
catch (JsonException ex)
{
throw new InvalidOperationException(
$"OpenClaw config contains non-JSON content and cannot be safely auto-edited: {ex.Message}");
}
}
private JObject FindUnityServer(JToken serversToken)
{
if (serversToken is JObject serverMap)
{
return serverMap[ServerName] as JObject;
}
if (serversToken is JArray legacyServers)
{
foreach (JToken token in legacyServers)
{
JObject server = token as JObject;
if (server == null)
{View on GitHub (pinned to c21bf496bc)
Solutions
- Open ~/.openclaw/openclaw.json in a text editor and validate it with a JSON linter; fix the syntax error, then click Configure again.
- If the file is unrecoverable, back it up, delete it, and let MCP for Unity create a fresh config via Configure().
- Run the JSON through `python -m json.tool ~/.openclaw/openclaw.json` to locate the exact parse error position.
Defensive patterns
Strategy: try-catch
Validate before calling
string text = File.ReadAllText(path);
try { JToken.Parse(text); }
catch (JsonException) { /* do not auto-edit; prompt user to fix manually */ } Try / catch
try { configurator.Configure(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("non-JSON content"))
{ ShowUserError("OpenClaw config is corrupt. Fix or delete ~/.openclaw/openclaw.json manually."); } Prevention
- Validate JSON with a linter before letting the configurator auto-edit.
- Back up config files before bulk configure operations.
- Avoid manual edits to openclaw.json while MCP for Unity is running.
When it happens
Trigger: CheckStatus() or Configure() is called when ~/.openclaw/openclaw.json exists but contains syntax errors, truncated content, TOML/INI/YAML instead of JSON, or text from a failed manual edit.
Common situations: The user hand-edited openclaw.json and left a trailing comma or missing brace. The file was partially written by a crashed process. The user pasted a snippet in the wrong format. Another tool overwrote the file with non-JSON content.
Related errors
- uvx not found. Install uv/uvx or set the override in Advance
- Failed to unregister: {ex.Message}
- Cherry Studio uses UI-based configuration. Please use the Ma
- uvx not found. Install uv/uvx or set the override in Advance
- uvx not found. Install uv/uvx or set the override in Advance
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/9773d0084a10b6c8.
Report an issue: GitHub.