Hospital MCP Server

Hospital MCP Server

Provides secure, read-only access to a PostgreSQL Hospital Management System through Claude Desktop. Enables querying doctor information, appointments, room status, and billing summaries using safe, parameterized queries.

Category
Visit Server

README

🏥 Hospital MCP Server

Secure PostgreSQL Access via Model Context Protocol (MCP)
Claude Desktop acts as the MCP client

This project implements a secure Model Context Protocol (MCP) server that connects to a PostgreSQL-based Hospital Management System.
Claude Desktop communicates with this server and can safely query hospital data through defined, read-only MCP tools.


📁 Project Structure


MY-FIRST-MCP-SERVER/
│
├── .venv/                # Virtual environment
├── .env                  # Environment variables (DB credentials)
├── .gitignore
├── .python-version
├── main.py               # MCP server implementation
├── pyproject.toml        # Project dependencies (uv/poetry/pdm)
├── README.md             # This documentation
└── uv.lock               # Dependency lockfile


🗄️ 1. PostgreSQL Setup

You must create secure read-only views before exposing data to Claude.

Create Views (Safe, non-sensitive)

CREATE VIEW doctors_view AS
SELECT doctor_id, department_id, specialization
FROM Doctors;

CREATE VIEW departments_view AS
SELECT department_id, name, head_doctor_id
FROM Departments;

CREATE VIEW public_appointments_view AS
SELECT appointment_id, patient_id, doctor_id, appointment_date
FROM Appointments;

CREATE VIEW rooms_view AS
SELECT room_id, room_number, current_status
FROM Rooms;

CREATE VIEW billing_summary_view AS
SELECT bill_id, patient_id, appointment_id, admission_id, total_amount
FROM Billing;

🔐 2. Create Restricted DB Role

CREATE ROLE mcp_readonly LOGIN PASSWORD 'your_password';

GRANT SELECT ON doctors_view TO mcp_readonly;
GRANT SELECT ON departments_view TO mcp_readonly;
GRANT SELECT ON public_appointments_view TO mcp_readonly;
GRANT SELECT ON rooms_view TO mcp_readonly;
GRANT SELECT ON billing_summary_view TO mcp_readonly;

REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM mcp_readonly;

ALTER ROLE mcp_readonly SET statement_timeout = '3s';
ALTER ROLE mcp_readonly SET idle_in_transaction_session_timeout = '2s';

Only the views are exposed — raw PHI tables are protected.


⚙️ 3. Environment Variables (.env)

Your MCP server reads DB credentials from here:

DB_HOST=localhost
DB_PORT=5432
DB_NAME=hospital_db
DB_USER=mcp_readonly
DB_PASSWORD=your_password

🧠 4. MCP Server (main.py)

main.py runs your MCP server and exposes tools such as:

  • get_doctor_by_id
  • list_doctors_by_department
  • get_appointments_for_doctor
  • check_room_status
  • get_patient_billing_summary

All SQL queries are:

✔ parameterized ✔ read-only ✔ safely constrained


🔌 5. Installing Dependencies

Inside your project folder:

uv sync

Or if using pip manually:

pip install -r requirements.txt

(Dependencies are defined in pyproject.toml)


🤝 6. Connecting MCP Server to Claude Desktop

Claude Desktop automatically detects MCP servers placed in its extensions directory.

In your local file system "C:\Users\shesh\AppData\Roaming\Claude\claude_desktop_config.json" edit this file with your configurations

{
  "mcpServers": {
    "postgres": {
      "command": "C:\\Users\\shesh\\my-first-mcp-server\\.venv\\Scripts\\python.exe",
      "args": [
        "C:\\Users\\shesh\\my-first-mcp-server\\main.py",
        "stdio"
      ],
      "cwd": "C:\\Users\\shesh\\my-first-mcp-server",
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "db_name",
        "DB_USER": "postgres",
        "DB_PASSWORD": "your_password"
      }
    }
  }
}

📍 Step 3 — Restart Claude Desktop

Go to:

Claude Desktop → Settings → Developer You should see:

hospital-mcp (running)

Claude will now:

  1. Launch your main.py MCP server
  2. Discover available tools
  3. Call them automatically during conversation

🧪 7. Testing Inside Claude

In Claude Desktop you can ask:

Get the list of doctors in the cardiology department.

Claude will call:

list_doctors_by_department(department_id=1)

Or:

Show me appointments for doctor 3.

Claude → calls your MCP tool → your DB → safe output returned.


🎯 Summary

You now have:

✔ A working Python MCP server ✔ Secure PostgreSQL integration ✔ Fully wired Claude Desktop tool access ✔ Safe read-only hospital data views ✔ Clean project structure

Claude Desktop communicates with your DB only through your safe MCP tools, never accessing raw tables directly.

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured