Skip to main content

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 MultiServerMCPClient interceptor
  • Official MCP Python SDK wrapper
  • S3 / MinIO presigned backend
  • TypeScript port
  • auto mode: 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-file-bridge 0.1.1
File Size Uploaded Provenance Actions
mcp_file_bridge-0.1.1.tar.gz 193.5 kB Without provenance Details for mcp_file_bridge-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-file-bridge 0.1.1
File Interpreter ABI Platform Actions
mcp_file_bridge-0.1.1-py3-none-any.whl Python 3 none any Details for mcp_file_bridge-0.1.1-py3-none-any.whl

Total release size: 207.5 kB

Release files / mcp_file_bridge-0.1.1.tar.gz

Download URL mcp_file_bridge-0.1.1.tar.gz
Size 193.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3e614b8be3a4b0d3a0e321bcd93887e597423c7cfa2e3e909f4728c38e30c1eb
BLAKE2b-256 checksum
How to use checksums
c272dd6fb4b66ef1e0341155be2dd93e3d396d081bd0ff2c22fb1670a1933b13
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.1-py3-none-any.whl

Download URL mcp_file_bridge-0.1.1-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02e8355eb7f0af7860ba4d2c27a3938e655a8481c38d10d17549e620bd673c0d
BLAKE2b-256 checksum
How to use checksums
ea63f971cd3eea3d83071d7e52b41db1de3d4aa9f28efa260601c172cba5900e
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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page