Skip to content

Commit 3c622be

Browse files
Adds client identification.
1 parent dd025bc commit 3c622be

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

.github/workflows/release.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,32 @@ jobs:
2525
- name: Install uv
2626
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
2727

28-
- name: Check tag matches pyproject.toml version
28+
- name: Check tag matches version files
2929
run: |
3030
TAG_VERSION="${GITHUB_REF##*/}"
3131
TAG_VERSION_NO_PREFIX="${TAG_VERSION#v}"
3232
echo "Tag version: $TAG_VERSION (stripped: $TAG_VERSION_NO_PREFIX)"
33+
3334
PYPROJECT_VERSION=$(grep '^version =' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
3435
echo "pyproject.toml version: $PYPROJECT_VERSION"
36+
37+
INIT_VERSION=$(grep '^__version__ =' src/pythonanywhere_mcp_server/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
38+
echo "__init__.py version: $INIT_VERSION"
39+
3540
if [ "$TAG_VERSION_NO_PREFIX" != "$PYPROJECT_VERSION" ]; then
3641
echo "Tag version ($TAG_VERSION_NO_PREFIX) does not match pyproject.toml version ($PYPROJECT_VERSION)" >&2
3742
exit 1
3843
fi
44+
45+
if [ "$TAG_VERSION_NO_PREFIX" != "$INIT_VERSION" ]; then
46+
echo "Tag version ($TAG_VERSION_NO_PREFIX) does not match __init__.py version ($INIT_VERSION)" >&2
47+
exit 1
48+
fi
49+
50+
if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then
51+
echo "pyproject.toml version ($PYPROJECT_VERSION) does not match __init__.py version ($INIT_VERSION)" >&2
52+
exit 1
53+
fi
3954
shell: bash
4055

4156
- name: Build package

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pythonanywhere-mcp-server"
7-
version = "0.0.6"
7+
version = "0.0.7"
88
description = "PythonAnywhere Model Context Protocol Server"
99
authors = [
1010
{name = "PythonAnywhere Developers", email = "[email protected]"}
1111
]
1212
readme = "README.md"
1313
requires-python = ">=3.13"
1414
dependencies = [
15-
"pythonanywhere-core",
15+
"pythonanywhere-core>=0.2.9",
1616
"mcp[cli]",
1717
]
1818
classifiers = [
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.7"

src/pythonanywhere_mcp_server/server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
from mcp.server.fastmcp import FastMCP
4+
from . import __version__
45
from .tools.file import register_file_tools
56
from .tools.webapp import register_webapp_tools
67
from .tools.website import register_website_tools
@@ -9,6 +10,9 @@
910

1011
def create_server():
1112
"""Create the MCP server."""
13+
# Set client identifier for API analytics
14+
os.environ["PYTHONANYWHERE_CLIENT"] = f"mcp-server/{__version__}"
15+
1216
API_TOKEN = os.getenv("API_TOKEN")
1317
if not API_TOKEN:
1418
raise RuntimeError("API_TOKEN environment variable must be set.")

src/pythonanywhere_mcp_server/tools/webapp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pythonanywhere_core.webapp import Webapp
66
from pythonanywhere_core.base import AuthenticationError, NoTokenError
7+
from pythonanywhere_core.exceptions import MissingCNAMEException
78

89
# ToDo: Add the log file functions once pythonanywhere-core webapp log file functions
910
# have been improved
@@ -28,6 +29,8 @@ def reload_webapp(domain: str) -> str:
2829
try:
2930
Webapp(domain).reload()
3031
return f"Webapp '{domain}' reloaded."
32+
except MissingCNAMEException as exc:
33+
return f"Webapp '{domain}' reloaded. Note: {str(exc)}"
3134
except (AuthenticationError, NoTokenError):
3235
raise RuntimeError("Authentication failed — check API_TOKEN and domain.")
3336
except Exception as exc:

tests/test_webapp_tools.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
from pathlib import Path
33
from pythonanywhere_core.base import AuthenticationError
4+
from pythonanywhere_core.exceptions import MissingCNAMEException
45

56
import tools.webapp as webapp_tools
67

@@ -118,3 +119,13 @@ def test_list_webapps(setup_webapp_tools, mocker):
118119
mocker.patch("tools.webapp.Webapp.list_webapps", return_value=expected)
119120
result = setup_webapp_tools.call_tool("list_webapps", {})
120121
assert result == expected
122+
123+
124+
def test_reload_webapp_handles_missing_cname_exception(setup_webapp_tools, mocker):
125+
mock_webapp = mocker.patch("tools.webapp.Webapp", autospec=True)
126+
mock_webapp.return_value.reload.side_effect = MissingCNAMEException()
127+
128+
result = setup_webapp_tools.call_tool("reload_webapp", {"domain": "test.com"})
129+
130+
assert "Webapp 'test.com' reloaded" in result
131+
assert "CNAME" in result or "cname" in result

uv.lock

Lines changed: 6 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)