Repository navigation
fix: keep tool input from overriding the MCP handler's tool - #613
Open
shreyanshj10 wants to merge 1 commit into
Open
shreyanshj10 wants to merge 1 commit into
shreyanshj10 wants to merge 1 commit into
Conversation
hshadccca
approved these changes
Nov 5, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #608.
What was wrong
assemble_tool_pool()built each MCP handler as a lambda whoseclientandtoolwere ordinary keyword parameters carrying defaults:execute_tool()dispatches withhandler(**block.input), so atoolkey in the model's tool input replaces the default. With the chapter's ownMCP_HOST_POLICY,mcp__deploy__statusisallowandmcp__deploy__triggerisconfirm, so this call:{"name": "mcp__deploy__status", "input": {"service": "web", "tool": "trigger"}}clears
permission_hook()with no prompt and then runscall_tool("trigger", {"service": "web"}). Against the unmodified chapter I got[deploy] Triggered: webwith zero permission prompts.I do not read this as a deliberate simplification. §5 introduces the default arguments only as the late-binding fix for the loop variable, and §6 says the host policy decides what runs. The dispatch path quietly contradicts §6, and since the point of the chapter is that the host owns authorization, a handler the tool input can re-target undercuts the lesson itself rather than shortening it.
The change
A small factory binds the pair in a closure, where call-time keywords cannot reach it:
That still fixes late binding, so §5's point stands. The same input now calls
statuswith a straytoolargument, and the server rejects it at the tool boundary exactly as §7 describes:functools.partialis not an alternative here: keywords passed at call time override the ones stored in a partial, so the redirect still goes through. I checked that before writing the fix.s15_integrated_harness/code.pycarries the same two lines, so it had the same bypass. I fixed both rather than leaving the integrated harness able to do what s14 no longer can, which is how #586 handled the s11/s15 pair.MCP_LESSONSintests/test_agent_teams_runtime.pyalready pairs the two chapters, so the test below covers both. Nothing else changed — no input validation, no schema enforcement, no extra error handling.The three
s14_mcp_pluginREADMEs are updated with the identical code block, plus a sentence saying default arguments solve late binding but stay overridable by caller keywords. The s15 READMEs describe this part in prose and do not embed the snippet, so they needed no change.Tests
tests/test_agent_teams_runtime.pyalready runstest_mcp_permission_uses_host_policyoverMCP_LESSONS(s14 and s15), so I added one sibling test beside it instead of a new file or any scaffolding. It fails before this change and passes after.I ran the tests this change touches:
python -m pytest tests/test_agent_teams_runtime.py -k mcp -q(4 passed, covering both chapters) andpython -m pytest tests/test_chapter_readmes.py -q(3 passed). I also checked the chapter-loading tests intests/test_agent_loop_boundaries.py,tests/test_permission_command_words.pyandtests/test_compaction_tool_pairs.pyagainstmainand this change adds no failures there.AI disclosure
I used an AI coding assistant on this change. I read it, reproduced the bypass and verified the fix against the chapter code myself, and I stand behind it.