I'm using a Docker container based on node:20-alpine and running Python 3.13 inside it. I installed my Python packages using uv pip install mcp==1.6.0.
When I try to run this import:
from mcp.server import NotificationOptions, Server
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/standalone/.venv/lib/python3.11/site-packages/mcp/__init__.py", line 1, in <module>
from .client.session import ClientSession
...
File "/app/standalone/.venv/lib/python3.11/site-packages/pydantic_core/__init__.py", line 6, in <module>
from ._pydantic_core import (
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'
But I already have pydantic-core installed, as shown in uv pip freeze:
pydantic==2.11.3
pydantic-core==2.33.1
Does anyone know why this is happening or how to fix it?
EDIT (Added debugging information)
This issue can be reproduced using the following Dockerfile:
FROM node:20-alpine
# Install basic deps
RUN apk add --no-cache curl
# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:${PATH}"
WORKDIR /app
# Create a Python 3.11 virtual environment
RUN uv venv --python=3.11 && \
uv pip install mcp
# Install the MCP server
# Add test file
COPY test_mcp.py .
# Run the test
CMD ["uv", "run", "test_mcp.py"]
test_mcp.py:
from mcp.server import NotificationOptions, Server
Then build and run the container:
docker build -t mcp-test .
docker run mcp-test`
This will result in the same error:
Traceback (most recent call last):
File "/app/test_mcp.py", line 1, in <module>
from mcp.server import NotificationOptions, Server
File "/app/.venv/lib/python3.11/site-packages/mcp/__init__.py", line 1, in <module>
from .client.session import ClientSession
File "/app/.venv/lib/python3.11/site-packages/mcp/client/session.py", line 6, in <module>
from pydantic import AnyUrl, TypeAdapter
File "/app/.venv/lib/python3.11/site-packages/pydantic/__init__.py", line 5, in <module>
from ._migration import getattr_migration
File "/app/.venv/lib/python3.11/site-packages/pydantic/_migration.py", line 4, in <module>
from .version import version_short
File "/app/.venv/lib/python3.11/site-packages/pydantic/version.py", line 5, in <module>
from pydantic_core import __version__ as __pydantic_core_version__
File "/app/.venv/lib/python3.11/site-packages/pydantic_core/__init__.py", line 6, in <module>
from ._pydantic_core import (
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'
Despite pydantic_core being installed as shown by:
uv pip freeze Output:
pydantic==2.11.3
pydantic-core==2.33.1
This error happens because Python versions < 3.13 don’t properly infer the extension suffix for compiled libraries like pydantic-core.
The fix is to use Python 3.13 or later (see python/cpython#95855).