test(community-v3): cover OpenAPI and other runtime-state tools#39
Merged
Merged
Conversation
The community test suite previously exercised only plain function tools, which deep-copy cleanly. That gap let the context-injection regression fixed in #38 ship green: FastMCP v3 tools that hold live runtime state (an httpx client on OpenAPI-generated tools, a client factory on proxy tools, a sub-server reference on mounted tools) failed to deep-copy and silently lost context injection. Add end-to-end coverage that drives the real middleware dispatch against those tool types, entirely in-process via httpx.MockTransport (no network): - tests/test_utils/community_openapi_server.py: factories for OpenAPI, proxy, and mounted FastMCP v3 servers, plus a multi-endpoint OpenAPI spec. - tests/community/test_community_v3_openapi.py: tools/list injects context on every tool, no copy failure is logged, cached tools are not mutated, tools/call strips context and captures it as intent without leaking it downstream, HTTP errors are captured, the tools/list event serializes OpenAPI tools, and get_more_tools coexists with generated tools. - tests/community/test_community_v3_runtime_state_tools.py: parametrized guard over openapi/proxy/mounted asserting context injection with no copy failures. All modules are FastMCP v3-only and skip cleanly when FastMCP is absent or on the v2 compatibility matrix. Verified on FastMCP 3.0.0b1 and 3.4.4.
kashishhora
approved these changes
Jul 10, 2026
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.
Summary
@server.toolfunction tools (which deep-copy cleanly), so no test caught that FastMCP v3 tools holding live runtime state fail to deep-copy.tools/list+tools/call) against OpenAPI-generated, proxy, and mounted tools — the three tool types that hold non-deepcopyable runtime state (anhttpx.AsyncClient, a client factory, a live sub-server reference respectively).httpx.MockTransport— no network, no live backend.What's covered
tests/test_utils/community_openapi_server.py(new factories):create_community_openapi_server(record_requests=…)— multi-endpoint OpenAPI spec over a mock transport; tools are realOpenAPITools.create_community_proxy_server()(ProxyTool) andcreate_community_mounted_server()(FastMCPProviderTool).tests/community/test_community_v3_openapi.py(end-to-end):tools/list, with the custom description and marked required"Error copying tool"loggedtools/callstripscontext, captures it asuser_intent, and never leaks it to the downstream HTTP requesttools/listevent response serializesOpenAPIToolsubclassesget_more_toolscoexists with generated tools and is excluded from injectiontests/community/test_community_v3_runtime_state_tools.py:[openapi, proxy, mounted]asserting context injection with zero copy failures.All modules are FastMCP v3-only and skip cleanly when FastMCP is absent (the
test-without-fastmcpjob) and on the v2 compatibility matrix.Test plan
uv run pytest tests/community/test_community_v3_openapi.py tests/community/test_community_v3_runtime_state_tools.py -v— 12 passed on FastMCP 3.0.0b1copy.deepcopy(tool)in the middleware fails 7 of the new tests (including the OpenAPI and mounted injection guards), confirming they catch the exact regression from fix(community-v3): inject tool context without deep-copying the tool #38uv run pytest tests/community/ tests/test_context_parameters.py -q— 97 passed (was 85), no regressionsuv run --with 'fastmcp==3.4.4' pytest tests/community/ tests/test_context_parameters.py -q— 97 passed on the upper matrix bound