Skip to content

Commit e409015

Browse files
committed
FastMCP working
1 parent e817d75 commit e409015

File tree

13 files changed

+383
-277
lines changed

13 files changed

+383
-277
lines changed

.github/workflows/test.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Test Deploy CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
vendoring:
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest] # , windows-latest
16+
runs-on: ${{ matrix.os }}
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.12'
26+
27+
- name: Install Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: 22
31+
32+
- name: Install Wrangler
33+
run: npm install -g wrangler
34+
35+
- name: Run vendoring (Linux/macOS)
36+
if: runner.os != 'Windows'
37+
run: |
38+
python3.12 -m venv .venv
39+
source .venv/bin/activate
40+
.venv/bin/pip install pyodide-build
41+
.venv/bin/pyodide venv .venv-pyodide
42+
.venv-pyodide/bin/pip install -t src/vendor -r vendor.txt
43+
44+
# Windows is not supported by pyodide.
45+
# - name: Run vendoring (Windows)
46+
# if: runner.os == 'Windows'
47+
# run: |
48+
# python -m venv .venv
49+
# .\.venv\Scripts\Activate.ps1
50+
# .venv\Scripts\pip install pyodide-build
51+
# .venv\Scripts\pyodide venv .venv-pyodide
52+
# .venv-pyodide\Scripts\pip install -t src/vendor -r vendor.txt
53+
54+
- name: Test worker deployment
55+
run: wrangler deploy --dry-run
56+
57+
- name: Run tests (Linux/macOS)
58+
if: runner.os != 'Windows'
59+
run: |
60+
source .venv/bin/activate
61+
pip install -r requirements-test.txt
62+
pytest tests

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.venv/
2+
.venv-pyodide/
3+
.pytest_cache/
24
node_modules/
5+
__pycache__/
36
src/vendor/
4-
.vscode/
7+
.vscode/
8+
.wrangler/

README.md

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
# Vendoring Packages: FastAPI + Jinja2 Example
1+
# Python Workers: FastMCP Example
22

3-
*Note: You must have Python Packages enabled on your account for built-in packages to work. Request Access to our Closed Beta using [This Form](https://forms.gle/FcjjhV3YtPyjRPaL8)*
4-
5-
This is an example of a Python Worker that uses a built-in package (FastAPI) with a vendored package (Jinja2).
3+
This is an example of a Python Worker that uses the FastMCP package.
64

75
## Adding Packages
86

9-
Built-in packages can be selected from [this list](https://developers.cloudflare.com/workers/languages/python/packages/#supported-packages) and added to your `requirements.txt` file. These can be used with no other explicit install step.
10-
117
Vendored packages are added to your source files and need to be installed in a special manner. The Python Workers team plans to make this process automatic in the future, but for now, manual steps need to be taken.
128

139
### Vendoring Packages
1410

15-
[//]: # (NOTE: when updating the instructions below, be sure to also update the vendoring.yml CI workflow)
16-
1711
First, install Python3.12 and pip for Python 3.12.
1812

1913
*Currently, other versions of Python will not work - use 3.12!*
@@ -30,36 +24,22 @@ Within our virtual environment, install the pyodide CLI:
3024
.venv/bin/pyodide venv .venv-pyodide
3125
```
3226

33-
Next, add packages to your vendor.txt file. Here we'll add jinja2
34-
```
35-
jinja2
36-
```
37-
38-
Lastly, add these packages to your source files at `src/vendor`. For any additional packages, re-run this command.
27+
Lastly, download the vendored packages. For any additional packages, re-run this command.
3928
```console
4029
.venv-pyodide/bin/pip install -t src/vendor -r vendor.txt
4130
```
4231

43-
### Using Vendored packages
44-
45-
In your wrangler.toml, make the vendor directory available:
46-
47-
```toml
48-
[[rules]]
49-
globs = ["vendor/**"]
50-
type = "Data"
51-
fallthrough = true
52-
```
53-
54-
Now, you can import and use the packages:
55-
56-
```python
57-
import jinja2
58-
# ... etc ...
59-
```
60-
6132
### Developing and Deploying
6233

6334
To develop your Worker, run `npx wrangler@latest dev`.
6435

6536
To deploy your Worker, run `npx wrangler@latest deploy`.
37+
38+
### Testing
39+
40+
To test run:
41+
```console
42+
source .venv/bin/activate
43+
pip install -r requirements-test.txt
44+
pytest tests
45+
```

requirements-test.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest
2+
requests
3+
mcp
4+
pytest-asyncio

0 commit comments

Comments
 (0)