A production-quality clinical decision-support MCP server for analyzing hormone reports and providing personalized PCOS management recommendations.
The PCOS Health Assistant is a Model Context Protocol (MCP) server that:
- Imports reference data – Loads menstrual cycle patterns from CSV datasets
- Extracts lab values – Parses hormone reports (PDFs) to extract medically relevant markers
- Analyzes findings – Compares extracted values against reference patterns and identifies abnormalities
- Recommends plans – Suggests personalized diet and exercise recommendations
- Generates reports – Creates professional downloadable reports with all findings and recommendations
- Cleans up – Securely deletes temporary files to protect patient privacy
✅ No patient data stored – All uploaded PDFs and extracted values are temporary
✅ No identifiers – Reference datasets contain only medical metrics, no participant IDs
✅ Automatic cleanup – Temporary files deleted after processing
✅ Clinical decision support only – Not a diagnostic tool; requires healthcare provider review
src/
├── app.module.ts # Root module, registers PCOSModule
├── index.ts # MCP server entry point
├── mongodb.ts # MongoDB connection & collection initialization
├── pcos/
│ └── pcos.module.ts # PCOS feature module
├── tools/
│ ├── importCycleDataset.ts # Tool 1: Import CSV reference data
│ ├── extractLabReport.ts # Tool 2: Extract lab values from PDF
│ ├── analyzePCOS.ts # Tool 3: Analyze findings & recommend plans
│ ├── generateReport.ts # Tool 4: Generate downloadable report
│ └── clearTemporaryFiles.ts # Tool 5: Delete temporary files
└── utils/
├── csv.ts # CSV parsing & filtering
├── pdf.ts # PDF extraction & validation
└── similarity.ts # Pattern matching & scoring
data/
├── datasets/
│ └── FedCycleData071012.csv # Reference menstrual cycle data
├── uploads/ # Temporary uploaded PDFs (auto-cleaned)
└── generated_reports/ # Generated report files
All collections contain reference data only (no patient information):
- cycle_patterns – Menstrual cycle metrics (FSH/LH ratio, testosterone, cycle length, etc.)
- diet_plans – Nutrition recommendations keyed by phenotype/hormone profile
- exercise_plans – Fitness recommendations keyed by fitness level and cycle phase
- pcos_guidelines – Clinical explanations for identified findings
Purpose: Load reference menstrual cycle data from CSV
Input: File path (optional; defaults to data/datasets/FedCycleData071012.csv)
Output: Import statistics (records imported, duplicates skipped)
Privacy: Filters out participant identifiers; keeps only medical metrics
Input: { filePath: "data/datasets/FedCycleData071012.csv" }
Output: { status: "success", imported: 10, duplicates: 0, total_processed: 10 }
Purpose: Extract lab values from uploaded hormone report PDF
Input: Base64-encoded PDF file
Output: Temporary JSON with extracted lab values
Privacy: No storage; values exist only in memory during processing
Input: { file_name: "report.pdf", file_type: "application/pdf", file_content: "JVBERi..." }
Output: { status: "success", lab_values: { lh: 12, fsh: 4, testosterone: 0.8, ... } }
Purpose: Analyze lab values against reference patterns
Input: Extracted lab values + fitness level
Output: Findings, explanations, diet/exercise recommendations, confidence score
Privacy: No storage; analysis is stateless
Input: { lab_values: { lh: 12, fsh: 4, testosterone: 0.8, ... }, fitness_level: "intermediate" }
Output: {
status: "success",
findings: ["elevated_lh_fsh_ratio", "elevated_testosterone"],
explanations: { ... },
diet_recommendation: { name: "Low Glycemic Index Diet", ... },
exercise_recommendation: { name: "Follicular Phase Workout", ... },
confidence_score: 85
}
Purpose: Generate professional downloadable report
Input: Lab values, findings, recommendations, confidence score
Output: Report file path + download URL
Privacy: Report stored with UUID filename only (no patient identifiers)
Input: { lab_values: {...}, findings: [...], confidence_score: 85 }
Output: { status: "success", report_id: "report_1234567890", file_path: "...", download_url: "/reports/report_1234567890.txt" }
Purpose: Delete temporary uploaded PDFs and extracted data
Input: Optional specific file path
Output: Cleanup status + count of deleted files
Privacy: Ensures no temporary data remains after processing
Input: { file_path: null } # Clears entire uploads/ directory
Output: { status: "success", deleted_count: 3, uploads_directory: "..." }
- Node.js 18+
- MongoDB Atlas account (or local MongoDB instance)
- NitroStack SDK
Create a .env file in the project root:
# MongoDB
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority
MONGODB_DB=pcos_assistant
# Server
NODE_ENV=development# Install dependencies
npm install
# Install widget dependencies
npm --prefix src/widgets install
# Start dev server
npm run dev-
Extract lab values from uploaded PDF:
User: "Extract lab values from my hormone report" → Tool: extractLabReport() → Returns: { lh: 12, fsh: 4, testosterone: 0.8, ... } -
Analyze findings against reference data:
User: "Analyze these lab values" → Tool: analyzePCOS() → Returns: { findings: [...], diet_plan: {...}, exercise_plan: {...} } -
Generate downloadable report:
User: "Generate a report with these findings" → Tool: generateReport() → Returns: { report_id: "...", download_url: "..." } -
Clean up temporary files:
User: "Clean up temporary files" → Tool: clearTemporaryFiles() → Returns: { deleted_count: 1 }
- Does NOT diagnose diseases
- Does NOT replace professional medical advice
- Requires review by a qualified healthcare provider
- All recommendations should be discussed with a physician
- Framework: NitroStack SDK (TypeScript)
- Database: MongoDB Atlas
- Transport: MCP (Model Context Protocol)
- PDF Processing: pdf-parse (for production; simplified in MVP)
- CSV Processing: Native Node.js file I/O
✅ Modular – Each tool is independent and reusable
✅ Stateless – No session state; each request is self-contained
✅ Privacy-first – Temporary data only; automatic cleanup
✅ Error-resilient – Graceful error handling with detailed logging
✅ Testable – Each utility function is pure and unit-testable
# Typecheck
npm run build
# Dev server
npm run dev- Create a new tool file in
src/tools/ - Implement the tool class with
@Tooldecorator - Register in
src/pcos/pcos.module.ts - Add utility functions to
src/utils/as needed
- Add CSV file to
data/datasets/ - Update
src/utils/csv.tsto filter relevant columns - Create MongoDB collection in
src/mongodb.ts - Seed data in
initializeCollections()
- Set
NODE_ENV=production - Configure MongoDB Atlas with IP whitelist
- Set strong
MONGODB_URIcredentials - Enable HTTPS for all connections
- Configure rate limiting on API endpoints
- Set up monitoring and alerting
- Review and test error handling
- Audit all temporary file cleanup
- Document medical disclaimers prominently
- Logs: Check
src/index.tsfor logging configuration - Errors: All errors logged via
ctx.logger.error() - Monitoring: Integrate with Sentry or similar for production
- Updates: Keep MongoDB driver and dependencies current
Proprietary – Clinical Decision Support Tool
Built with NitroStack SDK
For questions or issues, contact the development team.
