FastAPI + MCP + Nacos example with PDM
https://github.com/cxhello/nacos-fastapi-mcp-example.git
A reference FastAPI service that demonstrates how to integrate Nacos for configuration and service discovery together with the MCP (Model Context Protocol) ecosystem. The project is managed with PDM and targets Python 3.13.
src/utils).dev, start, lint, fmt, typecheck, test).app/ FastAPI entrypoints, Nacos integration, settings helper
src/utils/ Logging and trace helpers shared across the app
logs/ Local log output (ignored in Docker image)
.nacos-data/ Local Nacos snapshot storage (ignored in Docker image)
NACOS_SERVER_ADDR, NACOS_USERNAME, NACOS_NAMESPACE, ...)nacos-fastapi-mcp-example.yaml to the Nacos Config Service.nacos-fastapi-mcp-example.yamlDEFAULT_GROUPNACOS_NAMESPACE in your environmentcp .env.example .env
pdm install
pdm run dev
.env configuration):pdm run start
The application exposes:
GET /health โ lightweight health probe.GET /config/nacos โ current runtime configuration snapshot from Nacos.Dockerfile. Because .env is excluded by .dockerignore, pass it at runtime.
Build the image:
docker build -t nacos-fastapi-mcp-example:v0.1.0 .
Run the container (map ports and supply the .env file):
docker run -d \
--name nacos-fastapi-mcp-example \
--env-file .env \
-p 8000:8000 \
nacos-fastapi-mcp-example:v0.1.0
Adjust the port mapping if you expose a different APP_PORT.
.env.example enables Nacos registration; ensure the Nacos address and credentials are reachable, or toggle MCP_REGISTER_ENABLED/APP_WORKERS for local debugging.logs/ locally; mount a volume or override APP_LOG_PATH if you want to persist logs inside Docker.