Skip to content

fix(mcp): avoid repeated tool schema materialization#1959

Open
mattzcarey wants to merge 1 commit into
mainfrom
fix/1938-mcp-tool-materialization
Open

fix(mcp): avoid repeated tool schema materialization#1959
mattzcarey wants to merge 1 commit into
mainfrom
fix/1938-mcp-tool-materialization

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • cache MCP input/output JSON Schema conversion for unchanged live connection catalogs while continuing to return fresh AI tool records and execute closures
  • add Think.includeMcpTools, defaulting to true, so transport-only integrations such as Code Mode can skip direct MCP AI-tool materialization without disabling connection restore, discovery, waiting, raw listing, or calls
  • add regression coverage for a 313-tool catalog, cache invalidation, failed conversions, and transport-only connector access
  • document the new setting and ship patch changesets for agents and @cloudflare/think

Why

Think currently calls getAITools() before beforeTurn(), so an activeTools filter cannot prevent every MCP input and output schema from being converted to Zod. Large Code Mode-only catalogs therefore pay hundreds of conversions on every turn despite exposing no direct MCP tools to the model.

This change avoids conversion entirely for transport-only Think agents and reuses converted schemas for direct MCP exposure until the catalog or affected schema source changes.

Testing

  • pnpm --filter agents exec vitest --run --project workers src/tests/mcp/client-manager.test.ts
  • pnpm --filter @cloudflare/think exec vitest --run -c src/tests/vitest.config.ts src/tests/mcp-tool-materialization.test.ts
  • full agents package test suite
  • full @cloudflare/think package test suite
  • pnpm exec nx affected -t build test --base=origin/main
  • pnpm run check

Closes #1938


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f1054a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
agents Patch
@cloudflare/think Patch
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1959

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1959

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1959

create-think

npm i https://pkg.pr.new/create-think@1959

hono-agents

npm i https://pkg.pr.new/hono-agents@1959

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1959

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1959

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1959

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1959

commit: 7f1054a

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.

Think repeatedly compiles large MCP tool catalogs into Zod schemas and exceeds Durable Object memory limits

1 participant