client: fix set_roots updates live session at runtime#3714
client: fix set_roots updates live session at runtime#3714dgenio wants to merge 4 commits intoPrefectHQ:mainfrom
Conversation
Fixes PrefectHQ#326. Calling set_roots now updates the live session's roots callback if connected, not just pending session kwargs. Adds regression test to verify runtime update.
Test Failure AnalysisSummary: The static analysis ( Root Cause: The PR modifies Suggested Solution: Run uv run ruff format src/fastmcp/client/client.py tests/client/test_roots.pyOr run the full prek suite: uv run prek run --all-filesThe most likely formatting issues are:
Detailed AnalysisRelevant log excerpt: The Looking at the diff, likely issues:
assert result2.data == ["file://b/", "file://c/"]
@pytest.mark.parametrize("roots", [["x"], ["x", "y"]]) # ← needs blank line before this
if hasattr(self, "_session_state") and getattr(self._session_state, "session", None) is not None:Related Files
🤖 Triage analysis by marvin |
- Remove redundant getattr/hasattr guards in set_roots; access session directly and let AttributeError surface if MCP SDK changes - Add test_set_roots_before_connect regression test - File PrefectHQ#3715 for set_sampling_callback/set_elicitation_callback parity - Add TODO(PrefectHQ#3715) comments to sibling methods 🤖 Generated with GitHub Copilot
|
Thanks for investigating this. The bug is real, but I'm not comfortable reaching into Going to close this for now. If the SDK adds a public way to update callbacks on a live session, this becomes straightforward to implement on the FastMCP side. |
Description
Fixes #326.
Calling
Client.set_roots(...)during an active session previously only updated pending session kwargs, so runtime roots changes were not reflected until reconnect. This PR updates the live session callback when connected and adds a regression test that verifies runtime root updates are immediately visible.Closes #326
Contribution type
Checklist
uv run prek run --all-filesand all checks passTesting
uv run pytest tests/client/test_roots.py -q->5 passeduv run prek run --all-fileswas run previously; local environment was missingloq, so full pass should be confirmed in CI