home / mcp / fastapi mcp server
FastAPI + MCP 프로덕션 템플릿 - 현대적인 API 서버와 LLM 통합을 위한 완전한 개발 템플릿
Configuration
View docs{
"mcpServers": {
"joonheeu-fastapi-mcp-template": {
"url": "http://localhost:8001/sse",
"headers": {
"APP_NAME": "My Awesome API",
"LOG_FILE": "logs/app.log",
"LOG_LEVEL": "INFO",
"SECRET_KEY": "your-secure-random-key-here",
"ENVIRONMENT": "development",
"CORS_ORIGINS": "http://localhost:3000,http://localhost:8080"
}
}
}
}You run a modern API server that integrates FastAPI with MCP (Model Context Protocol), enabling structured tool usage, real-time MCP communication via SSE, and robust testing. This server pattern lets you expose API endpoints alongside MCP tools and resources, so an LLM or client can orchestrate data operations, query the database, and invoke domain-specific actions all through a unified interface.
Use an MCP client to interact with the FastAPI + MCP server. You can call MCP tools to perform domain actions, access MCP resources to read shared data, and subscribe to real-time updates via SSE. The API routes expose standard REST endpoints for your application data, while MCP endpoints provide tool invocation and resource access that an LLM or automation client can drive.
Prerequisites: you need Python installed on your system and a compatible package manager (UV is recommended for fast Python packaging). You may also want Docker if you plan to run containers.
Install dependencies using UV or your preferred Python package manager.
Set up environment variables to configure your environment, security, logging, and CORS as appropriate for development, testing, or production.
Run the integrated server or individual components using the commands shown below.
# Prerequisites: ensure Python is installed
# Install UV package manager and install dependencies
uv sync
# Or, using Python/pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Copy and customize environment variables
cp .env.example .envConfigure environment-specific settings for development, testing, and production. Enable secure defaults, automatic secret key generation, and CORS restrictions suitable for your deployment. Use a .env file for local development and a secure secret management approach in production.
Environment variables you commonly configure include app name, environment mode, secret keys, CORS origins for development, and logging options.
If you encounter port conflicts, verify which processes are bound to the ports you plan to use and terminate any conflicting processes. Check logs for errors, verify environment variables, and re-run the server with debugging enabled to isolate issues.
For debugging, enable verbose logging and run the development server in a hot-reload mode to iterate quickly.
You can access the API documentation, health checks, and the MCP SSE endpoint once the server is running. Typical endpoints include health checks and item or user management routes, while MCP endpoints expose tool calls and resources for integration with LLM clients.
Retrieve a paginated list of items with optional filters such as category and availability.
Fetch a single item by its identifier.
Create a new item with fields like name, price, description, and category.
Update fields of an existing item identified by its ID.
Delete an item by its ID.
Search items by a query against specified fields.
Return statistics about the database usage and state.
Export database data for backup or migration.