Fresh docker compose up -d --build produces a container that crash-loops on startup.
File "/app/hamroh/mcp_server.py", line 27, in <module>
from mcp.server.fastmcp import FastMCP
File "/app/.venv/lib/python3.11/site-packages/mcp/server/fastmcp.py", line 16, in <module>
raise ModuleNotFoundError(_MESSAGE, name=__name__)
ModuleNotFoundError: No module named 'mcp.server.fastmcp'. This is mcp 2.x, where FastMCP was
renamed to MCPServer (from mcp.server.mcpserver import MCPServer)
The container restarts forever; docker compose ps shows restarting.
Root cause
pyproject.toml declares an unbounded lower bound:
dependencies = [
"mcp>=1.2.0",
uv.lock pins the working version:
name = "mcp"
version = "1.27.0"
but the Dockerfile installs with
RUN uv venv /app/.venv && \
uv pip install --python /app/.venv/bin/python . --no-cache-dir
uv pip install . resolves from pyproject.toml and ignores uv.lock, so any build after mcp 2.x
was published picks up 2.x, where FastMCP was renamed to MCPServer. Builds from before the 2.x
release are unaffected, which is why this appears as a sudden breakage with no code change.
Fix
Either pin the major in pyproject.toml:
or make the image honour the lockfile (uv sync --frozen), which also pins every other unbounded
dependency and makes builds reproducible.
I patched locally with the <2 pin and both of my deployments build and run fine:
INFO hamroh.mcp_server MCP server listening on http://127.0.0.1:36731/mcp
INFO hamroh hamroh is live
Environment
- Ubuntu 22.04, aarch64 (OCI Ampere A1)
- Docker 29.5.2, Compose v5.1.4
- hamroh at current
main, built from a clean clone
Fresh
docker compose up -d --buildproduces a container that crash-loops on startup.The container restarts forever;
docker compose psshowsrestarting.Root cause
pyproject.tomldeclares an unbounded lower bound:uv.lockpins the working version:but the Dockerfile installs with
RUN uv venv /app/.venv && \ uv pip install --python /app/.venv/bin/python . --no-cache-diruv pip install .resolves frompyproject.tomland ignoresuv.lock, so any build after mcp 2.xwas published picks up 2.x, where
FastMCPwas renamed toMCPServer. Builds from before the 2.xrelease are unaffected, which is why this appears as a sudden breakage with no code change.
Fix
Either pin the major in
pyproject.toml:"mcp>=1.2.0,<2",or make the image honour the lockfile (
uv sync --frozen), which also pins every other unboundeddependency and makes builds reproducible.
I patched locally with the
<2pin and both of my deployments build and run fine:Environment
main, built from a clean clone