About Python Workers: FastMCP Example
Python Workers: FastMCP Example is an example Python Worker using FastMCP. It shows package vendoring, local development, deployment, testing, and linting workflows.
Key features
- 01FastMCP-based Python Worker example
- 02Vendor packages into source files
- 03Develop with Wrangler
- 04Deploy with Wrangler
- 05Test with pytest and format with Ruff
Use cases
- 01Learn how to package dependencies for Python Workers
- 02Develop and deploy a Worker with Wrangler
- 03Run tests and linting for the example
MCP support
The example uses FastMCP, but the README does not specify what MCP tools or resources the Worker exposes.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEPython Workers: FastMCP Example
This is an example of a Python Worker that uses the FastMCP package.
Note
Due to the size of the Worker, this example can only be deployed if you're using the Workers Paid plan. Free plan users will encounter deployment errors because this Worker exceeds the 3MB size limit.
Adding Packages
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.
Vendoring Packages
First, install Python3.12 and pip for Python 3.12.
Currently, other versions of Python will not work - use 3.12!
Then create a virtual environment and activate it from your shell:
python3.12 -m venv .venv
source .venv/bin/activate
Within our virtual environment, install the pyodide CLI:
.venv/bin/pip install pyodide-build
.venv/bin/pyodide venv .venv-pyodide
Lastly, download the vendored packages. For any additional packages, re-run this command.
.venv-pyodide/bin/pip install -t src/vendor -r vendor.txt
Developing and Deploying
To develop your Worker, run npx wrangler@latest dev.
To deploy your Worker, run npx wrangler@latest deploy.
Testing
To test run:
source .venv/bin/activate
pip install -r requirements-test.txt
pytest tests
Linting and Formatting
This project uses Ruff for linting and formatting:
pip install ruff
ruff check . # Run linting
ruff format . # Format code
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.