Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,157 +1,275 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
-
|
| 27 |
-
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
```
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
```
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
{
|
| 67 |
-
|
| 68 |
-
"
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Healthcare API MCP
|
| 3 |
+
emoji: π₯
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Healthcare API MCP Server
|
| 11 |
+
|
| 12 |
+
A Model Context Protocol (MCP) server providing structured access to public healthcare data APIs using **HTTP streaming** (no SSE).
|
| 13 |
+
|
| 14 |
+
## π― Features
|
| 15 |
+
|
| 16 |
+
### OpenFDA Provider (14 tools)
|
| 17 |
+
- Drug adverse events (FAERS database)
|
| 18 |
+
- FDA drug labels and recalls
|
| 19 |
+
- NDC directory and Drugs@FDA
|
| 20 |
+
- Device safety data
|
| 21 |
+
- Food safety data
|
| 22 |
+
|
| 23 |
+
### Clinical Guidelines Provider (5 tools)
|
| 24 |
+
- USPSTF preventive care recommendations
|
| 25 |
+
- CDC vaccine schedules
|
| 26 |
+
- Evidence-based lifestyle recommendations
|
| 27 |
+
- Care plan generation
|
| 28 |
+
|
| 29 |
+
### CMS Pricing Provider (5 tools)
|
| 30 |
+
- Medicare fee schedules
|
| 31 |
+
- Procedure cost estimates
|
| 32 |
+
- Facility cost comparisons
|
| 33 |
+
- Out-of-pocket estimates
|
| 34 |
+
|
| 35 |
+
**Total: 24 healthcare tools**
|
| 36 |
+
|
| 37 |
+
## π‘ API Endpoints
|
| 38 |
+
|
| 39 |
+
### List Tools
|
| 40 |
+
```bash
|
| 41 |
+
GET /mcp/tools
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Returns all available tools with descriptions.
|
| 45 |
+
|
| 46 |
+
### Call Tool (Standard)
|
| 47 |
+
```bash
|
| 48 |
+
POST /mcp/call
|
| 49 |
+
Content-Type: application/json
|
| 50 |
+
|
| 51 |
+
{
|
| 52 |
+
"tool": "openfda_get_adverse_event_summary",
|
| 53 |
+
"arguments": {
|
| 54 |
+
"drug_name": "Aspirin"
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
### Stream Tool Results (HTTP Streaming)
|
| 60 |
+
```bash
|
| 61 |
+
POST /mcp/stream
|
| 62 |
+
Content-Type: application/json
|
| 63 |
+
|
| 64 |
+
{
|
| 65 |
+
"tool": "openfda_fetch_adverse_events",
|
| 66 |
+
"arguments": {
|
| 67 |
+
"drug_name": "Aspirin",
|
| 68 |
+
"limit": 100
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
Returns newline-delimited JSON (NDJSON) stream with chunked transfer encoding.
|
| 74 |
+
|
| 75 |
+
## π Usage
|
| 76 |
+
|
| 77 |
+
### With curl
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
# List tools
|
| 81 |
+
curl https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/tools
|
| 82 |
+
|
| 83 |
+
# Call a tool
|
| 84 |
+
curl -X POST https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/call \
|
| 85 |
+
-H "Content-Type: application/json" \
|
| 86 |
+
-d '{
|
| 87 |
+
"tool": "openfda_search_drug_recalls",
|
| 88 |
+
"arguments": {"query": "Aspirin", "limit": 5}
|
| 89 |
+
}'
|
| 90 |
+
|
| 91 |
+
# Stream results
|
| 92 |
+
curl -N -X POST https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/stream \
|
| 93 |
+
-H "Content-Type: application/json" \
|
| 94 |
+
-d '{
|
| 95 |
+
"tool": "openfda_fetch_adverse_events",
|
| 96 |
+
"arguments": {"drug_name": "Metformin", "limit": 50}
|
| 97 |
+
}'
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
### With Python
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
import httpx
|
| 104 |
+
import json
|
| 105 |
+
|
| 106 |
+
# Call a tool
|
| 107 |
+
async with httpx.AsyncClient() as client:
|
| 108 |
+
response = await client.post(
|
| 109 |
+
"https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/call",
|
| 110 |
+
json={
|
| 111 |
+
"tool": "clinical_get_preventive_recommendations",
|
| 112 |
+
"arguments": {"age": 55, "sex": "female"}
|
| 113 |
+
}
|
| 114 |
+
)
|
| 115 |
+
result = response.json()
|
| 116 |
+
print(result)
|
| 117 |
+
|
| 118 |
+
# Stream results
|
| 119 |
+
async with httpx.AsyncClient() as client:
|
| 120 |
+
async with client.stream(
|
| 121 |
+
"POST",
|
| 122 |
+
"https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/stream",
|
| 123 |
+
json={
|
| 124 |
+
"tool": "openfda_fetch_adverse_events",
|
| 125 |
+
"arguments": {"drug_name": "Simvastatin", "limit": 100}
|
| 126 |
+
}
|
| 127 |
+
) as response:
|
| 128 |
+
async for line in response.aiter_lines():
|
| 129 |
+
if line:
|
| 130 |
+
data = json.loads(line)
|
| 131 |
+
print(data)
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
### With JavaScript/Node.js
|
| 135 |
+
|
| 136 |
+
```javascript
|
| 137 |
+
// Call a tool
|
| 138 |
+
const response = await fetch('https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/call', {
|
| 139 |
+
method: 'POST',
|
| 140 |
+
headers: {'Content-Type': 'application/json'},
|
| 141 |
+
body: JSON.stringify({
|
| 142 |
+
tool: 'cms_estimate_procedure_cost',
|
| 143 |
+
arguments: {procedure_name: 'colonoscopy'}
|
| 144 |
+
})
|
| 145 |
+
});
|
| 146 |
+
const result = await response.json();
|
| 147 |
+
console.log(result);
|
| 148 |
+
|
| 149 |
+
// Stream results
|
| 150 |
+
const streamResponse = await fetch('https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/stream', {
|
| 151 |
+
method: 'POST',
|
| 152 |
+
headers: {'Content-Type': 'application/json'},
|
| 153 |
+
body: JSON.stringify({
|
| 154 |
+
tool: 'openfda_fetch_adverse_events',
|
| 155 |
+
arguments: {drug_name: 'Aspirin', limit: 50}
|
| 156 |
+
})
|
| 157 |
+
});
|
| 158 |
+
|
| 159 |
+
const reader = streamResponse.body.getReader();
|
| 160 |
+
const decoder = new TextDecoder();
|
| 161 |
+
|
| 162 |
+
while (true) {
|
| 163 |
+
const {done, value} = await reader.read();
|
| 164 |
+
if (done) break;
|
| 165 |
+
|
| 166 |
+
const lines = decoder.decode(value).split('\n');
|
| 167 |
+
for (const line of lines) {
|
| 168 |
+
if (line.trim()) {
|
| 169 |
+
const data = JSON.parse(line);
|
| 170 |
+
console.log(data);
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## ποΈ Architecture
|
| 177 |
+
|
| 178 |
+
- **Protocol**: HTTP with chunked transfer encoding (no SSE)
|
| 179 |
+
- **Format**: JSON for requests/responses, NDJSON for streaming
|
| 180 |
+
- **Framework**: FastAPI + Uvicorn
|
| 181 |
+
- **Transport**: HTTP/1.1 streaming
|
| 182 |
+
- **Providers**: Factory pattern with modular providers
|
| 183 |
+
|
| 184 |
+
## π§ Configuration
|
| 185 |
+
|
| 186 |
+
Environment variables (optional):
|
| 187 |
+
|
| 188 |
+
- `ENABLED_PROVIDERS`: Comma-separated list (default: all)
|
| 189 |
+
- `OPENFDA_API_KEY`: Optional for higher FDA rate limits
|
| 190 |
+
- `LOG_LEVEL`: DEBUG, INFO, WARNING, ERROR
|
| 191 |
+
|
| 192 |
+
## π Example Queries
|
| 193 |
+
|
| 194 |
+
**Check Drug Safety:**
|
| 195 |
+
```bash
|
| 196 |
+
curl -X POST .../mcp/call -H "Content-Type: application/json" \
|
| 197 |
+
-d '{"tool": "openfda_get_adverse_event_summary", "arguments": {"drug_name": "Aspirin"}}'
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
**Get Preventive Care Recommendations:**
|
| 201 |
+
```bash
|
| 202 |
+
curl -X POST .../mcp/call -H "Content-Type: application/json" \
|
| 203 |
+
-d '{"tool": "clinical_get_preventive_recommendations", "arguments": {"age": 50, "sex": "female"}}'
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
**Estimate Medical Costs:**
|
| 207 |
+
```bash
|
| 208 |
+
curl -X POST .../mcp/call -H "Content-Type: application/json" \
|
| 209 |
+
-d '{"tool": "cms_estimate_procedure_cost", "arguments": {"procedure_name": "mri"}}'
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
## π Available Tools
|
| 213 |
+
|
| 214 |
+
See `/mcp/tools` endpoint for complete list with descriptions.
|
| 215 |
+
|
| 216 |
+
### OpenFDA (14 tools)
|
| 217 |
+
- `openfda_get_adverse_event_summary`
|
| 218 |
+
- `openfda_fetch_adverse_events`
|
| 219 |
+
- `openfda_top_reactions`
|
| 220 |
+
- `openfda_search_drug_labels`
|
| 221 |
+
- `openfda_search_ndc`
|
| 222 |
+
- `openfda_search_drug_recalls`
|
| 223 |
+
- `openfda_search_drugs_fda`
|
| 224 |
+
- `openfda_search_device_events`
|
| 225 |
+
- `openfda_search_device_recalls`
|
| 226 |
+
- `openfda_search_device_classifications`
|
| 227 |
+
- `openfda_search_510k`
|
| 228 |
+
- `openfda_search_pma`
|
| 229 |
+
- `openfda_search_food_recalls`
|
| 230 |
+
- `openfda_search_food_events`
|
| 231 |
+
|
| 232 |
+
### Clinical Guidelines (5 tools)
|
| 233 |
+
- `clinical_get_preventive_recommendations`
|
| 234 |
+
- `clinical_get_vaccine_schedule`
|
| 235 |
+
- `clinical_search_guidelines`
|
| 236 |
+
- `clinical_get_lifestyle_recommendations`
|
| 237 |
+
- `clinical_generate_care_plan`
|
| 238 |
+
|
| 239 |
+
### CMS Pricing (5 tools)
|
| 240 |
+
- `cms_get_medicare_fee`
|
| 241 |
+
- `cms_estimate_procedure_cost`
|
| 242 |
+
- `cms_search_procedure_codes`
|
| 243 |
+
- `cms_compare_facility_costs`
|
| 244 |
+
- `cms_estimate_out_of_pocket`
|
| 245 |
+
|
| 246 |
+
## π Security & Privacy
|
| 247 |
+
|
| 248 |
+
- β
Public APIs only (no PHI)
|
| 249 |
+
- β
No authentication required
|
| 250 |
+
- β
Rate limiting via OpenFDA API
|
| 251 |
+
- β
Stateless queries
|
| 252 |
+
|
| 253 |
+
## π Documentation
|
| 254 |
+
|
| 255 |
+
- [GitHub Repository](https://github.com/YOUR_USERNAME/healthcare_mcps)
|
| 256 |
+
- [Full Documentation](https://github.com/YOUR_USERNAME/healthcare_mcps/tree/main/healthcare_api_mcp)
|
| 257 |
+
|
| 258 |
+
## π Hackathon
|
| 259 |
+
|
| 260 |
+
Built for **HuggingFace MCP 1st Birthday Hackathon - Track 1**
|
| 261 |
+
|
| 262 |
+
Demonstrates:
|
| 263 |
+
- HTTP streaming (no SSE)
|
| 264 |
+
- Factory pattern architecture
|
| 265 |
+
- Clean code principles
|
| 266 |
+
- Production-ready error handling
|
| 267 |
+
- Healthcare data integration
|
| 268 |
+
|
| 269 |
+
## π License
|
| 270 |
+
|
| 271 |
+
Copyright (c) 2025. All Rights Reserved.
|
| 272 |
+
|
| 273 |
+
---
|
| 274 |
+
|
| 275 |
+
**HTTP Streaming | 24 Tools | No SSE | Production Ready**
|