hospital-ai-secure-assistant
Role-based AI assistant for hospital workflows, patient FAQ, staff tools, and secure document approvals with MCP-style tool access.
README
Hospital AI System
A simulated enterprise healthcare backend and UI for testing role-based AI assistants, hospital workflows, secure document approvals, prompt-injection defenses, and MCP-style tool access.
The project includes:
- FastAPI backend
- SQLite demo database
- Role-based JWT authentication
- Patient, staff, and management chat surfaces
- Public patient FAQ mode before login
- Secure Document Vault for approved confidential supervisor documents
- MCP-style tool listing and invocation endpoints
- Mock AI mode for local demos without external AI keys
1. Quick Setup
Run this from the project root on Windows PowerShell:
.\setup.ps1
The script will:
- create
.venvif it does not exist - install Python dependencies
- create
.envif missing - generate
hospital.dbif missing - create
secure_vault/if missing
To recreate demo data from scratch:
.\setup.ps1 -ResetDb
To setup and start the server immediately:
.\setup.ps1 -StartServer
If PowerShell blocks script execution, run:
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Then rerun:
.\setup.ps1
2. Manual Setup
If you do not want to use the setup script:
python -m venv .venv
.\.venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txt
python generate_hospital_data.py
Create .env:
HOSPITAL_AI_PROVIDER=mock
JWT_SECRET=hospital-dev-secret
REPORT_GENERATION_DELAY_SECONDS=0
3. Run Locally
Start the app:
.\.venv\Scripts\python.exe -m uvicorn app:app --host 127.0.0.1 --port 8000
Open:
- Main dashboard:
http://127.0.0.1:8000/ - Patient chat:
http://127.0.0.1:8000/patient - Staff chat:
http://127.0.0.1:8000/staff - Management chat:
http://127.0.0.1:8000/management - Secure Document Vault:
http://127.0.0.1:8000/vault - Swagger API docs:
http://127.0.0.1:8000/docs - Health/status:
http://127.0.0.1:8000/api/status
4. Run With Ngrok
Install ngrok, then start your local server first:
.\.venv\Scripts\python.exe -m uvicorn app:app --host 127.0.0.1 --port 8000
In another terminal:
ngrok http 8000
Ngrok will print a public URL like:
https://example-name.ngrok-free.dev
Share these with testers:
https://example-name.ngrok-free.dev/patienthttps://example-name.ngrok-free.dev/staffhttps://example-name.ngrok-free.dev/managementhttps://example-name.ngrok-free.dev/vaulthttps://example-name.ngrok-free.dev/docs
If you use a fixed ngrok domain, point it to the same local port your FastAPI app is running on.
To inspect active ngrok tunnels locally:
Invoke-RestMethod http://127.0.0.1:4040/api/tunnels
5. Demo Accounts
| Username | Password | Role |
|---|---|---|
admin |
Admin@123 |
SUPER_ADMIN |
supervisor1 |
Supervisor@123 |
HOSPITAL_SUPERVISOR |
doctor1 |
Doctor@123 |
DOCTOR |
doctor2 |
Doctor@123 |
DOCTOR |
doctor3 |
Doctor@123 |
DOCTOR |
nurse1 |
Nurse@123 |
NURSE |
labtech1 |
LabTech@123 |
LAB_TECH |
receptionist1 |
Reception@123 |
RECEPTIONIST |
billing1 |
Billing@123 |
BILLING_INSURANCE |
patient1 |
Patient@123 |
PATIENT |
patient2 |
Patient@123 |
PATIENT |
6. Chat Surfaces
Patient Chat
URL:
/patient
API:
POST /chat/patient
Behavior:
- Without login: public hospital FAQ mode
- With
PATIENTlogin: private patient mode
Public mode can answer general questions about:
- services
- appointment process
- lab services
- billing support
- emergency guidance
- medical-record request process
Public mode cannot reveal:
- patient profile
- medical records
- lab reports
- billing records
- prescriptions
- insurance claims
- appointment status
Staff Chat
URL:
/staff
API:
POST /chat/staff
Requires one of:
DOCTORNURSELAB_TECHRECEPTIONISTBILLING_INSURANCE
Each staff role only sees tools allowed for that role.
Management Chat
URL:
/management
API:
POST /chat/management
Requires:
SUPER_ADMINHOSPITAL_SUPERVISOR
Management role split:
- Supervisor creates secure document requests and checks own request status.
- Admin approves/rejects document requests and views pending queue.
- Admin does not create supervisor document requests.
- Supervisor does not approve requests.
7. Secure Document Vault
URL:
/vault
APIs:
GET /vault/docs
GET /vault/docs/{request_id}
Allowed roles:
SUPER_ADMINHOSPITAL_SUPERVISOR
Denied roles:
PATIENTDOCTORNURSELAB_TECHRECEPTIONISTBILLING_INSURANCE
Vault behavior:
- Supervisor creates confidential document requests from management chat.
- The generated document content is stored in
secure_vault/. - Chat never displays confidential document content.
- Request stays
PENDING_ADMIN_APPROVAL. - Admin approves/rejects.
- After approval, supervisor signs into
/vaultagain to view their own approved docs. - Admin signs into
/vaultto view all approved docs.
8. API Endpoints
| Method | Endpoint | Auth | Description |
|---|---|---|---|
GET |
/ |
No | Main UI |
GET |
/patient |
No | Patient UI |
GET |
/staff |
No page auth, chat requires JWT | Staff UI |
GET |
/management |
No page auth, chat requires JWT | Management UI |
GET |
/vault |
No page auth, vault APIs require JWT | Secure Document Vault UI |
GET |
/docs |
No | Swagger/OpenAPI docs |
GET |
/api/status |
No | Service status |
POST |
/auth/login |
No | Login and receive JWT |
POST |
/chat/patient |
Optional | Public patient FAQ or signed-in patient chat |
POST |
/chat/staff |
Yes | Staff chat |
POST |
/chat/management |
Yes | Management chat |
GET |
/mcp/health |
No | MCP health |
GET |
/mcp/tools |
Yes | List tools available to signed-in role |
POST |
/mcp/invoke |
Yes | Invoke a tool directly |
GET |
/mcp/sse |
Yes/token query | MCP SSE stream |
POST |
/mcp/sse/message |
Yes/token query | MCP SSE message endpoint |
GET |
/vault/docs |
Yes | List approved vault docs |
GET |
/vault/docs/{request_id} |
Yes | Read approved vault doc |
9. Database
Main SQLite database:
hospital.db
Generated by:
python generate_hospital_data.py
Important tables include:
usershospital_staffdoctorspatientsappointmentsmedical_recordsprescriptionslab_reportsbillinginsurancehospital_documentsaudit_logsmanagement_report_requests
management_report_requests stores metadata for secure document requests. The confidential document body is stored in secure_vault/.
10. Security Model
- JWT authentication
- Role-based access control
- Patient self-access isolation
- Staff tools limited by role
- Supervisor creates confidential document requests
- Admin approves/rejects confidential document requests
- Vault requires separate sign-in
- Vault content is not served from
/static - Chat does not display confidential vault document bodies
- Prompt filtering blocks obvious prompt-injection attempts
- Audit logs record tool execution attempts
11. Recommended Demo Flow
-
Open
/patient. -
Ask public question without login:
What services does the hospital provide? -
Sign in as
patient1. -
Ask:
Show my lab reports -
Open
/management. -
Sign in as
supervisor1. -
Ask:
Create lab reports document for patient 1 -
Sign out/refresh or login as
admin. -
Ask:
Show pending document requests Approve document request 1 -
Open
/vault. -
Sign in as
supervisor1to see own approved docs. -
Sign in as
adminto see all approved docs.
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.