Skip to content

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

@j450nhuang

Description

@j450nhuang

🐞 Bug Report: docker mcp tools call Fails to Parse JSON Arguments, Treating Complex Objects as Strings

Summary

The docker mcp tools call command line utility fails to correctly parse arguments provided as complex JSON objects (e.g., '{"key": "value"}'). Instead of deserializing the string into a nested object/map, the Go CLI passes the literal JSON string to the tool handler. This leads to validation errors in downstream APIs, as the API wrapper attempts to process the JSON string's characters as if they were property keys.

Affected Component(s)

  • mcp-cli / docker mcp tools call
  • File: .../cli/tools/call.go (specifically the parseArgs function)

Version

  • MCP Gateway/CLI Version: (Please Specify Version)
  • Go runtime version: (Please Specify Version)

Steps to Reproduce

  1. Set up a tool (e.g., API-patch-page) that expects a complex JSON object for an argument (e.g., properties).

  2. Attempt to call the tool with a valid, quoted JSON payload.

    docker mcp tools call API-patch-page \
    page_id='<VALID_UUID>' \
    properties='{"Test":{"rich_text":[{"text":{"content":"test content"}}]}}'
  3. Alternatively, use the simplest JSON object:

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

Observed Behavior

The command fails with a validation_error because the tool receives the properties value as a literal string ("{}") and tries to process its characters ({ and }) as property identifiers.

  • Error Message (for properties='{}'):
    {"status":400,"object":"error","code":"validation_error","message":"Couldn't find editable properties for these identifiers: 0,1","request_id":"..."}
  • Root Cause: The identifiers 0 and 1 correspond to the character indices of the string "{"}" which the tool is incorrectly trying to use as property names.

Technical Analysis (Root Cause)

The issue is that the parseArgs function only assigns the value as a raw string without checking if it contains JSON.

The problematic code in parseArgs:

// ... inside parseArgs function ...

if len(parts) == 2 {
    key = parts[0]
    value = parts[1] // <-- value is always a Go string here, even if it contains JSON.
} 

// ...

Proposed Solution (Fix in call.go)

The parseArgs function must attempt to unmarshal (decode) the string value as JSON. If the unmarshalling is successful, the resulting complex object should be used; otherwise, the value should remain a simple string.

The corrected logic for the value assignment block in parseArgs should look like this:

import (
    "encoding/json" 
    "strings"
)

// ... inside parseArgs function ...

if len(parts) == 2 {
    key = parts[0]
    rawValue := parts[1] // The value is a string here
    
    // FIX: Attempt to parse the string as JSON
    var parsedValue any
    if err := json.Unmarshal([]byte(rawValue), &parsedValue); err == nil {
        // Success: The string was valid JSON
        value = parsedValue
    } else {
        // Failure: The string is a simple value (or invalid JSON)
        value = rawValue 
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions