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.
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_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 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:
- Launch your
main.pyMCP server - Discover 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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。