trackmcp
Back to directory
AlwaysSany

health-api

View on GitHub

A comprehensive FastAPI microservice for health-related operations,which is also powered by the MCP server (FastAPI to MCP)

5 stars PythonOthers Updated Jan 8, 2026
alembicfastapimcpmcp-serverpostgresqlpydanticpythonfastmcpfastapimcpsqlalchemy

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.

project_structure

Installation

Install UV

bash
# 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 uv

Setup Project

Clone the repository:

bash
git clone 
cd health-api

Install dependencies:

bash
uv sync

Set up environment variables:

bash
cp .env.example .env
# Edit .env with your database credentials and secret key

Database 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:

sql
CREATE DATABASE health_db;

Generate a New Migration (Autogenerate)

bash
uv run alembic revision --autogenerate -m "Your migration message"

Apply Migrations (Upgrade Database)

bash
uv run alembic upgrade head

Start the application (choose one):

bash
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.sh

Some 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)

bash
uv run alembic downgrade -1

View Current Migration Status

bash
uv run alembic current

Show Migration History

bash
uv run alembic history

For more Alembic commands and usage, see the Alembic documentation.

Development

Install development dependencies:

bash
uv sync --group dev

Run tests:

bash
uv run pytest
# Or use the test script
chmod +x scripts/test.sh
./scripts/test.sh

Code formatting:

bash
uv run black app/ tests/
uv run isort app/ tests/

Type checking:

bash
uv run mypy app/

Docker

Build and run with Docker Compose:

bash
docker-compose up --build

This 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
bash
curl -H "Authorization: Bearer " 
-H "Accept: text/event-stream" http://localhost:5000/mcp

Database Migrations

Create a new migration:

bash
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:

bash
uv run alembic upgrade head

Authentication

  • 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:

Health-Microservice-API-Swagger-UI

๐Ÿ–ผ๏ธ 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,

json
{
  "mcpServers": {
    "health-api": {
      "serverUrl": "http://localhost:5000/mcp",
      "headers": {
        "Authorization": "Bearer 
        "
      } 
    }
  }
}

`vscode` or `cursor` settings,

json
{
  "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

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

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP