Repository navigation
Conversation
fetch_mcp_tools and call_mcp_tool each opened the transport, built a ClientSession, initialized it under the same deadline and mapped failures through _raise_mcp_failure. That now lives in one _run_mcp_session helper, import guard included; each function keeps only its own exchange. The retry-once-with-the-looked-up-end-user logic was written three times (per-account listing, search/execute listing, tool execution). It is now retry_for_end_user, with the same rules: only a 400 naming an account that was sent without an end user, and only if the lookup finds one. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
The retry condition is documented once, on retry_for_end_user, as the toolset callers already rely on; the copy above the tool's call site restated it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
retry_for_end_user already checks is_end_user_refusal before it calls the look-up, and every caller goes through it, so the look-up's own check was a second copy that could drift. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
Main changed the two MCP session bodies this branch folds into _run_mcp_session. The shared helper stays, with main's edits carried over: tools/list pages with list_tools(params=PaginatedRequestParams(...)), the mcp imports drop their ty ignores, and the shared SSL context merged on its own. The types import in fetch_mcp_tools sits inside _list, so it runs after the helper's guarded import and a broken install still raises ToolsetConfigError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
The pagination test only counted calls, so a regression to the old positional cursor argument would still pass. Assert the first call sends params=None and the second carries the next cursor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
This was referenced Nov 11, 2026
Contributor
Author
|
Shipped as part of #274: that branch was built on this one, and its squash merge (7dfbf28) contains every change here. A second review pass on main found no regression (879 tests on mcp 2.3.0 and 1.30.0, validate.sh 6/6, and the end-user retry against the mock behaves exactly as before this change). The guidance follow-up is #275. |
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.
What
fetch_mcp_toolsandcall_mcp_toolshare a new_run_mcp_session(endpoint, headers, timeout, work): it opens the transport, builds and initializes theClientSessionunder theanyio.fail_afterdeadline, runswork(session), and maps anyExceptionthrough_raise_mcp_failure. Each function now holds only its own exchange (paginatedtools/list, or onetools/call).fetch_tools, the search/execute listing,StackOneMcpTool.execute), is nowretry_for_end_user(call, accounts, look_up).Why
Both blocks were copied line for line, so a fix to one (deadline scope, failure mapping, retry rules) had to be made in two or three places. The next change to the MCP client (reusing a session across calls) touches exactly this code, so it goes on top of one copy instead of two.
Behaviour
None intended. Points checked:
initializeand the operation.Exceptionis mapped, soKeyboardInterruptandSystemExitstill propagate._look_up_end_userto check the refusal; the helper checks it first with the same predicate._build_mcp_headersruns again inside the lambda), as before.mcpimport guard is kept in the shared helper.How verified
uv run ruff check .,uv run ruff format --check .,uv run ty check stackone_ai examples: clean.uv run pytest(Python 3.13, MCP mock via pnpm): 871 passed, the same count asmain; the end-user retry tests intests/test_end_user_id.pyand the mocked-session tests intests/test_fetch_tools.pyrun unchanged.Gates (head e53d02b)
retry_for_end_user, so the look-up no longer repeats it. Declined 4: the unguardedmcp.typesimport incall_mcp_toolis unchanged from main, the session was already untyped for ty (the import carries an unresolved-import ignore), the unprefixed helper name matchesis_end_user_refusalandbuild_request_headers, and the one-element account list keeps one helper for both pathsRequested by guillaume@stackone.com in Slack (repo audit thread)
🤖 Generated with Claude Code
Summary by cubic
Shares the MCP session plumbing and the end-user retry logic, previously duplicated across two and three call sites respectively. No behavior change: deadline scope, failure mapping, retry eligibility, and header rebuild on retry all work as before.
Refactor
fetch_mcp_toolsandcall_mcp_toolnow delegate to a shared_run_mcp_sessionhelper; each keeps only its own exchange (tools/listpagination or onetools/call).retry_for_end_user, used by the per-account listing, search/execute listing, and tool execution paths; the refusal check lives only there.maincarried its edits into the shared helper:tools/listpagination, the dropped ty ignores, and the shared SSL context.mcpimport guard stays in the shared helper, so a missing optional dependency is still surfaced as aToolsetConfigError.list_toolsparams on each call, so a regression to the old positional cursor argument fails.Written for commit 2494d18. Summary will update on new commits.