Provides secure read-only access to a PostgreSQL-based Hospital Management System through defined views, enabling queries for doctors, departments, appointments, room status, and billing summaries while protecting sensitive patient health information.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Hospital MCP Servershow me appointments for Dr. Smith tomorrow"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
π₯ 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_idlist_doctors_by_departmentget_appointments_for_doctorcheck_room_statusget_patient_billing_summary
All SQL queries are:
β parameterized β read-only β safely constrained
π 5. Installing Dependencies
Inside your project folder:
uv syncOr 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:
Launch your
main.pyMCP serverDiscover available tools
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.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.