Skip to content

[Bug]: MCP tool calls fail when LLMs serialize array/object parameters as strings (MiMo, Ollama, etc.) #96916

Closed

Description

@visail

Summary

MCP tool calls fail with validation errors when LLMs serialize array parameters as JSON strings (e.g., "tags": "[\"test\",\"debug\"]" instead of "tags": ["test","debug"]). OpenClaw's validateToolArguments cannot coerce stringified JSON arrays/objects back to their expected types, causing all MCP tools with array or object typed parameters to fail with certain providers.

Environment

  • OpenClaw version: 2026.6.10 (aa69b12)
  • Affected provider: Xiaomi MiMo (mimo-v2.5-pro) via OpenAI-compatible API (openai-completions)
  • MCP server: Hindsight (self-hosted, streamable-http transport at http://127.0.0.1:8888/mcp/hermes/)
  • OS: Linux 6.18.18-trim (x64)

Steps to Reproduce

  1. Configure Hindsight MCP server in openclaw.json:
{
  "mcp": {
    "servers": {
      "hindsight-mcp": {
        "enabled": true,
        "url": "http://127.0.0.1:8888/mcp/hermes/",
        "transport": "streamable-http"
      }
    }
  }
}
  1. Call hindsight-mcp__retain with tags parameter:
{
  "name": "retain",
  "arguments": {
    "content": "test memory",
    "tags": ["test", "debug"]
  }
}
  1. Observe validation error:
Validation failed for tool "hindsight-mcp__retain":
  - tags: must be array
  - tags: must be null
  - tags: must match a schema in anyOf

Received arguments:
{
  "content": "test memory",
  "tags": "[\"test\",\"debug\"]"
}

Expected Behavior

MCP tool calls with array/object parameters (e.g., tags: ["test","debug"]) should succeed. OpenClaw's validation layer should coerce stringified JSON values back to their expected types when the schema expects array or object, so tools work across providers regardless of how LLMs serialize complex parameters.

Actual Behavior

Tool calls fail with validation errors when the LLM serializes array parameters as JSON strings. The validateToolArguments() in src-M7TBQdDX.js uses TypeBox Value.Convert and coerceWithJsonSchema, but neither can parse "[\"test\",\"debug\"]" back to ["test","debug"]. Direct MCP protocol calls with proper JSON arrays work fine — the issue is purely in OpenClaw's argument validation/coercion layer.

Root Cause Analysis

The issue spans two layers:

1. LLM Provider (MiMo model)

The Xiaomi MiMo model's OpenAI-compatible API returns tool_calls[].function.arguments where array-typed parameters are serialized as JSON strings. For example, tags: ["test","debug"] becomes tags: "[\"test\",\"debug\"]" in the parsed arguments object.

2. OpenClaw Validation Layer (src-M7TBQdDX.js)

In validateToolArguments():

function validateToolArguments(tool, toolCall) {
    const args = structuredClone(toolCall.arguments);
    Value.Convert(tool.parameters, args);  // TypeBox — only basic type coercion
    const coerced = coerceWithJsonSchema(args, tool.parameters);  // JSON Schema union coercion
    // Neither can parse "[\"test\",\"debug\"]" back to ["test","debug"]
    if (validator.Check(args)) return args;
    // Throws validation error
}
  • Value.Convert (TypeBox) only handles primitive type coercion (string→number, string→boolean). It cannot deserialize stringified JSON arrays.
  • coerceWithJsonSchema handles anyOf/oneOf union schemas by trying each variant, but doesn't attempt JSON.parse on string values when the target schema expects array/object.

3. MCP Server (not the issue)

Direct MCP protocol calls with proper JSON arrays work perfectly.

Proposed Fix

Add a JSON.parse fallback in validateToolArguments (or coerceWithJsonSchema) that attempts to deserialize stringified values when the schema expects array or object types:

function coerceStringifiedValues(value, schema) {
    if (typeof value === "string") {
        const schemaTypes = getSchemaTypes(schema);
        if (schemaTypes.includes("array") || schemaTypes.includes("object")) {
            try {
                const parsed = JSON.parse(value);
                if (schemaTypes.includes("array") && Array.isArray(parsed)) return parsed;
                if (schemaTypes.includes("object") && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
            } catch { /* not valid JSON, skip */ }
        }
    }
    return value;
}

This is the same approach proposed in PR #70882 (which was closed without merging) and PR #57455 (also closed).

Related Issues/PRs

Impact

This affects any MCP tool with array or object typed parameters when used with LLM providers that serialize complex types as strings. Known affected providers:

Workaround

Avoid using array/object parameters in MCP tool calls. For Hindsight's retain tool, this means omitting tags, metadata, and document_id parameters — functional but degraded.

Activity

  1. clawsweeper commented on Jun 26, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 25, 2026, 11:24 PM ET / 03:24 UTC.

    Summary
    Keep open: current main still lacks schema-aware parsing for MCP array/object parameters that arrive as JSON strings, and the focused prior fix PR was closed unmerged rather than becoming a canonical implementation.

    Reproducibility: yes. source-reproducible but not live-reproduced here: current main never JSON-parses schema-expected object/array strings before validation, so the reported stringified tags shape remains invalid.

    Root-cause cluster
    Relationship: canonical
    Canonical: #96916
    Summary: This issue is the current open canonical item for the stringified MCP object/array argument validation failure; older related reports or PRs are closed and unmerged.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    A focused repair PR is reasonable because the affected validator, MCP boundary, related reports, and validation path are clear, but live provider proof was not run in this read-only review.

    Review details

    Best possible solution:

    Add bounded, schema-aware JSON parsing in shared tool-argument validation for string values only when an object or array schema branch is expected, with regression tests for nullable/union MCP schemas.

    Do we have a high-confidence way to reproduce the issue?

    Yes, source-reproducible but not live-reproduced here: current main never JSON-parses schema-expected object/array strings before validation, so the reported stringified tags shape remains invalid.

    Is this the best way to solve the issue?

    Yes: the narrow maintainable fix belongs in the shared tool-argument validation boundary, not in one MCP server or a single provider-specific adapter.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • I did not run a live MiMo/Ollama/Hindsight reproduction; the current-main failure assessment is source-based.
    • A repair should bound any JSON parsing and keep it schema-gated so model-controlled strings are not parsed unnecessarily.

    Codex review notes: model internal, reasoning high; reviewed against 448b7c75b669.

    Label changes

    Label justifications:

    • P2: This is a concrete MCP/provider interoperability bug with a clear shared validation surface and limited blast radius.
    • impact:other: The issue makes MCP tools with array/object parameters fail for affected providers, which is maintainer-visible but outside the more specific impact labels.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs packages/llm-core/src/validation.test.ts
    • node scripts/run-vitest.mjs src/agents/agent-bundle-mcp-tools.materialize.test.ts

    What I checked:

    Likely related people:

    • Ayaan Zaidi: git show -s lists Ayaan Zaidi as committer for the commit that introduced the current shared validation and bundle MCP materialization files in this checkout. (role: committer for current shared validator implementation; confidence: medium; commits: 31a0f97dd944; files: packages/llm-core/src/validation.ts, packages/llm-core/src/validation.test.ts, src/agents/agent-bundle-mcp-materialize.ts)
    • openclaw-clownfish[bot]: git blame attributes the relevant validator and bundle MCP forwarding lines to the bot-authored repair commit; route through a human reviewer for follow-up. (role: authored current validation and MCP materialization behavior; confidence: medium; commits: 31a0f97dd944; files: packages/llm-core/src/validation.ts, src/agents/agent-bundle-mcp-materialize.ts, src/agents/agent-bundle-mcp-runtime.ts)
    • Sanjays2402: The closed unmerged PR that targeted this exact MCP object/array string coercion failure was authored by Sanjays2402, making it useful context for a replacement fix. (role: prior focused fix attempt author; confidence: low; commits: 8911332bd919; files: src/agents/pi-bundle-mcp-materialize.ts, src/agents/pi-bundle-mcp-tools.materialize.test.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    on Jun 26, 2026
  3. added a commit that references this issue on Jun 26, 2026
    f4231f0
  4. added a commit that references this issue on Jun 29, 2026
    9202dbb
  5. added a commit that references this issue on Jun 29, 2026
    f63cc7b
  6. added 2 commits that reference this issue on Jul 1, 2026
    ffc4575
  7. added 2 commits that reference this issue on Jul 4, 2026
    89ed702
    aed6fcd
  8. locked as resolved and limited conversation to collaborators on Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions