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

  1. Open ~/.openclaw/openclaw.json in a text editor and validate it with a JSON linter; fix the syntax error, then click Configure again.
  2. If the file is unrecoverable, back it up, delete it, and let MCP for Unity create a fresh config via Configure().
  3. 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

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


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/9773d0084a10b6c8. Report an issue: GitHub.