Skip to content

Selecting a custom agent disables deferred MCP tool loading from the second model call (all MCP tools loaded into context) #5195

Open

Description

@rg675

Describe the bug

With tool search enabled, MCP tools are deferred and /context shows "MCP Tools 0" for the default agent for the whole session.

When a custom agent is selected (--agent or /agent), deferral only holds for the first model call. From the second call on, every tool of every configured MCP server is loaded into context. In my case that is 26.9k tokens (one server with ~100 tools), added to every request.

Side effect: tool_search_tool then returns "No tools found" because the tools are already loaded (same symptom as #4773, different cause).

It happens with a minimal custom agent that has no tools: list, so it is not specific to the agent content.

Affected version

1.0.98

Steps to reproduce the behavior

  1. Configure an MCP server with many tools in ~/.copilot/mcp-config.json, with "toolSearch": true and "dynamicRetrieval": { "mcp": true } in settings.json.
  2. Create a minimal custom agent (name + description + one line of instructions, no tools: list).
  3. Run copilot --agent "<agent name>".
  4. Send hi, then run /context -> MCP Tools: 0.
  5. Send any second prompt, then run /context -> MCP Tools: 26.9k (all tools of the server listed).
  6. Repeat without --agent -> MCP Tools stays 0 for the whole session.

Same in non-interactive mode: copilot -p "Hi" --agent "<agent name>". In ~/.copilot/session-state/<id>/events.jsonl, the session.usage_record events show:

  • call 1: toolTokenCount=11485, inputTokens=27051
  • call 2: toolTokenCount=40069, inputTokens=66329, cacheReadTokens=0 (prompt cache invalidated)
  • requestBodyBytes unchanged (~170 KB) on both calls
    Without --agent, toolTokenCount stays constant (11207) on every call.

Expected behavior

Custom agents keep deferred MCP tool loading like the default agent: MCP tools are loaded only when found via tool search, and the tool list does not change between calls (so the prompt cache is not invalidated).

Additional context

Windows, Claude Opus 5.5 (also seen with Claude Sonnet 5.5).
Impact: ~27-39k extra tokens on every call of every custom-agent session, plus a prompt cache miss on the second call.
Workaround: --disable-mcp-server <name> for servers the agent does not need.
Related: #4773 ("Found 0 tools" for an already-loaded namespace).

Activity

  1. added theissue type on Oct 19, 2026
  2. added
    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agents
    area:context-memoryContext window, memory, compaction, checkpoints, and instruction loading
    area:mcpMCP server configuration, discovery, connectivity, OAuth, policy, and registry
    and removed on Oct 20, 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

    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agentsarea:context-memoryContext window, memory, compaction, checkpoints, and instruction loadingarea: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