fastbridge 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.
- fastbridge-0.1.0/LICENSE +21 -0
- fastbridge-0.1.0/PKG-INFO +237 -0
- fastbridge-0.1.0/README.md +195 -0
- fastbridge-0.1.0/pyproject.toml +150 -0
- fastbridge-0.1.0/src/fastbridge/__init__.py +15 -0
- fastbridge-0.1.0/src/fastbridge/decorators.py +47 -0
- fastbridge-0.1.0/src/fastbridge/django/__init__.py +1 -0
- fastbridge-0.1.0/src/fastbridge/django/apps.py +17 -0
- fastbridge-0.1.0/src/fastbridge/django/discovery.py +106 -0
- fastbridge-0.1.0/src/fastbridge/django/middleware.py +98 -0
- fastbridge-0.1.0/src/fastbridge/executor.py +69 -0
- fastbridge-0.1.0/src/fastbridge/fastapi/__init__.py +5 -0
- fastbridge-0.1.0/src/fastbridge/fastapi/bridge.py +71 -0
- fastbridge-0.1.0/src/fastbridge/fastapi/discovery.py +102 -0
- fastbridge-0.1.0/src/fastbridge/ir.py +92 -0
- fastbridge-0.1.0/src/fastbridge/litestar/__init__.py +5 -0
- fastbridge-0.1.0/src/fastbridge/litestar/bridge.py +71 -0
- fastbridge-0.1.0/src/fastbridge/litestar/discovery.py +65 -0
- fastbridge-0.1.0/src/fastbridge/naming.py +6 -0
- fastbridge-0.1.0/src/fastbridge/openapi.py +35 -0
- fastbridge-0.1.0/src/fastbridge/protocols.py +118 -0
- fastbridge-0.1.0/src/fastbridge/py.typed +0 -0
- fastbridge-0.1.0/tests/django_project.py +78 -0
- fastbridge-0.1.0/tests/test_django.py +139 -0
- fastbridge-0.1.0/tests/test_docs_config.py +90 -0
- fastbridge-0.1.0/tests/test_fastapi.py +207 -0
- fastbridge-0.1.0/tests/test_litestar.py +162 -0
- fastbridge-0.1.0/tests/test_package.py +83 -0
- fastbridge-0.1.0/tests/test_real_clients.py +125 -0
- fastbridge-0.1.0/tests/test_starlette.py +71 -0
fastbridge-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ihor Korolenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: fastbridge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Expose FastAPI, Starlette, Django and Litestar endpoints as MCP and UTCP tools with one line.
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: mcp,utcp,model-context-protocol,llm,agents,tools,fastapi,starlette,django,litestar,openapi
|
|
7
|
+
Author: korolenkowork
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Framework :: AsyncIO
|
|
12
|
+
Classifier: Framework :: Django
|
|
13
|
+
Classifier: Framework :: FastAPI
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
23
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Provides-Extra: django
|
|
27
|
+
Provides-Extra: fastapi
|
|
28
|
+
Provides-Extra: litestar
|
|
29
|
+
Provides-Extra: starlette
|
|
30
|
+
Requires-Dist: django (>=4.2) ; extra == "django"
|
|
31
|
+
Requires-Dist: fastapi (>=0.110) ; extra == "fastapi"
|
|
32
|
+
Requires-Dist: httpx (>=0.27)
|
|
33
|
+
Requires-Dist: litestar (>=2.4) ; (python_version < "4.0") and (extra == "litestar")
|
|
34
|
+
Requires-Dist: starlette (>=0.36.3) ; extra == "starlette"
|
|
35
|
+
Project-URL: Changelog, https://github.com/korolenkowork/FastBridge/blob/main/CHANGELOG.md
|
|
36
|
+
Project-URL: Documentation, https://korolenkowork.github.io/FastBridge/
|
|
37
|
+
Project-URL: Homepage, https://github.com/korolenkowork/FastBridge
|
|
38
|
+
Project-URL: Issues, https://github.com/korolenkowork/FastBridge/issues
|
|
39
|
+
Project-URL: Repository, https://github.com/korolenkowork/FastBridge
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# FastBridge
|
|
43
|
+
|
|
44
|
+
[](https://pypi.org/project/fastbridge/)
|
|
45
|
+
[](https://pypi.org/project/fastbridge/)
|
|
46
|
+
[](https://github.com/korolenkowork/FastBridge/actions/workflows/ci.yml)
|
|
47
|
+
[](https://korolenkowork.github.io/FastBridge/)
|
|
48
|
+
[](https://github.com/korolenkowork/FastBridge/blob/main/LICENSE)
|
|
49
|
+
|
|
50
|
+
Expose the endpoints you already have as **MCP** and **UTCP** tools, with one line
|
|
51
|
+
and no changes to the endpoints.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from fastapi import FastAPI
|
|
55
|
+
from fastbridge.fastapi import bridge
|
|
56
|
+
|
|
57
|
+
app = FastAPI()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@app.get("/items/{item_id}")
|
|
61
|
+
def get_item(item_id: int):
|
|
62
|
+
"""Fetch one item by id."""
|
|
63
|
+
...
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
bridge(app) # adds POST /mcp and GET /utcp
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Works with **FastAPI**, **Starlette**, **Django** and **Litestar**.
|
|
70
|
+
|
|
71
|
+
📖 **Documentation: <https://korolenkowork.github.io/FastBridge/>**
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install "fastbridge[fastapi]" # FastAPI
|
|
77
|
+
pip install "fastbridge[starlette]" # plain Starlette
|
|
78
|
+
pip install "fastbridge[django]" # Django
|
|
79
|
+
pip install "fastbridge[litestar]" # Litestar
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
poetry add "fastbridge[fastapi]"
|
|
84
|
+
uv add "fastbridge[fastapi]"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Python 3.10 or newer. The core depends only on `httpx`; each framework is an
|
|
88
|
+
optional extra, so you only install the one you use.
|
|
89
|
+
|
|
90
|
+
## What you get
|
|
91
|
+
|
|
92
|
+
| Endpoint | Protocol | What a client does |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `GET /utcp` | [UTCP](https://utcp.io/) manual | Reads the manual, then calls your endpoints **directly** (no proxy). |
|
|
95
|
+
| `POST /mcp` | [MCP](https://modelcontextprotocol.io/) (Streamable HTTP, JSON-RPC) | `tools/list`, `tools/call`; calls run **inside your app**. |
|
|
96
|
+
|
|
97
|
+
### UTCP view
|
|
98
|
+
|
|
99
|
+

|
|
100
|
+
|
|
101
|
+
### MCP view
|
|
102
|
+
|
|
103
|
+

|
|
104
|
+
|
|
105
|
+
Both screenshots are real responses from
|
|
106
|
+
[`examples/fastapi_app.py`](https://github.com/korolenkowork/FastBridge/blob/main/examples/fastapi_app.py).
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
Each framework has its own subpackage; nothing framework-specific leaks into the others.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from fastbridge.fastapi import bridge # FastAPI and plain Starlette
|
|
114
|
+
from fastbridge.litestar import bridge # Litestar
|
|
115
|
+
|
|
116
|
+
bridge(app)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# Django: settings.py. No view or URL changes.
|
|
121
|
+
INSTALLED_APPS = [..., "fastbridge.django"]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Choosing what is exposed
|
|
125
|
+
|
|
126
|
+
By default (`mode="all"`) every endpoint becomes a tool. To expose only some,
|
|
127
|
+
use opt-in mode and the parameter-less `@tool` marker; `@hidden` removes an
|
|
128
|
+
endpoint in either mode.
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from fastbridge import hidden, tool
|
|
132
|
+
from fastbridge.fastapi import bridge
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@app.get("/items/{item_id}")
|
|
136
|
+
@tool # exposed in opt-in mode
|
|
137
|
+
def get_item(item_id: int): ...
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@app.delete("/items/{item_id}")
|
|
141
|
+
@hidden # never exposed
|
|
142
|
+
def delete_item(item_id: int): ...
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
bridge(app, mode="opt-in")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
> **Think before leaving `mode="all"` on.** Every route, including `DELETE` and
|
|
149
|
+
> other state-changing routes, becomes callable by whoever can reach `/mcp`.
|
|
150
|
+
> Prefer `opt-in` for anything real.
|
|
151
|
+
|
|
152
|
+
## How it works
|
|
153
|
+
|
|
154
|
+
Each adapter discovers your routes and describes them in one shared form, which
|
|
155
|
+
both protocols are generated from. A tool call is then a **real request through
|
|
156
|
+
your own app**, so middleware, dependencies, authentication and validation all
|
|
157
|
+
still run. `Authorization`, `Cookie` and `X-API-Key` are forwarded from the MCP
|
|
158
|
+
request. An endpoint that answers `4xx`/`5xx` becomes an MCP result with
|
|
159
|
+
`isError: true`, so the model sees what went wrong.
|
|
160
|
+
|
|
161
|
+
See [How it works](https://korolenkowork.github.io/FastBridge/how-it-works/) for
|
|
162
|
+
the details.
|
|
163
|
+
|
|
164
|
+
## Framework coverage
|
|
165
|
+
|
|
166
|
+
| | FastAPI | Starlette | Litestar | Django |
|
|
167
|
+
|---|---|---|---|---|
|
|
168
|
+
| Input schema | full (OpenAPI) | path params only | full (OpenAPI) | path params only |
|
|
169
|
+
| Query params | declared | free-form `query` object | declared | free-form `query` object |
|
|
170
|
+
| Request body | declared | free-form `body` object | declared | free-form `body` object |
|
|
171
|
+
|
|
172
|
+
Where a framework declares no schema, MCP tools accept an optional free-form
|
|
173
|
+
`query` object and, for `POST`/`PUT`/`PATCH`, a free-form `body` object. UTCP
|
|
174
|
+
omits `query`, because its HTTP template cannot express an arbitrary query string.
|
|
175
|
+
|
|
176
|
+
## Limits worth knowing
|
|
177
|
+
|
|
178
|
+
- **Django function views are assumed to be `GET`.** They do not declare their
|
|
179
|
+
methods, so a `@require_POST` view is listed as `GET`. Class-based views are
|
|
180
|
+
read properly.
|
|
181
|
+
- **Django and CSRF.** Tool calls over MCP skip CSRF checking. UTCP clients call
|
|
182
|
+
the view directly and would hit it, so CSRF-protected `POST` views are left out
|
|
183
|
+
of the UTCP manual (MCP only) unless they are `csrf_exempt`.
|
|
184
|
+
- **The MCP server is minimal:** stateless JSON responses. No sessions, SSE
|
|
185
|
+
streaming, resources or prompts.
|
|
186
|
+
- **`/mcp` and `/utcp` have no authentication of their own.** Anyone who can
|
|
187
|
+
reach them can list your tools; calls are then subject to each endpoint's
|
|
188
|
+
normal auth. See [Security](https://korolenkowork.github.io/FastBridge/security/).
|
|
189
|
+
|
|
190
|
+
## Compatibility
|
|
191
|
+
|
|
192
|
+
| | Minimum | Newest tested |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| Python | 3.10 | 3.14 |
|
|
195
|
+
| Starlette | 0.36.3 | 1.10.0 |
|
|
196
|
+
| FastAPI | 0.110 | 0.165.0 |
|
|
197
|
+
| Django | 4.2 | 6.1.3 |
|
|
198
|
+
| Litestar | 2.4 | 2.25.0 |
|
|
199
|
+
|
|
200
|
+
CI runs the suite against the exact minimums and maximums on every change, and
|
|
201
|
+
against real MCP and UTCP clients. See
|
|
202
|
+
[Compatibility](https://korolenkowork.github.io/FastBridge/compatibility/).
|
|
203
|
+
|
|
204
|
+
## Examples
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
PYTHONPATH=src uvicorn fastapi_app:app --app-dir examples --port 8001
|
|
208
|
+
PYTHONPATH=src uvicorn django_app:application --app-dir examples --port 8002
|
|
209
|
+
PYTHONPATH=src uvicorn litestar_app:app --app-dir examples --port 8003
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Check a running server with the official clients (needs `mcp`, `utcp` and
|
|
213
|
+
`utcp-http` installed):
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
python examples/verify_clients.py http://127.0.0.1:8001
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Development
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
git clone https://github.com/korolenkowork/FastBridge
|
|
223
|
+
cd FastBridge
|
|
224
|
+
poetry install --with dev,docs
|
|
225
|
+
poetry run pytest
|
|
226
|
+
poetry run ruff check . && poetry run ruff format --check . && poetry run mypy
|
|
227
|
+
poetry run mkdocs serve
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
To cut a release, see the header of
|
|
231
|
+
[`.github/workflows/publish.yml`](https://github.com/korolenkowork/FastBridge/blob/main/.github/workflows/publish.yml).
|
|
232
|
+
Changes are listed in the [changelog](https://github.com/korolenkowork/FastBridge/blob/main/CHANGELOG.md).
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
MIT. See [LICENSE](https://github.com/korolenkowork/FastBridge/blob/main/LICENSE).
|
|
237
|
+
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# FastBridge
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/fastbridge/)
|
|
4
|
+
[](https://pypi.org/project/fastbridge/)
|
|
5
|
+
[](https://github.com/korolenkowork/FastBridge/actions/workflows/ci.yml)
|
|
6
|
+
[](https://korolenkowork.github.io/FastBridge/)
|
|
7
|
+
[](https://github.com/korolenkowork/FastBridge/blob/main/LICENSE)
|
|
8
|
+
|
|
9
|
+
Expose the endpoints you already have as **MCP** and **UTCP** tools, with one line
|
|
10
|
+
and no changes to the endpoints.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from fastapi import FastAPI
|
|
14
|
+
from fastbridge.fastapi import bridge
|
|
15
|
+
|
|
16
|
+
app = FastAPI()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@app.get("/items/{item_id}")
|
|
20
|
+
def get_item(item_id: int):
|
|
21
|
+
"""Fetch one item by id."""
|
|
22
|
+
...
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
bridge(app) # adds POST /mcp and GET /utcp
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Works with **FastAPI**, **Starlette**, **Django** and **Litestar**.
|
|
29
|
+
|
|
30
|
+
📖 **Documentation: <https://korolenkowork.github.io/FastBridge/>**
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install "fastbridge[fastapi]" # FastAPI
|
|
36
|
+
pip install "fastbridge[starlette]" # plain Starlette
|
|
37
|
+
pip install "fastbridge[django]" # Django
|
|
38
|
+
pip install "fastbridge[litestar]" # Litestar
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
poetry add "fastbridge[fastapi]"
|
|
43
|
+
uv add "fastbridge[fastapi]"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Python 3.10 or newer. The core depends only on `httpx`; each framework is an
|
|
47
|
+
optional extra, so you only install the one you use.
|
|
48
|
+
|
|
49
|
+
## What you get
|
|
50
|
+
|
|
51
|
+
| Endpoint | Protocol | What a client does |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `GET /utcp` | [UTCP](https://utcp.io/) manual | Reads the manual, then calls your endpoints **directly** (no proxy). |
|
|
54
|
+
| `POST /mcp` | [MCP](https://modelcontextprotocol.io/) (Streamable HTTP, JSON-RPC) | `tools/list`, `tools/call`; calls run **inside your app**. |
|
|
55
|
+
|
|
56
|
+
### UTCP view
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
### MCP view
|
|
61
|
+
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
Both screenshots are real responses from
|
|
65
|
+
[`examples/fastapi_app.py`](https://github.com/korolenkowork/FastBridge/blob/main/examples/fastapi_app.py).
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
Each framework has its own subpackage; nothing framework-specific leaks into the others.
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from fastbridge.fastapi import bridge # FastAPI and plain Starlette
|
|
73
|
+
from fastbridge.litestar import bridge # Litestar
|
|
74
|
+
|
|
75
|
+
bridge(app)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
# Django: settings.py. No view or URL changes.
|
|
80
|
+
INSTALLED_APPS = [..., "fastbridge.django"]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Choosing what is exposed
|
|
84
|
+
|
|
85
|
+
By default (`mode="all"`) every endpoint becomes a tool. To expose only some,
|
|
86
|
+
use opt-in mode and the parameter-less `@tool` marker; `@hidden` removes an
|
|
87
|
+
endpoint in either mode.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from fastbridge import hidden, tool
|
|
91
|
+
from fastbridge.fastapi import bridge
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@app.get("/items/{item_id}")
|
|
95
|
+
@tool # exposed in opt-in mode
|
|
96
|
+
def get_item(item_id: int): ...
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@app.delete("/items/{item_id}")
|
|
100
|
+
@hidden # never exposed
|
|
101
|
+
def delete_item(item_id: int): ...
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
bridge(app, mode="opt-in")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
> **Think before leaving `mode="all"` on.** Every route, including `DELETE` and
|
|
108
|
+
> other state-changing routes, becomes callable by whoever can reach `/mcp`.
|
|
109
|
+
> Prefer `opt-in` for anything real.
|
|
110
|
+
|
|
111
|
+
## How it works
|
|
112
|
+
|
|
113
|
+
Each adapter discovers your routes and describes them in one shared form, which
|
|
114
|
+
both protocols are generated from. A tool call is then a **real request through
|
|
115
|
+
your own app**, so middleware, dependencies, authentication and validation all
|
|
116
|
+
still run. `Authorization`, `Cookie` and `X-API-Key` are forwarded from the MCP
|
|
117
|
+
request. An endpoint that answers `4xx`/`5xx` becomes an MCP result with
|
|
118
|
+
`isError: true`, so the model sees what went wrong.
|
|
119
|
+
|
|
120
|
+
See [How it works](https://korolenkowork.github.io/FastBridge/how-it-works/) for
|
|
121
|
+
the details.
|
|
122
|
+
|
|
123
|
+
## Framework coverage
|
|
124
|
+
|
|
125
|
+
| | FastAPI | Starlette | Litestar | Django |
|
|
126
|
+
|---|---|---|---|---|
|
|
127
|
+
| Input schema | full (OpenAPI) | path params only | full (OpenAPI) | path params only |
|
|
128
|
+
| Query params | declared | free-form `query` object | declared | free-form `query` object |
|
|
129
|
+
| Request body | declared | free-form `body` object | declared | free-form `body` object |
|
|
130
|
+
|
|
131
|
+
Where a framework declares no schema, MCP tools accept an optional free-form
|
|
132
|
+
`query` object and, for `POST`/`PUT`/`PATCH`, a free-form `body` object. UTCP
|
|
133
|
+
omits `query`, because its HTTP template cannot express an arbitrary query string.
|
|
134
|
+
|
|
135
|
+
## Limits worth knowing
|
|
136
|
+
|
|
137
|
+
- **Django function views are assumed to be `GET`.** They do not declare their
|
|
138
|
+
methods, so a `@require_POST` view is listed as `GET`. Class-based views are
|
|
139
|
+
read properly.
|
|
140
|
+
- **Django and CSRF.** Tool calls over MCP skip CSRF checking. UTCP clients call
|
|
141
|
+
the view directly and would hit it, so CSRF-protected `POST` views are left out
|
|
142
|
+
of the UTCP manual (MCP only) unless they are `csrf_exempt`.
|
|
143
|
+
- **The MCP server is minimal:** stateless JSON responses. No sessions, SSE
|
|
144
|
+
streaming, resources or prompts.
|
|
145
|
+
- **`/mcp` and `/utcp` have no authentication of their own.** Anyone who can
|
|
146
|
+
reach them can list your tools; calls are then subject to each endpoint's
|
|
147
|
+
normal auth. See [Security](https://korolenkowork.github.io/FastBridge/security/).
|
|
148
|
+
|
|
149
|
+
## Compatibility
|
|
150
|
+
|
|
151
|
+
| | Minimum | Newest tested |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| Python | 3.10 | 3.14 |
|
|
154
|
+
| Starlette | 0.36.3 | 1.10.0 |
|
|
155
|
+
| FastAPI | 0.110 | 0.165.0 |
|
|
156
|
+
| Django | 4.2 | 6.1.3 |
|
|
157
|
+
| Litestar | 2.4 | 2.25.0 |
|
|
158
|
+
|
|
159
|
+
CI runs the suite against the exact minimums and maximums on every change, and
|
|
160
|
+
against real MCP and UTCP clients. See
|
|
161
|
+
[Compatibility](https://korolenkowork.github.io/FastBridge/compatibility/).
|
|
162
|
+
|
|
163
|
+
## Examples
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
PYTHONPATH=src uvicorn fastapi_app:app --app-dir examples --port 8001
|
|
167
|
+
PYTHONPATH=src uvicorn django_app:application --app-dir examples --port 8002
|
|
168
|
+
PYTHONPATH=src uvicorn litestar_app:app --app-dir examples --port 8003
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Check a running server with the official clients (needs `mcp`, `utcp` and
|
|
172
|
+
`utcp-http` installed):
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
python examples/verify_clients.py http://127.0.0.1:8001
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Development
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
git clone https://github.com/korolenkowork/FastBridge
|
|
182
|
+
cd FastBridge
|
|
183
|
+
poetry install --with dev,docs
|
|
184
|
+
poetry run pytest
|
|
185
|
+
poetry run ruff check . && poetry run ruff format --check . && poetry run mypy
|
|
186
|
+
poetry run mkdocs serve
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
To cut a release, see the header of
|
|
190
|
+
[`.github/workflows/publish.yml`](https://github.com/korolenkowork/FastBridge/blob/main/.github/workflows/publish.yml).
|
|
191
|
+
Changes are listed in the [changelog](https://github.com/korolenkowork/FastBridge/blob/main/CHANGELOG.md).
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT. See [LICENSE](https://github.com/korolenkowork/FastBridge/blob/main/LICENSE).
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "fastbridge"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Expose FastAPI, Starlette, Django and Litestar endpoints as MCP and UTCP tools with one line."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "korolenkowork" }]
|
|
10
|
+
keywords = [
|
|
11
|
+
"mcp",
|
|
12
|
+
"utcp",
|
|
13
|
+
"model-context-protocol",
|
|
14
|
+
"llm",
|
|
15
|
+
"agents",
|
|
16
|
+
"tools",
|
|
17
|
+
"fastapi",
|
|
18
|
+
"starlette",
|
|
19
|
+
"django",
|
|
20
|
+
"litestar",
|
|
21
|
+
"openapi",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 4 - Beta",
|
|
25
|
+
"Environment :: Web Environment",
|
|
26
|
+
"Framework :: AsyncIO",
|
|
27
|
+
"Framework :: Django",
|
|
28
|
+
"Framework :: FastAPI",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3.10",
|
|
33
|
+
"Programming Language :: Python :: 3.11",
|
|
34
|
+
"Programming Language :: Python :: 3.12",
|
|
35
|
+
"Programming Language :: Python :: 3.13",
|
|
36
|
+
"Programming Language :: Python :: 3.14",
|
|
37
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
38
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
39
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
40
|
+
"Typing :: Typed",
|
|
41
|
+
]
|
|
42
|
+
# The core is framework-neutral: it only needs an HTTP client to dispatch tool
|
|
43
|
+
# calls. Every web framework is an extra, so installing fastbridge never drags
|
|
44
|
+
# in a framework you do not use.
|
|
45
|
+
dependencies = ["httpx>=0.27"]
|
|
46
|
+
|
|
47
|
+
[project.optional-dependencies]
|
|
48
|
+
# Floors are verified in CI by running the full suite against exactly these
|
|
49
|
+
# versions (the `floor` job); see docs/compatibility.md.
|
|
50
|
+
starlette = ["starlette>=0.36.3"]
|
|
51
|
+
fastapi = ["fastapi>=0.110"]
|
|
52
|
+
django = ["django>=4.2"]
|
|
53
|
+
# Litestar declares Python <4.0; the marker lets Poetry resolve the open-ended
|
|
54
|
+
# requires-python above without capping it for everyone else.
|
|
55
|
+
litestar = ["litestar>=2.4; python_version < '4.0'"]
|
|
56
|
+
|
|
57
|
+
[project.urls]
|
|
58
|
+
Homepage = "https://github.com/korolenkowork/FastBridge"
|
|
59
|
+
Documentation = "https://korolenkowork.github.io/FastBridge/"
|
|
60
|
+
Repository = "https://github.com/korolenkowork/FastBridge"
|
|
61
|
+
Changelog = "https://github.com/korolenkowork/FastBridge/blob/main/CHANGELOG.md"
|
|
62
|
+
Issues = "https://github.com/korolenkowork/FastBridge/issues"
|
|
63
|
+
|
|
64
|
+
# ---------------------------------------------------------------------------
|
|
65
|
+
# Build
|
|
66
|
+
# ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
[build-system]
|
|
69
|
+
requires = ["poetry-core>=2.0"]
|
|
70
|
+
build-backend = "poetry.core.masonry.api"
|
|
71
|
+
|
|
72
|
+
[tool.poetry]
|
|
73
|
+
# Poetry 2.x reads the standard [project] table above; this section only holds
|
|
74
|
+
# what PEP 621 has no field for.
|
|
75
|
+
packages = [{ include = "fastbridge", from = "src" }]
|
|
76
|
+
include = [{ path = "tests", format = "sdist" }]
|
|
77
|
+
|
|
78
|
+
# ---------------------------------------------------------------------------
|
|
79
|
+
# Development dependencies (poetry install --with dev,docs)
|
|
80
|
+
# ---------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
[tool.poetry.group.dev.dependencies]
|
|
83
|
+
pytest = ">=8.0"
|
|
84
|
+
pytest-cov = ">=5.0"
|
|
85
|
+
fastapi = ">=0.110"
|
|
86
|
+
django = ">=4.2"
|
|
87
|
+
litestar = { version = ">=2.4", python = "<4.0" }
|
|
88
|
+
ruff = ">=0.6"
|
|
89
|
+
mypy = ">=1.11"
|
|
90
|
+
# Starlette's TestClient uses httpx below 1.0 and httpx2 from 1.0 onward;
|
|
91
|
+
# installing both lets the CI matrix cover the whole supported range.
|
|
92
|
+
httpx2 = { version = ">=0.1", python = ">=3.10" }
|
|
93
|
+
# Real protocol clients, for tests/test_real_clients.py. The tests skip when
|
|
94
|
+
# these are absent, and the library itself never imports them.
|
|
95
|
+
mcp = ">=1.0"
|
|
96
|
+
utcp = ">=1.0"
|
|
97
|
+
utcp-http = ">=1.0"
|
|
98
|
+
uvicorn = ">=0.30"
|
|
99
|
+
# tomllib arrived in 3.11; the tests read pyproject.toml on 3.10 too.
|
|
100
|
+
tomli = { version = ">=2.0", python = "<3.11" }
|
|
101
|
+
pyyaml = ">=6.0"
|
|
102
|
+
|
|
103
|
+
[tool.poetry.group.docs.dependencies]
|
|
104
|
+
# Capped below 2.0: that release removes the plugin system outright, which
|
|
105
|
+
# would take mkdocstrings and the Material theme with it.
|
|
106
|
+
mkdocs = ">=1.6,<2.0"
|
|
107
|
+
mkdocs-material = ">=9.5,<10.0"
|
|
108
|
+
mkdocstrings = { version = ">=0.26", extras = ["python"] }
|
|
109
|
+
|
|
110
|
+
# ---------------------------------------------------------------------------
|
|
111
|
+
# Tooling
|
|
112
|
+
# ---------------------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
[tool.pytest.ini_options]
|
|
115
|
+
testpaths = ["tests"]
|
|
116
|
+
pythonpath = ["src", "tests"]
|
|
117
|
+
|
|
118
|
+
[tool.coverage.run]
|
|
119
|
+
source = ["fastbridge"]
|
|
120
|
+
branch = true
|
|
121
|
+
|
|
122
|
+
[tool.coverage.report]
|
|
123
|
+
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:", "raise NotImplementedError"]
|
|
124
|
+
|
|
125
|
+
[tool.ruff]
|
|
126
|
+
target-version = "py310"
|
|
127
|
+
line-length = 120
|
|
128
|
+
src = ["src", "tests"]
|
|
129
|
+
extend-exclude = ["site"]
|
|
130
|
+
|
|
131
|
+
[tool.ruff.lint]
|
|
132
|
+
select = ["E", "F", "W", "I", "B", "UP", "SIM", "C4", "PIE", "RET", "RUF", "PT"]
|
|
133
|
+
ignore = [
|
|
134
|
+
"RUF012", # class-level mutable defaults are not used for shared state here.
|
|
135
|
+
"RET504", # a named variable before return often reads better.
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
[tool.ruff.lint.per-file-ignores]
|
|
139
|
+
"tests/*" = ["B008", "PT011", "PT018", "E501"]
|
|
140
|
+
"examples/*" = ["B008", "E501"]
|
|
141
|
+
"scripts/*" = ["E501"]
|
|
142
|
+
|
|
143
|
+
[tool.mypy]
|
|
144
|
+
python_version = "3.10"
|
|
145
|
+
files = ["src"]
|
|
146
|
+
check_untyped_defs = true
|
|
147
|
+
warn_unreachable = true
|
|
148
|
+
warn_unused_ignores = true
|
|
149
|
+
# The frameworks are optional, so any of them may be absent when type checking.
|
|
150
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""FastBridge: expose web endpoints as MCP and UTCP tools.
|
|
2
|
+
|
|
3
|
+
This package is framework-neutral and only holds the markers. Each framework
|
|
4
|
+
adapter lives in its own subpackage and is imported explicitly:
|
|
5
|
+
|
|
6
|
+
- ``fastbridge.fastapi`` (also plain Starlette)
|
|
7
|
+
- ``fastbridge.django``
|
|
8
|
+
- ``fastbridge.litestar``
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .decorators import hidden, tool
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
14
|
+
|
|
15
|
+
__all__ = ["__version__", "hidden", "tool"]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Optional markers. Level 0 (`bridge(app)`) needs none of these."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TypeVar
|
|
6
|
+
|
|
7
|
+
F = TypeVar("F")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def tool(fn: F) -> F:
|
|
11
|
+
"""Mark an endpoint for exposure when the app is bridged with ``mode="opt-in"``.
|
|
12
|
+
|
|
13
|
+
Takes no arguments and returns the endpoint unchanged, so it composes with
|
|
14
|
+
any other decorator. Place it **below** the framework's route decorator;
|
|
15
|
+
above it, the router would already have registered the unmarked function.
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
```python
|
|
19
|
+
@app.get("/items/{item_id}")
|
|
20
|
+
@tool
|
|
21
|
+
def get_item(item_id: int): ...
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
fn: The endpoint function, or a class-based view.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
``fn``, with a marker attribute set.
|
|
29
|
+
"""
|
|
30
|
+
fn.__fastbridge__ = True # type: ignore[attr-defined]
|
|
31
|
+
return fn
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def hidden(fn: F) -> F:
|
|
35
|
+
"""Never expose this endpoint, in any mode.
|
|
36
|
+
|
|
37
|
+
Use it to keep an endpoint out of MCP and UTCP when the app is bridged with
|
|
38
|
+
the default ``mode="all"``. Place it below the framework's route decorator.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
fn: The endpoint function, or a class-based view.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
``fn``, with a marker attribute set.
|
|
45
|
+
"""
|
|
46
|
+
fn.__fastbridge_hidden__ = True # type: ignore[attr-defined]
|
|
47
|
+
return fn
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Django adapter. Add "fastbridge.django" to INSTALLED_APPS; nothing else is required."""
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from django.apps import AppConfig
|
|
2
|
+
from django.conf import settings
|
|
3
|
+
|
|
4
|
+
MIDDLEWARE = "fastbridge.django.middleware.BridgeMiddleware"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FastBridgeConfig(AppConfig):
|
|
8
|
+
"""App config that installs :class:`~fastbridge.django.middleware.BridgeMiddleware`."""
|
|
9
|
+
|
|
10
|
+
name = "fastbridge.django"
|
|
11
|
+
label = "fastbridge"
|
|
12
|
+
|
|
13
|
+
def ready(self):
|
|
14
|
+
# Level 0: put the bridge first in the chain so users edit nothing but INSTALLED_APPS.
|
|
15
|
+
# Skip if the user already placed it themselves.
|
|
16
|
+
if MIDDLEWARE not in settings.MIDDLEWARE:
|
|
17
|
+
settings.MIDDLEWARE = [MIDDLEWARE, *settings.MIDDLEWARE]
|