Skip to content

Sub-agent MCP tool calls fail with structuredContent: expected record, received array when server returns JSON arrays #3030

Description

@mihaiLucian

Describe the bug

When a sub-agent launched via the task tool calls an MCP tool that returns a JSON array, the call fails with a Zod validation error. The exact same tool with the exact same parameters works fine when called from the primary/orchestrator agent.

The error is:

MCP server 'my-mcp-server': [{"expected":"record","code":"invalid_type","path":["structuredContent"],"message":"Invalid input: expected record, received array"}]

The root cause is in sdk/index.js where the CallToolResult schema defines structuredContent: z.record(z.string(), z.unknown()).optional(). z.record() only accepts plain objects, so when an MCP server returns a JSON array, the Zod validation rejects it. This validation only runs in the sub-agent code path, not the primary agent path.

Context Response type Result
Primary agent JSON array Works
Primary agent String Works
Primary agent JSON object Works
Sub-agent (via task) String Works
Sub-agent (via task) JSON object Works
Sub-agent (via task) JSON array Fails

Affected version

Reproduced on 1.0.36 and 1.0.39 (latest as of 2026-04-29). Using @github/copilot-sdk 0.3.0.

Steps to reproduce the behavior

  1. Register a stdio MCP server with a tool that returns a JSON array:

    [
      { "id": "abc-123", "status": "Succeeded", "startTime": "2026-04-27T10:00:00Z" },
      { "id": "def-456", "status": "Running", "startTime": "2026-04-28T01:00:00Z" }
    ]
  2. Configure a custom sub-agent with access to that tool:

    name: my-agent
    tools:
      - my-mcp-server/list_items
  3. Create a session with sub-agents enabled and have the orchestrator delegate to my-agent via the task tool

  4. The sub-agent calls my-mcp-server/list_items and gets the error above

A tool on the same server that returns a string (e.g., "No items found") succeeds in the same sub-agent session, confirming the issue is specifically with array responses.

Expected behavior

MCP tool calls returning JSON arrays should work the same way in sub-agents as they do in the primary agent. A few possible fixes:

  1. Accept arrays in structuredContent: z.union([z.record(z.string(), z.unknown()), z.array(z.unknown())])
  2. Normalize array responses before validation by wrapping [...] into { items: [...] }
  3. Apply the same lenient parsing that the primary agent uses to sub-agent MCP responses as well

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agentsarea:mcpMCP server configuration, discovery, connectivity, OAuth, policy, and registry

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions