Skip to content

Conversation

@dannykopping
Copy link
Collaborator

@dannykopping dannykopping commented Dec 23, 2025

Closes #69

When MCP tools are injected into a request that already has tools with
cache control breakpoints, we need to move the breakpoint to the final
tool in the list. This ensures prompt caching continues to work
correctly as documented by Anthropic.

The implementation:

  • Captures the first cache control breakpoint found on existing tools
  • Clears it from its original location
  • Sets it on the final tool after injection

When MCP tools are injected into a request that already has tools with
cache control breakpoints, we need to move the breakpoint to the final
tool in the list. This ensures prompt caching continues to work
correctly as documented by Anthropic.

The implementation:
- Captures the first cache control breakpoint found on existing tools
- Clears it from its original location
- Sets it on the final tool after injection

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@dannykopping dannykopping marked this pull request as ready for review December 23, 2025 15:48
@dannykopping dannykopping requested a review from pawbana December 23, 2025 15:48
@dannykopping dannykopping self-assigned this Dec 23, 2025
@pawbana
Copy link
Contributor

pawbana commented Dec 23, 2025

Instead of moving breakpoint could we change tool ordering moving injected tools to beginning of the list?

Copy link
Collaborator Author

I mean... probably? It's the same outcome.

Copy link
Collaborator Author

Hhmm ok maybe that's the more efficient way to do this, thanks.
I'll implement that tomorrow 👍

@pawbana
Copy link
Contributor

pawbana commented Dec 23, 2025

Not exactly. If I understand caching/breakpoints correctly moving breakpoint could result in it not being usable.

Example:
Call 1: tools[A, B(breakpoint), C, Injected_1, Injected_2]
Call 2: tools[A, B, Injected_1, Injected_2] -> could be cached if breakpoint is not moved

If injected tools are moved to the front this example will work.

Downside is that changes to injected tools will break all breakpoints but I would imagine injected tools change less frequently then tools in requests.

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.

2 participants