mcp-file-bridge
Give an external MCP server a signed, expiring link to a user's file — without base64 and without a shared volume.
/user-uploads/report.pdf ──► http://platform/mcp-files/report.pdf?session=…&expires=…&sig=…
▲
the MCP server just does urllib.request.urlopen(...)
Status: v0.1, early. Core + FastAPI endpoint + argument rewriter are usable; the LangChain adapter is next.
The gap this fills
MCP has no file-upload primitive for tool arguments. Tool results can carry resource links and embedded resources, but the client → server direction has nothing. The official File Uploads working group puts it plainly: servers "resort to prose instructions asking for base64 strings or local paths".
So everybody improvises. The five patterns you will actually meet:
| Pattern | Works when | Breaks when |
|---|---|---|
Pass a local path / use roots |
client and server share a filesystem | the server is remote |
| Base64 inside the tool argument | files are tiny | 10 MB → 13 MB of JSON, straight through the context window |
| Signed URL (this library) | both sides can speak HTTP | network is one-way and the server cannot reach you |
Vendor upload channel (attach_file in ChatGPT, File Uploads in Claude) |
you are that vendor | you are not |
Proxy that base64-encodes paths (mcp-file-proxy) |
you cannot change the server | large files |
mcp-file-bridge implements the third one as a library, and keeps the first one for
stdio servers automatically.
Install
pip install mcp-file-bridge # core, zero dependencies
pip install "mcp-file-bridge[fastapi]" # + the download endpoint
Three lines
from fastapi import FastAPI
from mcp_file_bridge import FileBridge, HmacSigner
from mcp_file_bridge.endpoints.fastapi import mount_bridge
app = FastAPI()
bridge = FileBridge(
root_for=lambda session_id: Path("/data/sessions") / session_id, # your storage, your rules
signer=HmacSigner(os.environ["FILE_BRIDGE_SECRET"]),
base_url="http://platform.internal:8000", # what the *MCP server* can reach
ttl=1800,
)
mount_bridge(app, bridge)
url = bridge.link(session_id, "uploads/report.pdf") # hand this to the tool
Rewriting tool arguments
The framework-agnostic core is one pure function — no LangChain, no MCP SDK:
from mcp_file_bridge.interceptors.rewrite import rewrite_local_paths
args, changed = rewrite_local_paths(
tool_args,
session_id=run.thread_id, # from the runtime, never from the model
bridge=bridge,
is_local_path=lambda v: v.startswith("/files/"),
session_prefix="/files/",
)
if changed:
call = call.override(args=args)
LangChain / langchain-mcp-adapters
The adapter ships with the package and imports nothing from LangChain — it only
relies on the interceptor contract (name / args / override() + a handler).
from langchain_mcp_adapters.client import MultiServerMCPClient
from mcp_file_bridge.adapters.langchain import langchain_bridge
client = MultiServerMCPClient(
servers,
tool_interceptors=[
langchain_bridge(
bridge,
session_id=lambda: runtime.thread_id, # resolved per call
is_local_path=lambda v: v.startswith("/files/"),
session_prefix="/files/",
)
],
)
Writing your own adapter
An adapter is ~20 lines: hand it the tool name, the arguments and the session id, and give back rewritten arguments. If your framework exposes any hook around tool calls — a middleware, a wrapper, a decorator — that is enough:
args, changed = rewrite_local_paths(args, session_id=sid, bridge=bridge, is_local_path=...)
if changed:
args = args # call the tool with these instead
If it exposes no hook at all (a closed client with only a url field), put a
proxy in front of the MCP server instead — that is the fallback, not the main path.
Node / TypeScript
ts/ is a dependency-free port with the same wire format — a link minted by one
language verifies in the other (ts/tests/signer.test.ts pins a Python-produced
signature vector).
import { FileBridge, HmacSigner, rewriteLocalPaths } from "mcp-file-bridge";
const bridge = new FileBridge({
rootFor: (sessionId) => `/data/sessions/${sessionId}`,
signer: new HmacSigner(process.env.BRIDGE_SECRET!),
baseUrl: "http://platform:8000",
});
const { args } = rewriteLocalPaths(toolArgs, {
sessionId,
bridge,
isLocalPath: (v) => v.startsWith("/files/"),
sessionPrefix: "/files/",
});
cd ts && npm install && npm test && npm run build
Tests
uv sync --extra dev
uv run python -m pytest -q # 14 tests
Thirteen are unit tests. One (tests/integration) spawns a real stdio MCP server
through the real MultiServerMCPClient and asserts that what arrives on the wire
is a URL, not the local path — that is the test which keeps the "three lines"
claim honest.
Note for Windows: pass --basetemp=.pytest_tmp if your sandbox blocks pytest from
deleting its temp directories.
Design notes
- Scope comes from the runtime, not the model. The session id is injected by the agent runner. A model cannot widen its own access by inventing an id.
- Local servers get a path, remote servers get a URL. A stdio MCP already shares your filesystem; a URL there is pure overhead. Decide per server, not globally.
- Fail loudly. A path that does not resolve is left untouched (or raises), never silently replaced with a default file. Silent fallback is how "it worked" pipelines end up training on the wrong data.
- Storage agnostic. The library only asks for
root_for(session_id) -> Path. S3, a mounted volume, a database blob store — all yours to implement.
Security model
A link is a bearer credential for one file, for a few minutes:
- HMAC-SHA256 over
session:path:expires, compared in constant time; - URLs expire (default 30 min) and are refused after that;
resolve()refuses paths that escape the session root;- the endpoint is intentionally anonymous — the signature is the authentication.
Put it behind HTTPS in production, keep the TTL short, and do not log full URLs.
Demo
pip install -e ".[fastapi]"
python demo/demo.py
It starts the bridge, mints a link for a file in a temp session, then fetches it the way an MCP server would, and prints status + byte count.
Roadmap
- LangChain
MultiServerMCPClientinterceptor - Official MCP Python SDK wrapper
- S3 / MinIO presigned backend
- TypeScript port
-
automode: path for stdio, URL for streamable HTTP
Relationship to SEP-2356
The working group's draft adds a declarative "this argument is a file" descriptor. When it lands, this library does not become obsolete: the descriptor replaces the detection step, and the signed-link transport underneath stays the same. That is deliberate — the mechanism lives at the transport layer, not in your tool schemas.
License
Apache-2.0.
Metadata
Release files for mcp-file-bridge 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_file_bridge-0.1.0.tar.gz | 262.3 kB | Without provenance | Details for mcp_file_bridge-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_file_bridge-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mcp_file_bridge-0.1.0-py3-none-any.whl |
Total release size: 276.3 kB
Release files / mcp_file_bridge-0.1.0.tar.gz
| Download URL | mcp_file_bridge-0.1.0.tar.gz |
|---|---|
| Size | 262.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90fd7eee7c0a835c3ab1145f59a86baafefdde277ab0a11b9251eba33912f534
|
|
BLAKE2b-256 checksum How to use checksums |
799662b13306986d87c604465a79ebab5d27547497dc86081902f331a015361e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / mcp_file_bridge-0.1.0-py3-none-any.whl
| Download URL | mcp_file_bridge-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cfd094c2eca629a8f4509c3f2e50cf2f2e9374e4285f6e2655ca922ac2187c07
|
|
BLAKE2b-256 checksum How to use checksums |
e08c429a41b3ec8941508823e4a2a6a1d88fa5a65e56c705eec2f5a07c35c383
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for mcp-file-bridge 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.