Skip to content

Parse JSON arguments correctly in docker mcp tools call#365

Open
Pnkcaht wants to merge 1 commit intodocker:mainfrom
Pnkcaht:fix/issue-307-json-args
Open

Parse JSON arguments correctly in docker mcp tools call#365
Pnkcaht wants to merge 1 commit intodocker:mainfrom
Pnkcaht:fix/issue-307-json-args

Conversation

@Pnkcaht
Copy link
Contributor

@Pnkcaht Pnkcaht commented Jan 24, 2026

What I did

Updated the CLI argument parsing logic for docker mcp tools call to correctly handle complex JSON values passed via the command line.
The CLI now attempts to deserialize argument values as JSON when possible, allowing objects and arrays (e.g. {}, nested maps, lists) to be passed to tools as structured data instead of raw strings.

Related issue

Fixed #307

What was the problem?

When calling MCP tools via the CLI, arguments provided in the form key=value were always treated as plain strings.
This caused failures for tools that expect structured JSON objects, for example:

docker mcp tools call API-patch-page
page_id=''
properties='{}'

Instead of receiving an empty object ({}), the tool received the literal string "{}".
Downstream APIs then attempted to interpret each character of the string as a property key, resulting in validation errors such as:

Couldn't find editable properties for these identifiers: 0,1

As a result:

  • Tools requiring JSON objects or arrays could not be called from the CLI
  • Even valid JSON payloads failed at runtime
  • Users had no way to pass structured arguments reliably

How this change fixes it

The argument parsing logic now attempts to unmarshal each key=value argument as JSON.

Specifically:

  • Each argument value is first treated as a raw string
  • The CLI attempts to json.Unmarshal the value
  • If unmarshalling succeeds, the parsed JSON object (map, slice, number, boolean, etc.) is used
  • If it fails, the value is safely kept as a plain string
  • Repeated keys continue to be aggregated into slices as before

This allows tools to receive structured data exactly as expected, without breaking existing behavior for simple string arguments.

Before / After (Summary)

Before

  • All CLI arguments were passed as strings
  • JSON objects like {} or nested payloads were not supported
  • Tools failed with validation errors when expecting structured input

After

  • JSON objects and arrays are correctly parsed and passed as structured values
  • Simple string arguments continue to work unchanged
  • Tools that require complex inputs can now be invoked reliably from the CLI

Screenshot

How this change fixes it

The CLI argument parsing logic was updated to intelligently interpret argument values as JSON when possible.
In parseArgs, each key=value argument is now processed as follows:

  • The argument is split once into key and rawValue
  • The value is optimistically passed through json.Unmarshal
  • If unmarshalling succeeds, the parsed value (object, array, number, boolean, etc.) is used
  • If unmarshalling fails, the value is treated as a plain string
  • Flag-style arguments without an explicit value continue to be supported
  • Repeated keys are aggregated into slices, preserving existing behavior

This allows users to pass structured JSON payloads (such as {}, nested objects, or arrays) directly via the CLI, while remaining fully backward-compatible with simple string arguments.

image

Signed-off-by: pnkcaht <samzoovsk19@gmail.com>
Copy link

@cutecatfann cutecatfann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker mcp tools call Fails to Parse JSON Arguments, Treating Complex Objects as Strings

2 participants