Skip to content

System message tools duplicates built-in tools when MCP tools present #11064

@shanevcantwell

Description

@shanevcantwell

Bug

generateToolsSystemMessage() in buildToolsSystemMessage.ts duplicates all built-in tools in the system prompt when any MCP/dynamic tool is present.

Root cause

Line 43 iterates tools (all tools) instead of withDynamicMessage (only tools without systemMessageDescription). When the withDynamicMessage.length > 0 branch fires, every tool — including built-in ones already listed via createSystemMessageExampleCall — gets a second listing via toolToSystemToolDefinition.

Built-in tools appear twice:

  1. In the predefined section (via systemMessageDescription.prefix + example call)
  2. In the dynamic section (via toolToSystemToolDefinition)

Impact

  • Wastes context tokens with duplicate definitions
  • Sends contradictory format information (predefined uses example calls, dynamic uses tool_definition blocks)
  • Disproportionately affects local models with smaller context windows
  • Dormant without MCP tools — only triggers when dynamic tools are registered alongside built-in tools

Fix

One-line change: for (const tool of tools)for (const tool of withDynamicMessage)

The withDynamicMessage array is already computed on line 18-20 for exactly this purpose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:mcpRelates to Model Context Protocol (MCP)kind:bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions