|
| 1 | +# PythonAnywhere Model Context Protocol Server |
| 2 | + |
| 3 | +A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) |
| 4 | +server acts as a bridge between AI-powered tools and your |
| 5 | +[PythonAnywhere](https://www.pythonanywhere.com/) account, enabling secure, |
| 6 | +programmatic management of files, websites, webapps, and scheduled tasks. By |
| 7 | +exposing a standardized interface, it allows language models and automation |
| 8 | +clients to perform operations—such as editing files, deploying web apps, or |
| 9 | +scheduling jobs—on your behalf, all while maintaining fine-grained control |
| 10 | +and auditability. |
| 11 | + |
| 12 | +## Features |
| 13 | +- **File management**: Read, upload, delete files and list directory trees. |
| 14 | + _(also enables debugging with direct access to log files, which are just |
| 15 | + files on PythonAnywhere)_ |
| 16 | +- **ASGI Web app management**: Create, delete, reload, and list. |
| 17 | + _(as described in the [PythonAnywhere ASGI |
| 18 | + documentation](https://help.pythonanywhere.com/pages/ASGICommandLine))_ |
| 19 | +- **WSGI Web app management**: Reload only _(at the moment)_. |
| 20 | +- **Scheduled task management**: List, create, update, and delete. |
| 21 | + _(Npote that it enables LLMs to execute arbitrary commands if a task is |
| 22 | + scheduled to soon after creation and deleted after execution. For that we |
| 23 | + would suggest running it with [mcp-server-time](https://pypi.org/project/mcp-server-time/) |
| 24 | + as models easily get confused about time.)_ |
| 25 | + |
| 26 | +## Installation |
| 27 | +MCP protocol is well-defined and supported by various clients, but |
| 28 | +installation is different depending on the client you are using. We will |
| 29 | +cover cases that we tried and tested. |
| 30 | + |
| 31 | +In all cases, you need to have `uv` installed and available in your `PATH`. |
| 32 | + |
| 33 | +Have your PythonAnywhere API token and username ready. You can find (or |
| 34 | +generate) your API token in the [API section of your PythonAnywhere |
| 35 | +account](https://www.pythonanywhere.com/account/#api_token). |
| 36 | + |
| 37 | +### Desktop Extension - works with Claude Desktop |
| 38 | +Probably the most straightforward way to install the MCP server is to use |
| 39 | +the [desktop extension](https://github.com/anthropics/dxt/) for Claude Desktop. |
| 40 | + |
| 41 | +1. Open Claude Desktop. |
| 42 | +2. **[Download the latest .dxt file](https://github.com/pythonanywhere/pythonanywhere-mcp-server/releases/latest/download/pythonanywhere-mcp-server.dxt)**. |
| 43 | +3. Double-click on the downloaded .dxt file or drag the file into the window. |
| 44 | +4. Configure your PythonAnywhere API token and username. |
| 45 | +5. Restart Claude Desktop. |
| 46 | + |
| 47 | +### Claude Code |
| 48 | +Run: |
| 49 | + ```bash |
| 50 | + claude mcp add pythonanywhere-mcp-server\ |
| 51 | + -e API_TOKEN=yourpythonanywhereapitoken\ |
| 52 | + -e LOGNAME=yourpythonanywhereusername\ |
| 53 | + -- uvx pythonanywhere-mcp-server |
| 54 | + ``` |
| 55 | + |
| 56 | +### GitHub Copilot in PyCharm: |
| 57 | +Add it to your `mcp.json`. |
| 58 | + |
| 59 | +```json |
| 60 | +{ |
| 61 | + "servers": { |
| 62 | + "pythonanywhere-mcp-server": { |
| 63 | + "type": "stdio", |
| 64 | + "command": "uvx", |
| 65 | + "args": ["pythonanywhere-mcp-server"], |
| 66 | + "env": { |
| 67 | + "API_TOKEN": "yourpythonanywhereapitoken", |
| 68 | + "LOGNAME": "yourpythonanywhereusername" |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### Claude Desktop (manual setup) and Cursor: |
| 76 | +Add it to `claude_desktop_config.json` (for Claude Desktop) or (`mcp.json` |
| 77 | +for Cursor). |
| 78 | + |
| 79 | +```json |
| 80 | +{ |
| 81 | + "mcpServers": { |
| 82 | + "pythonanywhere-mcp-server": { |
| 83 | + "type": "stdio", |
| 84 | + "command": "uvx", |
| 85 | + "args": ["pythonanywhere-mcp-server"], |
| 86 | + "env": { |
| 87 | + "API_TOKEN": "yourpythonanywhereapitoken", |
| 88 | + "LOGNAME": "yourpythonanywhereusername" |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Caveats |
| 96 | + |
| 97 | +Direct integration of an LLM with your PythonAnywhere account offers |
| 98 | +significant capabilities, but also introduces risks. We strongly advise |
| 99 | +maintaining human oversight, especially for sensitive actions such as |
| 100 | +modifying or deleting files. |
| 101 | + |
| 102 | +If you are running multiple MCP servers simultaneously, be |
| 103 | +cautious—particularly if any server can access external resources you do not |
| 104 | +control, such as GitHub issues. These can become attack vectors. For more |
| 105 | +details, see [this story](https://simonwillison.net/2025/Jul/6/supabase-mcp-lethal-trifecta/). |
| 106 | + |
| 107 | +## Implementation |
| 108 | + |
| 109 | +Server uses [python mcp sdk](https://github.com/modelcontextprotocol/python-sdk) |
| 110 | +in connection with [pythonanywhere-core](https://github.com/pythonanywhere/pythonanywhere-core) |
| 111 | +package ([docs](https://core.pythonanywhere.com/)) that wraps subset of [PythonAnywhere |
| 112 | +API](https://help.pythonanywhere.com/pages/API/) and would be expanded in |
| 113 | +the future as needed. |
0 commit comments