mcp-file-bridge 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. mcp_file_bridge-0.1.0/.github/workflows/ci.yml +60 -0
  2. mcp_file_bridge-0.1.0/.gitignore +24 -0
  3. mcp_file_bridge-0.1.0/.verify/.gitignore +1 -0
  4. mcp_file_bridge-0.1.0/.verify/.lock +0 -0
  5. mcp_file_bridge-0.1.0/.verify/CACHEDIR.TAG +1 -0
  6. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge/__init__.py +7 -0
  7. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge/adapters/__init__.py +5 -0
  8. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge/adapters/langchain.py +72 -0
  9. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge/bridge.py +68 -0
  10. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge/endpoints/fastapi.py +33 -0
  11. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge/interceptors/rewrite.py +40 -0
  12. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge/signer.py +43 -0
  13. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/INSTALLER +1 -0
  14. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/METADATA +194 -0
  15. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/RECORD +15 -0
  16. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/REQUESTED +0 -0
  17. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/WHEEL +4 -0
  18. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/direct_url.json +1 -0
  19. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/licenses/LICENSE +202 -0
  20. mcp_file_bridge-0.1.0/.verify/Lib/site-packages/mcp_file_bridge-0.1.0.dist-info/uv_cache.json +1 -0
  21. mcp_file_bridge-0.1.0/.verify/Scripts/activate +130 -0
  22. mcp_file_bridge-0.1.0/.verify/Scripts/activate.bat +71 -0
  23. mcp_file_bridge-0.1.0/.verify/Scripts/activate.csh +76 -0
  24. mcp_file_bridge-0.1.0/.verify/Scripts/activate.fish +127 -0
  25. mcp_file_bridge-0.1.0/.verify/Scripts/activate.nu +104 -0
  26. mcp_file_bridge-0.1.0/.verify/Scripts/activate.ps1 +82 -0
  27. mcp_file_bridge-0.1.0/.verify/Scripts/activate.xsh +102 -0
  28. mcp_file_bridge-0.1.0/.verify/Scripts/activate_this.py +59 -0
  29. mcp_file_bridge-0.1.0/.verify/Scripts/deactivate.bat +39 -0
  30. mcp_file_bridge-0.1.0/.verify/Scripts/pydoc.bat +22 -0
  31. mcp_file_bridge-0.1.0/.verify/Scripts/python.exe +0 -0
  32. mcp_file_bridge-0.1.0/.verify/Scripts/pythonw.exe +0 -0
  33. mcp_file_bridge-0.1.0/.verify/pyvenv.cfg +5 -0
  34. mcp_file_bridge-0.1.0/LICENSE +202 -0
  35. mcp_file_bridge-0.1.0/PKG-INFO +237 -0
  36. mcp_file_bridge-0.1.0/README.md +216 -0
  37. mcp_file_bridge-0.1.0/demo/demo.py +81 -0
  38. mcp_file_bridge-0.1.0/pyproject.toml +46 -0
  39. mcp_file_bridge-0.1.0/src/mcp_file_bridge/__init__.py +7 -0
  40. mcp_file_bridge-0.1.0/src/mcp_file_bridge/adapters/__init__.py +5 -0
  41. mcp_file_bridge-0.1.0/src/mcp_file_bridge/adapters/langchain.py +72 -0
  42. mcp_file_bridge-0.1.0/src/mcp_file_bridge/bridge.py +68 -0
  43. mcp_file_bridge-0.1.0/src/mcp_file_bridge/endpoints/fastapi.py +33 -0
  44. mcp_file_bridge-0.1.0/src/mcp_file_bridge/interceptors/rewrite.py +44 -0
  45. mcp_file_bridge-0.1.0/src/mcp_file_bridge/signer.py +43 -0
  46. mcp_file_bridge-0.1.0/tests/integration/fake_server.py +23 -0
  47. mcp_file_bridge-0.1.0/tests/integration/test_langchain_real.py +74 -0
  48. mcp_file_bridge-0.1.0/tests/test_bridge.py +73 -0
  49. mcp_file_bridge-0.1.0/tests/test_endpoint.py +68 -0
  50. mcp_file_bridge-0.1.0/tests/test_langchain_adapter.py +93 -0
  51. mcp_file_bridge-0.1.0/ts/package-lock.json +570 -0
  52. mcp_file_bridge-0.1.0/ts/package.json +23 -0
  53. mcp_file_bridge-0.1.0/ts/src/bridge.ts +72 -0
  54. mcp_file_bridge-0.1.0/ts/src/index.ts +3 -0
  55. mcp_file_bridge-0.1.0/ts/src/rewrite.ts +46 -0
  56. mcp_file_bridge-0.1.0/ts/src/signer.ts +47 -0
  57. mcp_file_bridge-0.1.0/ts/tests/bridge.test.ts +72 -0
  58. mcp_file_bridge-0.1.0/ts/tests/signer.test.ts +33 -0
  59. mcp_file_bridge-0.1.0/ts/tsconfig.json +16 -0
  60. mcp_file_bridge-0.1.0/uv.lock +2750 -0
@@ -0,0 +1,60 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, windows-latest]
15
+ python: ["3.10", "3.12", "3.13"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: astral-sh/setup-uv@v5
20
+ with:
21
+ python-version: ${{ matrix.python }}
22
+
23
+ # The package itself has no dependencies; dev extras pull in pytest and the
24
+ # real LangChain/MCP SDK used by the integration test.
25
+ - name: Install
26
+ run: uv sync --extra dev
27
+
28
+ - name: Lint
29
+ run: uv run ruff check .
30
+
31
+ - name: Test
32
+ run: uv run python -m pytest -q
33
+
34
+ typescript:
35
+ runs-on: ${{ matrix.os }}
36
+ strategy:
37
+ fail-fast: false
38
+ matrix:
39
+ os: [ubuntu-latest, windows-latest]
40
+ node: ["18", "20", "22"]
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+
44
+ - uses: actions/setup-node@v4
45
+ with:
46
+ node-version: ${{ matrix.node }}
47
+ cache: npm
48
+ cache-dependency-path: ts/package-lock.json
49
+
50
+ - name: Install
51
+ working-directory: ts
52
+ run: npm ci
53
+
54
+ - name: Test
55
+ working-directory: ts
56
+ run: npm test
57
+
58
+ - name: Typecheck
59
+ working-directory: ts
60
+ run: npm run build
@@ -0,0 +1,24 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .idea/
11
+ .vscode/
12
+ *.log
13
+ .DS_Store
14
+
15
+ # pytest scratch dir
16
+ .pytest_tmp/
17
+
18
+ dist/
19
+ .pytest_tmp*/
20
+ _*.txt
21
+
22
+ ts/node_modules/
23
+ ts/dist/
24
+ node_modules/
@@ -0,0 +1 @@
1
+ *
File without changes
@@ -0,0 +1 @@
1
+ Signature: 8a477f597d28d172789f06886806bc55
@@ -0,0 +1,7 @@
1
+ """File transfer for MCP servers that cannot see your filesystem."""
2
+
3
+ from .bridge import FileAccessError, FileBridge
4
+ from .signer import DEFAULT_TTL_SECONDS, HmacSigner, default_expiry
5
+
6
+ __all__ = ["FileAccessError", "FileBridge", "HmacSigner", "DEFAULT_TTL_SECONDS", "default_expiry"]
7
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ """Adapters are the only framework-aware code in this package.
2
+
3
+ Each adapter is a thin shell: it knows how one framework hands you a tool call,
4
+ and forwards the arguments to :func:`mcp_file_bridge.interceptors.rewrite.rewrite_local_paths`.
5
+ """
@@ -0,0 +1,72 @@
1
+ """LangChain / langchain-mcp-adapters interceptor.
2
+
3
+ Nothing here imports LangChain: the adapter only relies on the shape every
4
+ tool interceptor already has — an object with ``name`` / ``args`` / ``override()``,
5
+ plus a handler coroutine. That keeps the dependency list empty and the adapter
6
+ usable across versions.
7
+
8
+ from langchain_mcp_adapters.client import MultiServerMCPClient
9
+ from mcp_file_bridge.adapters.langchain import langchain_bridge
10
+
11
+ client = MultiServerMCPClient(
12
+ servers,
13
+ tool_interceptors=[langchain_bridge(bridge, session_id=runtime.thread_id)],
14
+ )
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from collections.abc import Awaitable, Callable
20
+ from typing import Any
21
+
22
+ from ..bridge import FileBridge
23
+ from ..interceptors.rewrite import rewrite_local_paths
24
+
25
+ SessionId = str | Callable[[], str]
26
+
27
+
28
+ class LangChainBridgeInterceptor:
29
+ """Rewrite session-file arguments before the MCP server sees them."""
30
+
31
+ def __init__(
32
+ self,
33
+ bridge: FileBridge,
34
+ *,
35
+ session_id: SessionId,
36
+ is_local_path: Callable[[str], bool],
37
+ session_prefix: str = "/",
38
+ ) -> None:
39
+ self._bridge = bridge
40
+ self._session_id = session_id
41
+ self._is_local_path = is_local_path
42
+ self._session_prefix = session_prefix
43
+
44
+ def _resolve_session(self) -> str:
45
+ return self._session_id() if callable(self._session_id) else self._session_id
46
+
47
+ async def __call__(self, request: Any, handler: Callable[[Any], Awaitable[Any]]) -> Any:
48
+ args, changed = rewrite_local_paths(
49
+ dict(getattr(request, "args", None) or {}),
50
+ session_id=self._resolve_session(),
51
+ bridge=self._bridge,
52
+ is_local_path=self._is_local_path,
53
+ session_prefix=self._session_prefix,
54
+ )
55
+ if not changed:
56
+ return await handler(request)
57
+ return await handler(request.override(args=args))
58
+
59
+
60
+ def langchain_bridge(
61
+ bridge: FileBridge,
62
+ *,
63
+ session_id: SessionId,
64
+ is_local_path: Callable[[str], bool],
65
+ session_prefix: str = "/",
66
+ ) -> LangChainBridgeInterceptor:
67
+ return LangChainBridgeInterceptor(
68
+ bridge,
69
+ session_id=session_id,
70
+ is_local_path=is_local_path,
71
+ session_prefix=session_prefix,
72
+ )
@@ -0,0 +1,68 @@
1
+ """Turn a session-relative path into a link an external tool can fetch."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable
6
+ from pathlib import Path
7
+ from urllib.parse import quote
8
+
9
+ from .signer import DEFAULT_TTL_SECONDS, HmacSigner, default_expiry
10
+
11
+
12
+ class FileAccessError(Exception):
13
+ """Raised when a path is outside the session scope, or is not a file."""
14
+
15
+
16
+ class FileBridge:
17
+ """Links files inside ``root_for(session_id)`` behind an HMAC signature.
18
+
19
+ ``root_for`` is the only thing the library assumes about your storage: give
20
+ it a session id, get back the directory that session is allowed to expose.
21
+ Everything else (where files really live, how they got there) stays yours.
22
+ """
23
+
24
+ def __init__(
25
+ self,
26
+ *,
27
+ root_for: Callable[[str], Path],
28
+ signer: HmacSigner,
29
+ base_url: str,
30
+ ttl: int = DEFAULT_TTL_SECONDS,
31
+ route_prefix: str = "/mcp-files",
32
+ ) -> None:
33
+ self._root_for = root_for
34
+ self._signer = signer
35
+ self._base_url = base_url.rstrip("/")
36
+ self._ttl = ttl
37
+ self._route_prefix = "/" + route_prefix.strip("/")
38
+ self._history: list[tuple[str, str, int]] = []
39
+
40
+ @property
41
+ def route_prefix(self) -> str:
42
+ return self._route_prefix
43
+
44
+ @property
45
+ def signer(self) -> HmacSigner:
46
+ return self._signer
47
+
48
+ def resolve(self, session_id: str, rel_path: str) -> Path:
49
+ """Resolve ``rel_path`` inside the session root, refusing to escape it."""
50
+ root = self._root_for(session_id).resolve()
51
+ candidate = (root / rel_path).resolve()
52
+ try:
53
+ candidate.relative_to(root)
54
+ except ValueError as exc:
55
+ raise FileAccessError(f"path escapes session scope: {rel_path}") from exc
56
+ if not candidate.is_file():
57
+ raise FileAccessError(f"not a file: {rel_path}")
58
+ return candidate
59
+
60
+ def link(self, session_id: str, rel_path: str, *, ttl: int | None = None) -> str:
61
+ """Return an expiring URL for ``rel_path`` (validated before signing)."""
62
+ self.resolve(session_id, rel_path)
63
+ expires = default_expiry(self._ttl if ttl is None else ttl)
64
+ signature = self._signer.sign(session_id, rel_path, expires)
65
+ return (
66
+ f"{self._base_url}{self._route_prefix}/{quote(rel_path, safe='/')}"
67
+ f"?session={quote(session_id, safe='')}&expires={expires}&sig={signature}"
68
+ )
@@ -0,0 +1,33 @@
1
+ """Drop-in download endpoint for FastAPI / Starlette.
2
+
3
+ from fastapi import FastAPI
4
+ from mcp_file_bridge.endpoints.fastapi import mount_bridge
5
+
6
+ app = FastAPI()
7
+ mount_bridge(app, bridge)
8
+
9
+ FastAPI is an optional dependency: the core package has none.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import time
15
+ from typing import Any
16
+
17
+ from ..bridge import FileAccessError, FileBridge
18
+
19
+
20
+ def mount_bridge(app: Any, bridge: FileBridge) -> None:
21
+ from fastapi.responses import FileResponse, PlainTextResponse
22
+
23
+ pattern = bridge.route_prefix + "/{rel_path:path}"
24
+
25
+ @app.get(pattern)
26
+ async def _download(rel_path: str, session: str, expires: int, sig: str) -> Any:
27
+ if not bridge.signer.verify(session, rel_path, expires, sig, now=int(time.time())):
28
+ return PlainTextResponse("link is invalid or expired", status_code=403)
29
+ try:
30
+ path = bridge.resolve(session, rel_path)
31
+ except FileAccessError:
32
+ return PlainTextResponse("file not found", status_code=404)
33
+ return FileResponse(path, filename=path.name)
@@ -0,0 +1,40 @@
1
+ """Rewrite tool arguments before they reach an external MCP server.
2
+
3
+ Design notes:
4
+ - only values that look like session files are touched; plain strings (a city
5
+ name, an id) are passed through untouched
6
+ - ``thread_id`` / ``session_id`` is taken from the agent runtime, never from the
7
+ model, so a model cannot widen its own scope
8
+ - on stdio servers the file is already on the same filesystem: hand over the
9
+ real path instead of a URL
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from collections.abc import Callable
15
+ from typing import Any
16
+
17
+ from ..bridge import FileBridge
18
+
19
+
20
+ def rewrite_local_paths(
21
+ args: dict[str, Any],
22
+ *,
23
+ session_id: str,
24
+ bridge: FileBridge,
25
+ is_local_path: Callable[[str], bool],
26
+ session_prefix: str = "/",
27
+ ) -> tuple[dict[str, Any], list[str]]:
28
+ """Return ``(new_args, changed_keys)``; unknown/invalid paths stay as they are."""
29
+ changed: list[str] = []
30
+ result = dict(args)
31
+ for key, value in args.items():
32
+ if not isinstance(value, str) or not is_local_path(value):
33
+ continue
34
+ rel_path = value.removeprefix(session_prefix).lstrip("/")
35
+ try:
36
+ result[key] = bridge.link(session_id, rel_path)
37
+ except Exception: # noqa: BLE001 - a bad path must not break the tool call
38
+ continue
39
+ changed.append(key)
40
+ return result, changed
@@ -0,0 +1,43 @@
1
+ """Signed, expiring links to files that live behind a session scope.
2
+
3
+ The pattern is the same one object storage uses for presigned URLs: the holder
4
+ of the link can fetch the bytes until it expires, and nobody else can mint one
5
+ without the secret.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import hmac
12
+ import time
13
+ from dataclasses import dataclass
14
+
15
+ DEFAULT_TTL_SECONDS = 1800
16
+
17
+
18
+ @dataclass(frozen=True)
19
+ class HmacSigner:
20
+ """HMAC-SHA256 signer. ``secret`` never leaves the server."""
21
+
22
+ secret: str
23
+
24
+ def sign(self, session_id: str, rel_path: str, expires: int) -> str:
25
+ payload = f"{session_id}:{rel_path}:{expires}".encode()
26
+ return hmac.new(self.secret.encode(), payload, hashlib.sha256).hexdigest()
27
+
28
+ def verify(
29
+ self,
30
+ session_id: str,
31
+ rel_path: str,
32
+ expires: int,
33
+ signature: str,
34
+ *,
35
+ now: int | None = None,
36
+ ) -> bool:
37
+ if expires < (now if now is not None else int(time.time())):
38
+ return False
39
+ return hmac.compare_digest(self.sign(session_id, rel_path, expires), signature)
40
+
41
+
42
+ def default_expiry(ttl: int = DEFAULT_TTL_SECONDS, *, now: int | None = None) -> int:
43
+ return (now if now is not None else int(time.time())) + ttl
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.5
2
+ Name: mcp-file-bridge
3
+ Version: 0.1.0
4
+ Summary: Give external MCP servers a signed, expiring link to user files — no base64, no shared volumes.
5
+ Author: liuyurong
6
+ License: Apache-2.0
7
+ License-File: LICENSE
8
+ Keywords: file-transfer,mcp,model-context-protocol,presigned-url
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.10
12
+ Provides-Extra: dev
13
+ Requires-Dist: langchain-mcp-adapters>=0.1; extra == 'dev'
14
+ Requires-Dist: mcp>=1.9; extra == 'dev'
15
+ Requires-Dist: pytest>=8; extra == 'dev'
16
+ Requires-Dist: ruff>=0.6; extra == 'dev'
17
+ Provides-Extra: fastapi
18
+ Requires-Dist: fastapi>=0.110; extra == 'fastapi'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # mcp-file-bridge
22
+
23
+ **Give an external MCP server a signed, expiring link to a user's file — without base64 and without a shared volume.**
24
+
25
+ ```
26
+ /user-uploads/report.pdf ──► http://platform/mcp-files/report.pdf?session=…&expires=…&sig=…
27
+ ▲
28
+ the MCP server just does urllib.request.urlopen(...)
29
+ ```
30
+
31
+ > Status: v0.1, early. Core + FastAPI endpoint + argument rewriter are usable; the LangChain adapter is next.
32
+
33
+ ---
34
+
35
+ ## The gap this fills
36
+
37
+ MCP has **no file-upload primitive for tool arguments**. Tool *results* can carry
38
+ [resource links and embedded resources](https://modelcontextprotocol.io/specification/2025-06-18/server/tools),
39
+ but the client → server direction has nothing. The official
40
+ [File Uploads working group](https://modelcontextprotocol.io/community/working-groups/file-uploads/)
41
+ puts it plainly: servers "resort to prose instructions asking for base64 strings or local paths".
42
+
43
+ So everybody improvises. The five patterns you will actually meet:
44
+
45
+ | Pattern | Works when | Breaks when |
46
+ |---|---|---|
47
+ | Pass a local path / use `roots` | client and server share a filesystem | the server is remote |
48
+ | Base64 inside the tool argument | files are tiny | 10 MB → 13 MB of JSON, straight through the context window |
49
+ | **Signed URL (this library)** | both sides can speak HTTP | network is one-way and the server cannot reach you |
50
+ | Vendor upload channel (`attach_file` in ChatGPT, File Uploads in Claude) | you are that vendor | you are not |
51
+ | Proxy that base64-encodes paths (`mcp-file-proxy`) | you cannot change the server | large files |
52
+
53
+ `mcp-file-bridge` implements the third one as a library, and keeps the first one for
54
+ stdio servers automatically.
55
+
56
+ ---
57
+
58
+ ## Install
59
+
60
+ ```bash
61
+ pip install mcp-file-bridge # core, zero dependencies
62
+ pip install "mcp-file-bridge[fastapi]" # + the download endpoint
63
+ ```
64
+
65
+ ## Three lines
66
+
67
+ ```python
68
+ from fastapi import FastAPI
69
+ from mcp_file_bridge import FileBridge, HmacSigner
70
+ from mcp_file_bridge.endpoints.fastapi import mount_bridge
71
+
72
+ app = FastAPI()
73
+ bridge = FileBridge(
74
+ root_for=lambda session_id: Path("/data/sessions") / session_id, # your storage, your rules
75
+ signer=HmacSigner(os.environ["FILE_BRIDGE_SECRET"]),
76
+ base_url="http://platform.internal:8000", # what the *MCP server* can reach
77
+ ttl=1800,
78
+ )
79
+ mount_bridge(app, bridge)
80
+
81
+ url = bridge.link(session_id, "uploads/report.pdf") # hand this to the tool
82
+ ```
83
+
84
+ ## Rewriting tool arguments
85
+
86
+ The framework-agnostic core is one pure function — no LangChain, no MCP SDK:
87
+
88
+ ```python
89
+ from mcp_file_bridge.interceptors.rewrite import rewrite_local_paths
90
+
91
+ args, changed = rewrite_local_paths(
92
+ tool_args,
93
+ session_id=run.thread_id, # from the runtime, never from the model
94
+ bridge=bridge,
95
+ is_local_path=lambda v: v.startswith("/files/"),
96
+ session_prefix="/files/",
97
+ )
98
+ if changed:
99
+ call = call.override(args=args)
100
+ ```
101
+
102
+ ### LangChain / `langchain-mcp-adapters`
103
+
104
+ The adapter ships with the package and imports nothing from LangChain — it only
105
+ relies on the interceptor contract (`name` / `args` / `override()` + a handler).
106
+
107
+ ```python
108
+ from langchain_mcp_adapters.client import MultiServerMCPClient
109
+ from mcp_file_bridge.adapters.langchain import langchain_bridge
110
+
111
+ client = MultiServerMCPClient(
112
+ servers,
113
+ tool_interceptors=[
114
+ langchain_bridge(
115
+ bridge,
116
+ session_id=lambda: runtime.thread_id, # resolved per call
117
+ is_local_path=lambda v: v.startswith("/files/"),
118
+ session_prefix="/files/",
119
+ )
120
+ ],
121
+ )
122
+ ```
123
+
124
+ ### Writing your own adapter
125
+
126
+ An adapter is ~20 lines: hand it the tool name, the arguments and the session id,
127
+ and give back rewritten arguments. If your framework exposes any hook around tool
128
+ calls — a middleware, a wrapper, a decorator — that is enough:
129
+
130
+ ```python
131
+ args, changed = rewrite_local_paths(args, session_id=sid, bridge=bridge, is_local_path=...)
132
+ if changed:
133
+ args = args # call the tool with these instead
134
+ ```
135
+
136
+ If it exposes no hook at all (a closed client with only a `url` field), put a
137
+ proxy in front of the MCP server instead — that is the fallback, not the main path.
138
+
139
+
140
+ ---
141
+
142
+ ## Design notes
143
+
144
+ - **Scope comes from the runtime, not the model.** The session id is injected by the
145
+ agent runner. A model cannot widen its own access by inventing an id.
146
+ - **Local servers get a path, remote servers get a URL.** A stdio MCP already shares
147
+ your filesystem; a URL there is pure overhead. Decide per server, not globally.
148
+ - **Fail loudly.** A path that does not resolve is left untouched (or raises), never
149
+ silently replaced with a default file. Silent fallback is how "it worked" pipelines
150
+ end up training on the wrong data.
151
+ - **Storage agnostic.** The library only asks for `root_for(session_id) -> Path`.
152
+ S3, a mounted volume, a database blob store — all yours to implement.
153
+
154
+ ## Security model
155
+
156
+ A link is a bearer credential for one file, for a few minutes:
157
+
158
+ - HMAC-SHA256 over `session:path:expires`, compared in constant time;
159
+ - URLs expire (default 30 min) and are refused after that;
160
+ - `resolve()` refuses paths that escape the session root;
161
+ - the endpoint is intentionally anonymous — the signature *is* the authentication.
162
+
163
+ Put it behind HTTPS in production, keep the TTL short, and do not log full URLs.
164
+
165
+ ---
166
+
167
+ ## Demo
168
+
169
+ ```bash
170
+ pip install -e ".[fastapi]"
171
+ python demo/demo.py
172
+ ```
173
+
174
+ It starts the bridge, mints a link for a file in a temp session, then fetches it the
175
+ way an MCP server would, and prints status + byte count.
176
+
177
+ ## Roadmap
178
+
179
+ - [x] LangChain `MultiServerMCPClient` interceptor
180
+ - [ ] Official MCP Python SDK wrapper
181
+ - [ ] S3 / MinIO presigned backend
182
+ - [ ] TypeScript port
183
+ - [ ] `auto` mode: path for stdio, URL for streamable HTTP
184
+
185
+ ## Relationship to SEP-2356
186
+
187
+ The working group's draft adds a declarative "this argument is a file" descriptor.
188
+ When it lands, this library does not become obsolete: the descriptor replaces the
189
+ *detection* step, and the signed-link *transport* underneath stays the same. That is
190
+ deliberate — the mechanism lives at the transport layer, not in your tool schemas.
191
+
192
+ ## License
193
+
194
+ Apache-2.0.
@@ -0,0 +1,15 @@
1
+ mcp_file_bridge-0.1.0.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
2
+ mcp_file_bridge-0.1.0.dist-info/METADATA,sha256=AUSBydhUKIUF8WRZ5M7_r6CqkpiueiJ-s9JdO6dfXmM,6916
3
+ mcp_file_bridge-0.1.0.dist-info/RECORD,,
4
+ mcp_file_bridge-0.1.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ mcp_file_bridge-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
6
+ mcp_file_bridge-0.1.0.dist-info/direct_url.json,sha256=Kxn6nEVxBzo5DegKJJFs2fmuOlxSowvPo5teGIDBmb0,109
7
+ mcp_file_bridge-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
8
+ mcp_file_bridge-0.1.0.dist-info/uv_cache.json,sha256=fWvtD0rnEsjdo0f_JI44NsICmPxw9te60KLGfwFHvZQ,127
9
+ mcp_file_bridge/__init__.py,sha256=Tp1ecXo5hA8XxJ1Wpw9BXmO4rs4BHFlaghjZ7KODNGk,308
10
+ mcp_file_bridge/adapters/__init__.py,sha256=LQSoUtJt88lTojZoYLj7NgPP3AwsxTNNrJJJpVkYsmc,244
11
+ mcp_file_bridge/adapters/langchain.py,sha256=Gx5W3Di7fzCn8GU54WzgI70y9j5r1zmiAukszvuT1GY,2287
12
+ mcp_file_bridge/bridge.py,sha256=wZXzZfh7OQxfeRtEues-nkKmnSb0hQG-9MDyy2dNAXM,2460
13
+ mcp_file_bridge/endpoints/fastapi.py,sha256=16iShaArP7dCBh2dTV8RFWMpQKmS8c9PVY6WKcBKegQ,1078
14
+ mcp_file_bridge/interceptors/rewrite.py,sha256=bxWvjEXhDhfJ1s-_0auUZ_1hHs-i9OikjEAMSWOtyzo,1352
15
+ mcp_file_bridge/signer.py,sha256=6DSRJj5oESmbiAnelqQLSmK6ZilFLK3_v7l8BvdTiQo,1255
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1 @@
1
+ {"url":"file:///D:/opensource/mcp-file-bridge/dist/mcp_file_bridge-0.1.0-py3-none-any.whl","archive_info":{}}