FastAPI MCP Server
A sample FastAPI project that implements the Model Context Protocol (MCP), allowing AI assistants to connect to a PostgreSQL database and manage notes through natural language interactions.
README
FastAPI Sample Project
간단한 FastAPI 샘플 프로젝트입니다.
설치
필요한 패키지들을 설치하세요:
pip install -r requirements.txt
실행
로컬 실행
서버를 실행하려면:
# 방법 1: uvicorn 직접 사용
uvicorn main:app --reload
# 방법 2: Python 스크립트 실행
python main.py
Docker를 사용한 실행 (권장)
Docker를 사용하여 FastAPI 애플리케이션을 실행 (외부 PostgreSQL 데이터베이스 연결):
사전 준비
- 프로젝트 루트에
.env파일을 생성하고 PostgreSQL 연결 정보를 입력하세요:
POSTGRES_URL=your_postgresql_url
POSTGRES_URL_NON_POOLING=your_postgresql_url_non_pooling
POSTGRES_USER=your_username
POSTGRES_HOST=your_host
POSTGRES_PASSWORD=your_password
POSTGRES_DATABASE=your_database
POSTGRES_URL_NO_SSL=your_postgresql_url_no_ssl
POSTGRES_PRISMA_URL=your_prisma_url
스크립트 사용 (권장)
# 스크립트 설정 (최초 1회)
chmod +x scripts/*.sh
# 서비스 시작
./scripts/start.sh
# 로그 확인
./scripts/logs.sh
# 서비스 중지
./scripts/stop.sh
# 완전 정리
./scripts/clean.sh
직접 명령어 사용
# FastAPI 서비스 시작
docker-compose up -d
# 로그 확인
docker-compose logs -f app
# 서비스 중지
docker-compose down
서버가 실행되면 다음 URL에서 접근할 수 있습니다:
- API 서버: http://localhost:8000
- API 문서: http://localhost:8000/docs
- ReDoc 문서: http://localhost:8000/redoc
- MCP 서버: http://localhost:8000/mcp
API 엔드포인트
기본 엔드포인트
GET /: API 문서로 리다이렉트GET /health: API 상태 확인
데이터베이스 엔드포인트
GET /db/test-connection: 데이터베이스 연결 테스트GET /db/config: 데이터베이스 설정 정보 확인 (비밀번호는 가려짐)GET /db/tables: 데이터베이스의 모든 테이블 목록 조회GET /db/table/{table_name}: 특정 테이블의 구조 정보 조회GET /db/table/{table_name}/data: 특정 테이블의 데이터 조회 (limit, offset 파라미터 지원)
노트 관리 엔드포인트 (MCP 통합)
POST /notes: 새로운 노트 생성 (사용자가 "노트" 언급 시 사용)GET /notes: 모든 노트 조회 (페이징 지원)GET /notes/{note_id}: 특정 노트 조회DELETE /notes/{note_id}: 특정 노트 삭제
MCP (Model Context Protocol) 사용법
이 프로젝트는 FastAPI MCP를 통합하여 MCP 클라이언트와 연결할 수 있습니다.
MCP 클라이언트 연결
SSE를 사용한 연결
가장 인기 있는 MCP 클라이언트(Claude Desktop, Cursor & Windsurf)는 다음 설정을 사용합니다:
{
"mcpServers": {
"fastapi-mcp": {
"url": "http://localhost:8000/mcp"
}
}
}
mcp-remote를 사용한 연결
인증이나 SSE를 지원하지 않는 MCP 클라이언트의 경우 mcp-remote를 브리지로 사용할 수 있습니다:
{
"mcpServers": {
"fastapi-mcp": {
"url": "https://mcp-rosy.vercel.app/mcp"
}
}
}
MCP 서버 접근
- MCP 서버는
http://localhost:8000/mcp에서 실행됩니다 - FastAPI 애플리케이션과 함께 자동으로 시작됩니다
개발
이 프로젝트는 FastAPI 프레임워크를 사용하여 구축되었습니다. 자동으로 생성되는 API 문서를 통해 엔드포인트를 테스트할 수 있습니다.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.