Skip to content

fix: adapt retrieve_tools instructions for code execution routing mode#341

Merged
Dumbris merged 3 commits intomainfrom
fix/retrieve-tools-mode-instructions
Mar 12, 2026
Merged

fix: adapt retrieve_tools instructions for code execution routing mode#341
Dumbris merged 3 commits intomainfrom
fix/retrieve-tools-mode-instructions

Conversation

@Dumbris
Copy link
Contributor

@Dumbris Dumbris commented Mar 12, 2026

Summary

  • Fix 1: The handleRetrieveTools() handler always returned call_tool_read/write/destructive instructions in usage_instructions, even when called from code execution mode (/mcp/code). In that mode, LLMs should be told to use code_execution with call_tool(serverName, toolName, args) in JavaScript instead. Added handleRetrieveToolsForMode() (closure factory) and handleRetrieveToolsWithMode() (mode-aware implementation) to switch instructions based on routing mode.
  • Fix 2 (verified): Read-only agent token enforcement in code_execution is already implemented. When AuthInfo.Permissions is ["read"], calling write/destructive tools inside JavaScript returns PERMISSION_DENIED. Tests exist and pass (TestExecuteAuthContext_PermissionDenied). The AuthContext is properly passed from HTTP context to JS runtime in mcp_code_execution.go.

Changed files

  • internal/server/mcp.go — Added handleRetrieveToolsForMode(), handleRetrieveToolsWithMode(), and mode-aware usage_instructions switch
  • internal/server/mcp_routing.go — Updated buildCodeExecModeTools() and buildCallToolModeTools() to use mode-specific handlers
  • internal/server/mcp_routing_test.go — Added 4 tests for mode-specific instructions

Test plan

  • TestRetrieveToolsInstructions_CodeExecutionMode — code_execution mode mentions code_execution/call_tool(), does NOT recommend call_tool_read/write/destructive
  • TestRetrieveToolsInstructions_RetrieveToolsMode — retrieve_tools mode mentions call_tool_read/write/destructive and intent tracking
  • TestRetrieveToolsInstructions_DefaultMode — empty mode falls back to retrieve_tools instructions
  • TestHandleRetrieveToolsForMode_ClosureReturnsDifferentInstructions — closures for different modes produce different instructions
  • TestExecuteAuthContext_PermissionDenied — existing test verifies read-only token blocks destructive calls in JS runtime
  • Race detector passes on new tests
  • Personal and server editions build successfully

🤖 Generated with Claude Code

The handleRetrieveTools handler was always returning call_tool_read/write/destructive
instructions regardless of routing mode. When called from code_execution mode (/mcp/code),
LLMs should be told to use `code_execution` with `call_tool()` in JavaScript instead.

- Add handleRetrieveToolsForMode() that returns a closure with the routing mode baked in
- Add handleRetrieveToolsWithMode() that switches usage_instructions based on routing mode
- Keep handleRetrieveTools() as backward-compatible wrapper for existing callers
- Update buildCodeExecModeTools() to use RoutingModeCodeExecution
- Update buildCallToolModeTools() to use RoutingModeRetrieveTools
- Verify read-only agent token enforcement in code_execution (already implemented)
- Add 4 tests covering mode-specific instructions and closure behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 12, 2026

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1b8e235
Status: ✅  Deploy successful!
Preview URL: https://ebc1db30.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-retrieve-tools-mode-inst.mcpproxy-docs.pages.dev

View logs

claude added 2 commits March 12, 2026 21:34
filepath.ToSlash ensures tmpBase paths don't break JSON on Windows
(e.g., C:\Users\... → C:/Users/...).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Skip MkdirAll and validation when DataDir contains unresolved ${...}
references — Windows rejects $ and {} in directory names. The
expandDataDir warning already alerts the user.

Also fix TestLoadConfig_DataDirExpandFailure to use forward slashes
in JSON to avoid invalid escape sequences on Windows paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/retrieve-tools-mode-instructions

Available Artifacts

  • archive-darwin-amd64 (25 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (14 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (25 MB)
  • archive-windows-arm64 (22 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (28 MB)
  • installer-dmg-darwin-arm64 (25 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 23020927989 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris Dumbris merged commit 7256894 into main Mar 12, 2026
23 checks passed
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