[BUG] Background subagents don't receive MCP tools, causing XML text fallback

Resolved 💬 3 comments Opened Jan 1, 2026 by sorryhyun Closed Feb 15, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Summary

When subagents run with run_in_background: true, they don't have access to MCP tools. The model falls back to generating XML-formatted function calls as plain text instead of proper tool_use blocks.

Expected Behavior

Background subagents should be able to call MCP tools using proper tool_use content blocks, just like foreground execution.

Actual Behavior

The model outputs text like:

<function_calls>
<invoke name="mcp__server__tool_name">
<parameter name="param">value</parameter>
</invoke>
</function_calls>

Instead of:

{"type": "tool_use", "name": "mcp__server__tool_name", "input": {"param": "value"}}

Root Cause

Multiple internal functions pass mcpTools: [] (empty array) to the agent execution context:

options: {
  querySource: "background_task_*",
  agents: [],
  isNonInteractiveSession: false,
  hasAppendSystemPrompt: false,
  mcpTools: []  // ← Always empty
}

When mcpTools is empty, the model doesn't know the MCP tools exist and falls back to XML text output.

Suggested Fix

Pass mcpTools from the parent context (or the root-level X1 variable) instead of hardcoding empty arrays in background execution contexts.

Environment

  • Claude Code version: 2.0.76
  • Affects: All platforms

What Should Happen?

Background subagents should be able to call MCP tools using proper tool_use content blocks, just like foreground execution.

Error Messages/Logs

Steps to Reproduce

  1. Configure an MCP server with custom tools
  2. Create a subagent that should call an MCP tool
  3. Invoke with run_in_background: true
  4. Observe the agent outputs XML text instead of executing the tool

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.0.76

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

WSL (Windows Subsystem for Linux)

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗