Skip to content

🐞 Bug Report: JSON Parameter Parsing Fails on Windows Due to Quoting in Command Construction #33

@ejgarner118

Description

@ejgarner118

🐞 Bug Report: JSON Parameter Parsing Fails on Windows Due to Quoting in Command Construction

Summary

When using the godot-mcp server on Windows, all scene and node creation commands that require JSON parameters fail with a parsing error. This is due to how the Node.js server constructs the Godot command, specifically the quoting of the JSON string for Windows shells.


Symptoms / Error Output

Attempts to create a scene or add a node result in errors like:

Failed to parse JSON parameters: '{scene_path:main_scene_tscn.tscn,node_type:MeshInstance3D,node_name:Primitive,parent_node_path:root}'
JSON Error: Unexpected character at line 0
SCRIPT ERROR: Invalid access to property or key 'scene_path' on a base object of type 'Nil'.
   at: add_node (res://godot-mcp/build/scripts/godot_operations.gd:469)
  • The JSON string is not valid JSON (uses single quotes and unquoted keys).

How to Reproduce

  1. Set up godot-mcp on Windows as per the README.
  2. Attempt to use any MCP tool that passes JSON parameters (e.g., add_node, create_scene).
  3. Observe the error in the output and in the Godot debug logs.

Root Cause Analysis

  • The Node.js server serializes parameters to JSON, then wraps the string in single quotes when building the command:
    `'${escapedParams}'`
  • On Windows, the shell passes the single quotes literally, so Godot receives:
    '{scene_path:main_scene_tscn.tscn,node_type:MeshInstance3D,node_name:Primitive,parent_node_path:root}'
    
    instead of valid JSON:
    {"scene_path":"main_scene_tscn.tscn","node_type":"MeshInstance3D","node_name":"Primitive","parent_node_path":"root"}
    
  • Godot’s JSON parser fails, causing all parameterized operations to break.

What We Noticed

  • The issue only occurs on Windows, not on Unix-like shells (where single quotes are stripped by the shell).
  • The error is consistent for all MCP operations that pass JSON parameters.
  • The Node.js code uses single quotes for all platforms, which is not compatible with Windows command-line parsing.

How We Fixed It

We patched the MCP server’s executeOperation function to use double quotes for the JSON parameter on Windows, and single quotes elsewhere:

const isWindows = process.platform === 'win32';
const quotedParams = isWindows
    ? `\"${paramsJson.replace(/\"/g, '\\"')}\"`
    : `'${escapedParams}'`;

This ensures the JSON string is passed as valid JSON to Godot on all platforms.


Suggested Fix

Update the MCP server’s command construction logic to detect Windows and use double quotes for the JSON parameter, or otherwise ensure the JSON string is passed as valid JSON to Godot.


Additional Context

  • MCP server version: (latest as of July 2024)
  • Godot version: 4.4.1.stable.official.49a5bc7b6
  • Node.js version: (your version here)
  • OS: Windows 10

Thank you for this awesome tool! Let us know if you need any more details or a PR with the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions