Data-backed File URIs misinterpret reserved characters in names
Author: RaycarlLeiCreated Sep 16, 2026Updated Sep 16, 2026
Labelsbug
File(data=..., name=...) does not preserve filenames containing URI-reserved characters. A name such as report#draft.pdf produces file:///report#draft.pdf, whose path is /report and whose fragment is draft.pdf. Literal percent escapes are also reinterpreted: report%20draft.pdf identifies report draft.pdf instead.
from urllib.parse import unquote, urlsplit
from fastmcp.utilities.types import File
for name in ["report#draft.pdf", "report?draft.pdf", "report%20draft.pdf"]:
uri = File(data=b"report data", format="pdf", name=name).to_resource_content().resource.uri
print(name, "->", uri, "->", unquote(urlsplit(uri).path))The decoded path should retain the supplied filename. For example, the first URI should be file:///report%23draft.pdf. The same incorrect URI is returned by Client.call_tool() when a tool returns this File.
Reproduced on current main 490049f, FastMCP 4.0.4, Python 3.12.10, Windows. Prepared with Codex.
Source: PrefectHQ/fastmcp