health-api
A comprehensive FastAPI microservice for health-related operations,which is also powered by the MCP server (FastAPI to MCP)
Documentation
Health Microservice API
A comprehensive FastAPI microservice for health-related operations with JWT authentication, PostgreSQL database, and Alembic migrations.It is backed by MCP server using `FastApiMCP`
Working Demo
health-api-mcp-server-with-fastapi-demo.webm
Features
- JWT-based authentication
- PostgreSQL database with async SQLAlchemy
- Alembic database migrations
- Comprehensive health domain models (Patient, Doctor, Appointment, Medical Record)
- RESTful API endpoints
- Interactive API documentation (Swagger UI)
- Modular project structure
- CORS middleware
- Async/await support
- UV package manager for fast dependency resolution
- Comprehensive test suite
Prerequisites
- Python 3.13.3+
- PostgreSQL
- UV package manager
Project Structure
The project follows a modular structure suitable for large applications with clear separation of concerns between models, schemas, routes, and business logic.
Installation
Install UV
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Or with pip
pip install uvSetup Project
Clone the repository:
git clone
cd health-apiInstall dependencies:
uv syncSet up environment variables:
cp .env.example .env
# Edit .env with your database credentials and secret keyDatabase Migrations with Alembic (using UV)
Alembic is used for handling database migrations. All commands below assume you are in the project root directory.
But first off all create up a PostgreSQL database:
CREATE DATABASE health_db;Generate a New Migration (Autogenerate)
uv run alembic revision --autogenerate -m "Your migration message"Apply Migrations (Upgrade Database)
uv run alembic upgrade headStart the application (choose one):
uv run uvicorn app.main:app --host 0.0.0.0 --port 5000 --reload
# Or use the convenience script
chmod +x scripts/start.sh
./scripts/start.shSome more required alembic migration commands
These commands are not required during setup but are useful for managing migrations in the future
during development.
Downgrade Database (Revert Last Migration)
uv run alembic downgrade -1View Current Migration Status
uv run alembic currentShow Migration History
uv run alembic historyFor more Alembic commands and usage, see the Alembic documentation.
Development
Install development dependencies:
uv sync --group devRun tests:
uv run pytest
# Or use the test script
chmod +x scripts/test.sh
./scripts/test.shCode formatting:
uv run black app/ tests/
uv run isort app/ tests/Type checking:
uv run mypy app/Docker
Build and run with Docker Compose:
docker-compose up --buildThis will start both the PostgreSQL database and the FastAPI application.
API Documentation
Once the application is running, visit:
- Swagger UI: http://localhost:5000/docs
- ReDoc: http://localhost:5000/redoc
- MCP ping: check on terminal with the following command
curl -H "Authorization: Bearer "
-H "Accept: text/event-stream" http://localhost:5000/mcpDatabase Migrations
Create a new migration:
uv run alembic revision --autogenerate -m "Description of changes"
# Or use the migration script
chmod +x scripts/migrate.sh
./scripts/migrate.sh "Description of changes"Apply migrations:
uv run alembic upgrade headAuthentication
- Register a new user: `POST /auth/register`
- Login to get access token: `POST /auth/login`
- Use the token in Authorization header: `Bearer `
Main API Endpoints (after authentication)
After obtaining a JWT access token, you can access the following endpoints:
๐ผ๏ธ Click to see the Health Microservice API endpoints
Doctors
- `GET /doctors` โ List all doctors
- `GET /doctors/{doctor_id}` โ Get a specific doctor by ID
- `POST /doctors` โ Create a new doctor
- `PUT /doctors/{doctor_id}` โ Update a doctor's information
- `DELETE /doctors/{doctor_id}` โ Delete a doctor
Patients
- `GET /patients` โ List all patients
- `GET /patients/{patient_id}` โ Get a specific patient by ID
- `POST /patients` โ Create a new patient
- `PUT /patients/{patient_id}` โ Update a patient's information
- `DELETE /patients/{patient_id}` โ Delete a patient
Medical Records
- `GET /medical-records` โ List all medical records (optionally filter by patient)
- `GET /medical-records/{record_id}` โ Get a specific medical record by ID
- `POST /medical-records` โ Create a new medical record
- `PUT /medical-records/{record_id}` โ Update a medical record
- `DELETE /medical-records/{record_id}` โ Delete a medical record
Appointments
- `GET /appointments` โ List all appointments
- `GET /appointments/{appointment_id}` โ Get a specific appointment by ID
- `POST /appointments` โ Create a new appointment
- `PUT /appointments/{appointment_id}` โ Update an appointment
- `DELETE /appointments/{appointment_id}` โ Delete an appointment
Telemedicine
- `POST /telemedicine/visits/` โ Create a new virtual visit
- `GET /telemedicine/visits/` โ List all virtual visits
- `GET /telemedicine/visits/{visit_id}` โ Get a specific virtual visit by ID
- `POST /telemedicine/chats/` โ Create a new chat log
- `GET /telemedicine/chats/` โ List all chat logs
- `GET /telemedicine/chats/{chat_id}` โ Get a specific chat log by ID
- `POST /telemedicine/videos/` โ Create a new video session
- `GET /telemedicine/videos/` โ List all video sessions
- `GET /telemedicine/videos/{video_id}` โ Get a specific video session by ID
Lab
- `POST /lab/orders/` โ Create a new lab order
- `GET /lab/orders/` โ List all lab orders
- `GET /lab/orders/{order_id}` โ Get a specific lab order by ID
- `POST /lab/results/` โ Create a new lab result
- `GET /lab/results/` โ List all lab results
- `GET /lab/results/{result_id}` โ Get a specific lab result by ID
- `POST /lab/images/` โ Create a new diagnostic image
- `GET /lab/images/` โ List all diagnostic images
- `GET /lab/images/{image_id}` โ Get a specific diagnostic image by ID
Referral
- `POST /referral/requests/` โ Create a new referral request
- `GET /referral/requests/` โ List all referral requests
- `GET /referral/requests/{request_id}` โ Get a specific referral request by ID
- `POST /referral/statuses/` โ Create a new referral status
- `GET /referral/statuses/` โ List all referral statuses
- `GET /referral/statuses/{status_id}` โ Get a specific referral status by ID
- `POST /referral/notes/` โ Create a new specialist note
- `GET /referral/notes/` โ List all specialist notes
- `GET /referral/notes/{note_id}` โ Get a specific specialist note by ID
Pharmacy
- `POST /pharmacy/medications/` โ Create a new medication
- `GET /pharmacy/medications/` โ List all medications
- `GET /pharmacy/medications/{med_id}` โ Get a specific medication by ID
- `POST /pharmacy/prescriptions/` โ Create a new prescription
- `GET /pharmacy/prescriptions/` โ List all prescriptions
- `GET /pharmacy/prescriptions/{pres_id}` โ Get a specific prescription by ID
- `POST /pharmacy/orders/` โ Create a new pharmacy order
- `GET /pharmacy/orders/` โ List all pharmacy orders
- `GET /pharmacy/orders/{order_id}` โ Get a specific pharmacy order by ID
Insurance
- `POST /insurance/plans/` โ Create a new insurance plan
- `GET /insurance/plans/` โ List all insurance plans
- `GET /insurance/plans/{plan_id}` โ Get a specific insurance plan by ID
- `POST /insurance/claims/` โ Create a new insurance claim
- `GET /insurance/claims/` โ List all insurance claims
- `GET /insurance/claims/{claim_id}` โ Get a specific insurance claim by ID
- `POST /insurance/payments/` โ Create a new payment
- `GET /insurance/payments/` โ List all payments
- `GET /insurance/payments/{payment_id}` โ Get a specific payment by ID
- `POST /insurance/invoices/` โ Create a new invoice
- `GET /insurance/invoices/` โ List all invoices
- `GET /insurance/invoices/{invoice_id}` โ Get a specific invoice by ID
All these endpoints require the Authorization: Bearer header. Refer to the interactive API docs at /docs for detailed request/response schemas and try out the endpoints interactively.
Package Management with UV
UV provides fast dependency resolution and installation. Useful commands:
- `uv sync` - Install dependencies from lock file
- `uv add ` - Add a new dependency
- `uv remove ` - Remove a dependency
- `uv run ` - Run command in virtual environment
- `uv lock` - Update the lock file
MCP Integration
Integration with MCP is done by using the
`FastApiMCP` class from the `fastapi_mcp` package.
The MCP server is mounted to the FastAPI
application using the `mount` method.
`windsurf` settings,
{
"mcpServers": {
"health-api": {
"serverUrl": "http://localhost:5000/mcp",
"headers": {
"Authorization": "Bearer
"
}
}
}
}`vscode` or `cursor` settings,
{
"servers": {
"health-api": {
"url": "http://localhost:5000/mcp",
"headers": {
"Authorization": "Bearer
"
}
}
}
}Note: I haven't tested on `vscode` or `cursor` yet.
License
MIT License
TODOs
- [ ] Add more test cases
- [ ] Add more features
- [ ] Add more documentation
- [ ] Add more security features
- [ ] Add more logging
- [ ] Add more monitoring
- [ ] Add more performance optimization
Contributing
1. Install development dependencies: `uv sync
--group dev`
2. Make your changes
3. Run tests: `uv run pytest`
4. Format code: `uv run black app/ tests/`
5. Submit a pull request
See more at [Contributing](https://github.com/
AlwaysSany/health-api/blob/main/CONTRIBUTING.md).
Contact
- Author: Sany Ahmed
- Email: sany2k8@gmail.com
References
Frequently asked questions
What is health-api?
health-api is A comprehensive FastAPI microservice for health-related operations,which is also powered by the MCP server (FastAPI to MCP)
How do I install health-api?
Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.
Is health-api open source?
Yes โ it is hosted on GitHub at https://github.com/AlwaysSany/health-api and has 5 stars.
Related MCP tools
An AI Gateway, registry, and proxy that sits in front of any MCP, A2A, or REST/gRPC APIs, exposing a unified endpoint with centralized discovery, guardrails and management. Optimizes Agent & Tool calling, and supports plugins.
MCP server and Claude plugin for Postgres skills and documentation. Helps AI coding tools generate better PostgreSQL code.
AI-powered OSINT agent with interactive REPL, MCP server, and CLI. 19 tools. Works with Claude, GPT-4, or local models. For authorized security research only.
Production-grade MCP server giving Claude 27 security intelligence tools across 21 APIs โ CVE lookup, EPSS scoring, CISA KEV, MITRE ATT&CK, Shodan, VirusTotal, and more.
Open-source coding agent memory. Records issues, attempts, fixes and decisions, then warns your agent before it repeats an approach that already failed. Native MCP server for Claude Code, Cursor, Antigravity and Codex. 100% local, no cloud, no telemetry. MIT.
An LLM agent that conducts deep research (local and web) on any given topic and generates a long report with citations. Built for the Model Context Protocol to
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP