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.


Object storage (S3 / MinIO)

If the files already live in S3-compatible storage, don't copy them through your app: let the store hand out the URL. S3Bridge is a drop-in replacement for FileBridge — same link(session_id, rel_path) call, same adapter wiring.

from mcp_file_bridge import S3Bridge, S3FileStore, S3Settings

store = S3FileStore(
    S3Settings(
        bucket="agent-uploads",
        access_key="...",
        secret_key="...",
        endpoint_url="http://minio:9000",  # omit for AWS
        region="us-east-1",
        key_prefix="threads",              # optional: tenants/42, etc.
    )
)
bridge = S3Bridge(store=store, ttl=900)
bridge.link("session-1", "uploads/data.npz")  # -> presigned GET, valid 15 min

SigV4 query signing is implemented with the standard library, so this stays a zero-dependency install. Two things behave differently from the local bridge:

  • No endpoint of your own. S3 serves the bytes; mount_bridge() is not needed.
  • No free existence check. Pass exists=lambda session_id, rel_path: ... if you want a missing object to fail at link time instead of at the MCP server.

The session id becomes a key prefix, so one bucket can serve every conversation without a per-session bucket or policy change.


Proxy for clients you don't control

Interceptors need a seam in the client's code. Desktop apps and hosted agent platforms have none — for those, point the MCP config at this process instead of at the real server (install with pip install "mcp-file-bridge[proxy]", which pins mcp>=1.9,<2 — the 2.x SDK renamed the streamable-HTTP helper and is not supported yet):

{
  "mcpServers": {
    "firstarrival": {
      "command": "python",
      "args": [
        "-m", "mcp_file_bridge.proxy",
        "--upstream-url", "http://127.0.0.1:19100/mcp",
        "--session-id", "3d49a74b-72e3-4149-821e-642d8e7aaf4e",
        "--root-template", "/app/saves/threads/{session}/user-data",
        "--base-url", "http://127.0.0.1:15050",
        "--secret", "the-same-secret-your-platform-signs-with"
      ]
    }
  }
}

The proxy speaks stdio to the client, opens the real server (stdio via --upstream-command, or streamable HTTP via --upstream-url), forwards tools/list, and rewrites file arguments on tools/call. Drop --base-url when both processes share a filesystem: the upstream then receives the local path.

Two properties worth knowing:

  • The model never sees the secret, so it cannot mint a link for another session. Pass the session id in the config, not in a tool argument.
  • One proxy process per session. That is what makes "the scope is the conversation" true without asking the client to send a session id.

Anything the proxy does not have to touch — non-string arguments, strings that are not files, nested objects — is forwarded untouched.

Two notes from real deployments:

  • Proxies: upstream HTTP bypasses HTTP(S)_PROXY and the OS proxy by default, because Windows registry proxies also apply to localhost and some produce confusing 502s. Pass --trust-env-proxy if the real server is only reachable through a corporate proxy.
  • NO_PROXY matters: if your client (the platform) fetches the signed link, make sure its own proxy settings exclude the platform host, or the download goes to the proxy instead of the platform.

DeepSeek Harness (DSH) and other per-session hosts

Hosts that mount one stdio server per conversation hand the proxy two useful facts for free, and withhold a third:

  • given: the process runs with cwd = the session's workspace (mountAcpMcpServers(agentCtx, servers, sessionCwd) sets cwd: sessionCwd);
  • given: a fresh process per session, so killing the conversation kills the bridge;
  • not given: the session id — nothing puts it in env or in the arguments.

That is what --session-id-from-cwd is for: the working directory name becomes the session, and --root-template . treats that workspace as the file root.

{
  "mcpServers": {
    "firstarrival": {
      "command": "python",
      "args": [
        "-m", "mcp_file_bridge.proxy",
        "--upstream-url", "http://127.0.0.1:19100/mcp",
        "--session-id-from-cwd",
        "--root-template", ".",
        "--base-url", "http://127.0.0.1:15050",
        "--secret", "from-your-platform-config",
        "--virtual-prefix", "/home/gem/user-data"
      ]
    }
  }
}

Two adjustments cover the other storage layouts:

Where the uploads are --root-template
inside the session workspace . (default shape above)
a sibling directory of the workspace ../user-data
a global tree keyed by session (/saves/threads/<id>/user-data) /saves/threads/{session}/user-data

If your host puts uploads somewhere unrelated to cwd, pass --session-id instead and let the template place {session}.

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.3.2

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.3.2
File Size Uploaded Provenance Actions
mcp_file_bridge-0.3.2.tar.gz 31.5 kB Without provenance Details for mcp_file_bridge-0.3.2.tar.gz

Built distribution (wheel)

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

Total release size: 53.3 kB

Release files / mcp_file_bridge-0.3.2.tar.gz

Download URL mcp_file_bridge-0.3.2.tar.gz
Size 31.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9ed57aa21d82042602f7c552aca78b1cac1aefa27c44350e00d6457ff93404b1
BLAKE2b-256 checksum
How to use checksums
e832e39987bc0a69349d1e3ef76dfe87c59ca1e2351f290134702c863c0c6248
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.3.2-py3-none-any.whl

Download URL mcp_file_bridge-0.3.2-py3-none-any.whl
Size 21.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6c1ca1449bedf2db1fd41f830a03ed385fce11c979e3d7c2f76c0902e54f299
BLAKE2b-256 checksum
How to use checksums
d5a56b15cf07a0296fe6502f9ced2da14c451bda5410438223e8e52d9539d583
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.3.2

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