Supports containerized deployment with Docker and Docker Compose, including production and development configurations with volume mounting for development mode.
Supports environment variable management through .env files for configuring server settings across different environments.
Integrated as the main API server framework, providing automatic API documentation, type safety, and high performance features for the MCP server implementation.
Provides deployment support to Heroku cloud platform with instructions for app creation, environment variable configuration, and deployment via git.
Includes database integration capabilities with environment variable support for PostgreSQL connection configuration in production environments.
Utilizes pre-commit hooks for development workflow automation, ensuring code quality checks before committing changes.
Leverages Pydantic for data validation, settings management, and model definitions within the MCP server.
Provides comprehensive test coverage with pytest, including unit tests, integration tests, coverage reporting, and specialized test configurations.
Integrates Scalar for beautiful and interactive API documentation, enhancing the standard FastAPI documentation capabilities.
FastAPI + MCP Template
현대적인 API 서버와 MCP(Model Context Protocol) 통합 템플릿
FastAPI와 MCP를 활용한 프로덕션 수준의 API 서버 템플릿입니다. LLM 통합, 구조화된 로깅, 포괄적인 테스트, 그리고 최고의 개발자 경험을 제공합니다.
✨ 주요 특징
🚀 프로덕션 수준의 API 서버
- 현대적인 FastAPI: 자동 API 문서화, 타입 안전성, 고성능
- Scalar 문서화: 아름답고 대화형 API 문서
- 구조화된 로깅: 색상 지원, 파일 로테이션, 요청 추적
- 포괄적인 예외 처리: 타입별 커스텀 예외 및 상세한 오류 정보
- Dependency Injection: FastAPI DI 패턴으로 깔끔한 코드 구조
🤖 MCP 서버 통합
- FastMCP 구현: 최신 Model Context Protocol 표준
- SSE 통신: 실시간 Server-Sent Events 연결
- 도구 및 리소스: LLM이 활용할 수 있는 다양한 도구
- 확장 가능: 새로운 MCP 기능 쉽게 추가
🛡️ 보안 및 설정
- 환경별 설정: 개발, 테스트, 프로덕션 환경 지원
- 보안 기본값: 자동 시크릿 키 생성, CORS 보안 설정
- 환경변수 관리: .env 파일 지원 및 완전한 설정 검증
🧪 완전한 테스트 커버리지
- 단위 테스트: MCP 도구 및 API 엔드포인트
- 통합 테스트: 전체 시스템 엔드투엔드 테스트
- 동시성 테스트: 멀티스레드 및 성능 테스트
📁 프로젝트 구조
🚀 빠른 시작
1️⃣ 환경 설정
의존성 설치
환경변수 설정
.env
파일 주요 설정:
2️⃣ 서버 실행
🎯 통합 실행 (권장)
🔄 개별 실행
🐳 Docker 실행
3️⃣ 접속 확인
서비스 | URL | 설명 |
---|---|---|
🌐 API 서버 | http://localhost:8000 | 메인 API 엔드포인트 |
📚 API 문서 | http://localhost:8000/docs | 대화형 API 문서 (Scalar) |
❤️ 헬스체크 | http://localhost:8000/health | 서버 상태 확인 |
🤖 MCP 서버 | http://localhost:8001/sse | MCP SSE 엔드포인트 |
🛠️ 템플릿 커스터마이징
💡 빠른 설정
🆕 새 프로젝트 생성
🔄 백업에서 복원
📚 API 문서
🏥 헬스 체크
📦 아이템 관리
👥 사용자 관리
📖 API 사용 예시
아이템 생성
아이템 검색
🤖 MCP 서버 기능
🔨 사용 가능한 도구 (Tools)
도구명 | 설명 | 매개변수 |
---|---|---|
get_items | 아이템 목록 조회 | skip , limit , category , available_only |
get_item_by_id | ID로 아이템 조회 | item_id |
create_item | 새 아이템 생성 | name , price , description , etc. |
update_item | 아이템 수정 | item_id , 수정할 필드들 |
delete_item | 아이템 삭제 | item_id |
search_items | 아이템 검색 | query , search_field |
get_database_stats | 데이터베이스 통계 | 없음 |
export_database | 데이터 내보내기 | 없음 |
📦 사용 가능한 리소스 (Resources)
리소스 URI | 설명 |
---|---|
database://schema | 데이터베이스 스키마 정보 |
docs://api | API 문서 정보 |
data://items | 아이템 데이터 |
data://users | 사용자 데이터 |
🎯 MCP 사용 예시
MCP 클라이언트에서 도구 호출:
🧪 테스트
🏃 테스트 실행
📊 테스트 커버리지
- API 엔드포인트: 모든 CRUD 작업 및 오류 시나리오
- MCP 도구: 모든 도구 기능 및 오류 처리
- 통합 테스트: API ↔ MCP 데이터 일관성
- 동시성 테스트: 멀티스레드 환경에서의 안정성
- 시스템 한계 테스트: 대용량 데이터 및 극한 상황
🎯 테스트 예시
🚀 배포
🐳 Docker 배포
프로덕션 빌드
Docker Compose
☁️ 클라우드 배포
Heroku
AWS ECS / Azure Container Instances
📊 프로덕션 모니터링
환경변수 설정:
🔧 개발 가이드
📝 새 API 엔드포인트 추가
- 모델 정의 (
src/core/models.py
):
- 라우터 생성 (
src/api/routers/new_router.py
):
- 앱에 등록 (
src/api/app.py
):
🔨 새 MCP 도구 추가
- 도구 정의 (
src/mcp_server/tools.py
):
- 리소스 추가 (
src/mcp_server/resources.py
):
🧪 테스트 작성
- 단위 테스트:
- 통합 테스트:
📋 코딩 스타일
- 타입 힌트: 모든 함수에 타입 힌트 사용
- Docstring: Google 스타일 docstring 사용
- 로깅: 구조화된 로깅 (
logger.info()
,logger.error()
) - 예외 처리: 커스텀 예외 클래스 사용
- 의존성 주입: FastAPI Depends() 패턴 활용
🔍 문제 해결
🚨 일반적인 문제들
포트 충돌
환경변수 설정 오류
의존성 문제
로그 확인
🔧 디버깅 팁
- DEBUG 모드 활성화:
- 개발 서버에서 실행:
- MCP 서버 단독 테스트:
🤝 기여하기
🔄 기여 워크플로우
- Fork 저장소
- Feature 브랜치 생성:
git checkout -b feature/amazing-feature
- 커밋:
git commit -m 'Add amazing feature'
- 푸시:
git push origin feature/amazing-feature
- Pull Request 생성
📋 기여 가이드라인
- 코드 스타일: Black, isort, flake8 사용
- 테스트: 새 기능에 대한 테스트 추가
- 문서화: Docstring 및 README 업데이트
- 커밋 메시지: Conventional Commits 스타일 사용
🛠️ 개발 환경 설정
📄 라이선스
이 프로젝트는 MIT 라이선스 하에 배포됩니다.
🙏 감사의 말
- FastAPI - 현대적인 Python 웹 프레임워크
- FastMCP - Model Context Protocol 구현
- Pydantic - 데이터 검증 및 설정 관리
- UV - 빠른 Python 패키지 매니저
This server cannot be installed
Production-ready API server template integrating FastAPI with Model Context Protocol (MCP) for LLM integration, structured logging, and comprehensive testing.
Related MCP Servers
- -securityAlicense-qualityA high-performance FastAPI server supporting Model Context Protocol (MCP) for seamless integration with Large Language Models, featuring REST, GraphQL, and WebSocket APIs, along with real-time monitoring and vector search capabilities.Last updated -5PythonMIT License
- -securityFlicense-qualityA production-ready MCP server built with FastAPI, providing an enhanced tool registry for creating, managing, and documenting AI tools for Large Language Models (LLMs).Last updated -13Python
- -securityFlicense-qualityA simple application demonstrating Model Context Protocol (MCP) integration with FastAPI and Streamlit, allowing users to interact with LLMs through a clean interface.Last updated -3Python
- -securityAlicense-qualityA Model Context Protocol (MCP) server that implements AI-First Development framework principles, allowing LLMs to interact with context-first documentation tools and workflows for preserving knowledge and intent alongside code.Last updated -321PythonAGPL 3.0