Skip to content

test(community-v3): cover OpenAPI and other runtime-state tools#39

Merged
naji247 merged 1 commit into
mainfrom
test/community-v3-openapi-runtime-state-coverage
Jul 10, 2026
Merged

test(community-v3): cover OpenAPI and other runtime-state tools#39
naji247 merged 1 commit into
mainfrom
test/community-v3-openapi-runtime-state-coverage

Conversation

@naji247

@naji247 naji247 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary

  • Closes the coverage gap that let the context-injection regression fixed in fix(community-v3): inject tool context without deep-copying the tool #38 ship green: the community suite only ever exercised plain @server.tool function tools (which deep-copy cleanly), so no test caught that FastMCP v3 tools holding live runtime state fail to deep-copy.
  • Adds end-to-end tests that drive the real middleware dispatch (tools/list + tools/call) against OpenAPI-generated, proxy, and mounted tools — the three tool types that hold non-deepcopyable runtime state (an httpx.AsyncClient, a client factory, a live sub-server reference respectively).
  • Runs entirely in-process via httpx.MockTransport — no network, no live backend.
  • Test-only change. No production code is modified.

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 real OpenAPITools.
  • create_community_proxy_server() (ProxyTool) and create_community_mounted_server() (FastMCPProviderTool).

tests/community/test_community_v3_openapi.py (end-to-end):

  • context injected into every tool on tools/list, with the custom description and marked required
  • no "Error copying tool" logged
  • server's cached tools are not mutated across repeated lists
  • tools/call strips context, captures it as user_intent, and never leaks it to the downstream HTTP request
  • HTTP-500 tool calls are captured as errors and surface to the client
  • the tools/list event response serializes OpenAPITool subclasses
  • get_more_tools coexists with generated tools and is excluded from injection
  • deepcopy precondition guard

tests/community/test_community_v3_runtime_state_tools.py:

  • parametrized guard over [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-fastmcp job) 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.0b1
  • Regression check: temporarily restoring copy.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 #38
  • uv run pytest tests/community/ tests/test_context_parameters.py -q — 97 passed (was 85), no regressions
  • uv run --with 'fastmcp==3.4.4' pytest tests/community/ tests/test_context_parameters.py -q — 97 passed on the upper matrix bound
  • Confirmed the new modules import cleanly and skip when FastMCP is not installed

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.
@naji247 naji247 merged commit 78e1716 into main Jul 10, 2026
43 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