You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Selecting a custom agent disables deferred MCP tool loading from the second model call (all MCP tools loaded into context) #5195
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
Configure an MCP server with many tools in ~/.copilot/mcp-config.json, with "toolSearch": true and "dynamicRetrieval": { "mcp": true } in settings.json.
Create a minimal custom agent (name + description + one line of instructions, no tools: list).
Run copilot --agent "<agent name>".
Send hi, then run /context -> MCP Tools: 0.
Send any second prompt, then run /context -> MCP Tools: 26.9k (all tools of the server listed).
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:
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