home / mcp / health api mcp server

Health API MCP Server

FastAPI health service with JWT auth, PostgreSQL, Alembic migrations, and MCP integration.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "alwayssany-health-api": {
      "url": "http://localhost:5000/mcp",
      "headers": {
        "Authorization": "Bearer <put_your_bearer_token_here>"
      }
    }
  }
}

This Health Microservice API MCP server provides a FastAPI-based backend for health-related operations, secured with JWT authentication and backed by PostgreSQL. It exposes a comprehensive set of REST endpoints for health entities and integrates with MCP to enable centralized, scalable client access across services.

How to use

After you have a running MCP-enabled health API, you can connect your MCP client to manage data and perform actions across doctors, patients, medical records, appointments, and related health services. Authenticate first to retrieve a JWT access token, then include the token in the Authorization header for subsequent requests. Use the interactive API docs (Swagger UI) to explore available endpoints, request bodies, and responses, and leverage MCP to streamline cross-service requests and secure access.

How to install

Prerequisites you need before installation:

  • Python 3.13.3 or newer
  • PostgreSQL server
  • UV package manager

How to install

Step by step install and run flow:

How to install

1) Install the UV package manager if not already present.

How to install

2) Install UV or use pip as an alternative.

How to install

3) Clone the project repository and navigate into the project directory.

How to install

4) Synchronize dependencies with UV.

How to install

5) Copy the example environment file and update credentials.

How to install

6) Create and migrate the database using Alembic migrations via UV.

How to install

7) Start the application using the recommended command.

How to install

# Install UV (example)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Or via pip
pip install uv

# Clone the project
git clone <repository-url>
cd health-api

# Install dependencies
uv sync

# Set up environment
cp .env.example .env
# Edit .env with your database credentials and secret key

# Prepare the database (PostgreSQL must be running)
CREATE DATABASE health_db;

# Generate and apply migrations
uv run alembic revision --autogenerate -m "Your migration message"
uv run alembic upgrade head

# Start the application
uv run uvicorn app.main:app --host 0.0.0.0 --port 5000 --reload

How to install

If you prefer a convenience script, you can use the provided startup script once you have dependencies installed.

Configuration and MCP integration

The MCP integration is used to connect this FastAPI application to an MCP server. The MCP client is wired into the FastAPI app using the FastApiMCP integration, and the MCP endpoint is exposed at the /mcp path for cross-service interactions.

MCP connection example

{
  "mcpServers": {
    "health_api": {
      "serverUrl": "http://localhost:5000/mcp",
      "headers": {
        "Authorization": "Bearer <put_your_bearer_token_here>"
      },
      "name": "health_api"
    }
  }
}

HTTP MCP connection details

If you are using a client that reads MCP configuration in JSON, you can configure the HTTP MCP server as shown above. Ensure the URL points to your running MCP endpoint and include the Authorization header with a valid token.

Security and access

Use JWT-based authentication for all protected endpoints. Register a user to obtain credentials, log in to receive a token, and attach the token to the Authorization header in subsequent requests.

Development notes

A modular project structure separates models, schemas, routes, and business logic for easier maintenance. Alembic handles database migrations, and the UV package manager enables fast dependency resolution during development.

API documentation

Once the application is running, you can access interactive API documentation to explore available endpoints, request bodies, and responses at the following paths: /docs and /redoc.

Troubleshooting

If you encounter connection issues, verify that the MCP server URL is accessible, the Authorization header contains a valid token, and the database is up and reachable. Review environment variables in the .env file to ensure database credentials and secret keys are correct.