Skip to content

Feature Request: Improve MCP Tool Response Handling #2552

Description

@luiskabes-arch

Feature Request: Improve MCP Tool Response Handling

Summary

The run_mcp tool returns raw MCP protocol responses as unparsed strings, and persists large responses to temp files. This forces the AI agent to manually read, strip prefixes, and double-parse JSON — adding unnecessary round-trips and friction for every MCP call.

Current Behavior

  1. Agent calls run_mcp with server name, tool name, and args
  2. For small responses: raw string is returned inline (still unparsed)
  3. For large responses (~20KB+): output is saved to a temp file, agent must Read the file manually
  4. The MCP protocol wraps content in [{type: "text", text: "JSON_STRING"}] — the text field is itself a JSON string, requiring double parsing
  5. Agent must: read file → strip "The MCP server responded with: " prefix → parse outer JSON → parse inner text field as JSON

Expected Behavior

  1. run_mcp should auto-parse the MCP content array ([{type, text}])
  2. Extract the text content and parse it as JSON
  3. Return structured JSON directly to the agent's context
  4. Do not persist responses to temp files unless they truly exceed context limits (25KB is well within limits)

Impact

  • Every MCP call is affected, not just specific servers
  • Adds 2-4 extra tool calls per MCP interaction (Read file, parse, verify)
  • Increases latency and token usage for no functional benefit
  • Makes MCP integration feel sluggish compared to other IDEs/tools

Example: Banani MCP

Current flow (4 steps):

run_mcp → output persisted to /var/folders/.../output.txt (25.6KB)
Read file → get raw string with prefix
RunCommand (python) → parse double-encoded JSON
Read parsed output → finally get structured data

Expected flow (1 step):

run_mcp → returns structured JSON directly
{
  "flow": { "name": "...", "id": "..." },
  "designs": [
    {
      "screenName": "Final - Product",
      "source": "...",
      "screenSize": "desktop"
    }
  ]
}

Comparison

Other tools (e.g., OpenCode, Claude Desktop, Cursor) handle MCP responses as structured data natively. The MCP protocol defines typed content blocks — the client should parse them, not pass raw strings to the agent.

Suggested Implementation

  • Parse [{type: "text", text: "..."}] content arrays automatically
  • If text is valid JSON, deserialize it before returning
  • Only persist to file if the deserialized response exceeds a reasonable threshold (e.g., 100KB+)
  • Remove the "The MCP server responded with: " prefix from inline responses
  • Return a consistent structured object with server_name, tool_name, and result (parsed)

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