Skip to content

fix: inject deferred MCP tools into system prompt and lift selectSearch cap - #343

Open
OliverZou wants to merge 1 commit into
usewhale:mainfrom
OliverZou:fix/mcp-tools-lost
Open

fix: inject deferred MCP tools into system prompt and lift selectSearch cap#343
OliverZou wants to merge 1 commit into
usewhale:mainfrom
OliverZou:fix/mcp-tools-lost

Conversation

@OliverZou

Copy link
Copy Markdown
Contributor

Summary

Two issues left the agent blind to available MCP tools:

  1. The system prompt had no visibility into which MCP tools exist. The <available-deferred-tools> block was only surfaced inside tool_search responses, so the agent could not discover MCP tools without first knowing to call tool_search — a discoverability deadlock.

  2. tool_search capped exact-name (select:) queries at maxSearchResults=5, silently dropping the rest even when the user explicitly named them.

Fixes:

  • Inject <available-deferred-tools> into every turn via a dynamic system block so the agent always knows what MCP tools are available.
  • Cap the block at 4000 characters (newline-boundary truncation) with an omission notice so many tools don't blow up the prompt.
  • Remove the maxSearchResults cap from selectSearch so select: queries return every requested tool, not just the first five.
  • Show all tool names (not just the first five) in tool_search no-match hints, aligning with the new system-prompt visibility.
  • Add tests for the new render path, selectSearch cap removal, truncation behavior, and updated hint format.

Validation

  • Local test-windows — 7/7 packages pass
  • Focused tests — all relevant suites pass
  • Linux CI — deferred to GitHub Actions

User-visible impact

  • System prompt: each turn now includes an <available-deferred-tools> block listing all connected MCP tools.
  • tool_search no-match hints: now show all tool names with a total count, no more silent truncation to five.
  • tool_search select: queries: no longer capped at 5 results.

Breaking changes

None.

Notes

  • The 4000-character cap prevents system-prompt blowup when many MCP tools are registered.
  • Test coverage added in deferred_test.go, mcp_runtime_test.go, and catalog_mcp_test.go.

…ch cap

Two issues left the agent blind to available MCP tools:

1. The system prompt had no visibility into which MCP tools exist. The
   <available-deferred-tools> block was only surfaced inside tool_search
   responses, so the agent could not discover MCP tools without first
   knowing to call tool_search — a discoverability deadlock.

2. tool_search capped exact-name (select:) queries at maxSearchResults=5,
   silently dropping the rest even when the user explicitly named them.

Fixes:
- Inject <available-deferred-tools> into every turn via a dynamic system
  block so the agent always knows what MCP tools are available.
- Cap the block at 4000 characters (newline-boundary truncation) with an
  omission notice so many tools don't blow up the prompt.
- Remove the maxSearchResults cap from selectSearch so select: queries
  return every requested tool, not just the first five.
- Show all tool names (not just the first five) in tool_search no-match
  hints, aligning with the new system-prompt visibility.
- Add tests for the new render path, selectSearch cap removal, truncation
  behavior, and updated hint format.
@OliverZou
OliverZou force-pushed the fix/mcp-tools-lost branch from 70956fc to 36054dc Compare July 18, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant