File size: 6,917 Bytes
82b2148
 
 
 
 
 
 
4531bd0
 
 
82b2148
cf0dfc3
82b2148
 
 
cf0dfc3
82b2148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
---
title: Healthcare API MCP
emoji: πŸ₯
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
tags:
  - building-mcp-track-enterprise
  - building-mcp-track-research
---
Link to my LinkedIn post and video submission: https://www.linkedin.com/posts/activity-7399100966597476352-BwTv

# Healthcare API MCP Server

A Model Context Protocol (MCP) server providing structured access to public healthcare data APIs using **HTTP streaming** .

## 🎯 Features

### OpenFDA Provider (14 tools)
- Drug adverse events (FAERS database)
- FDA drug labels and recalls
- NDC directory and Drugs@FDA
- Device safety data
- Food safety data

### Clinical Guidelines Provider (5 tools)
- USPSTF preventive care recommendations
- CDC vaccine schedules
- Evidence-based lifestyle recommendations
- Care plan generation

### CMS Pricing Provider (5 tools)
- Medicare fee schedules
- Procedure cost estimates
- Facility cost comparisons
- Out-of-pocket estimates

**Total: 24 healthcare tools**

## πŸ“‘ API Endpoints

### List Tools
```bash
GET /mcp/tools
```

Returns all available tools with descriptions.

### Call Tool (Standard)
```bash
POST /mcp/call
Content-Type: application/json

{
  "tool": "openfda_get_adverse_event_summary",
  "arguments": {
    "drug_name": "Aspirin"
  }
}
```

### Stream Tool Results (HTTP Streaming)
```bash
POST /mcp/stream
Content-Type: application/json

{
  "tool": "openfda_fetch_adverse_events",
  "arguments": {
    "drug_name": "Aspirin",
    "limit": 100
  }
}
```

Returns newline-delimited JSON (NDJSON) stream with chunked transfer encoding.

## πŸš€ Usage

### With curl

```bash
# List tools
curl https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/tools

# Call a tool
curl -X POST https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/call \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "openfda_search_drug_recalls",
    "arguments": {"query": "Aspirin", "limit": 5}
  }'

# Stream results
curl -N -X POST https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/stream \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "openfda_fetch_adverse_events",
    "arguments": {"drug_name": "Metformin", "limit": 50}
  }'
```

### With Python

```python
import httpx
import json

# Call a tool
async with httpx.AsyncClient() as client:
    response = await client.post(
        "https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/call",
        json={
            "tool": "clinical_get_preventive_recommendations",
            "arguments": {"age": 55, "sex": "female"}
        }
    )
    result = response.json()
    print(result)

# Stream results
async with httpx.AsyncClient() as client:
    async with client.stream(
        "POST",
        "https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/stream",
        json={
            "tool": "openfda_fetch_adverse_events",
            "arguments": {"drug_name": "Simvastatin", "limit": 100}
        }
    ) as response:
        async for line in response.aiter_lines():
            if line:
                data = json.loads(line)
                print(data)
```

### With JavaScript/Node.js

```javascript
// Call a tool
const response = await fetch('https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/call', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    tool: 'cms_estimate_procedure_cost',
    arguments: {procedure_name: 'colonoscopy'}
  })
});
const result = await response.json();
console.log(result);

// Stream results
const streamResponse = await fetch('https://YOUR_USERNAME-healthcare-api-mcp.hf.space/mcp/stream', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    tool: 'openfda_fetch_adverse_events',
    arguments: {drug_name: 'Aspirin', limit: 50}
  })
});

const reader = streamResponse.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const {done, value} = await reader.read();
  if (done) break;

  const lines = decoder.decode(value).split('\n');
  for (const line of lines) {
    if (line.trim()) {
      const data = JSON.parse(line);
      console.log(data);
    }
  }
}
```

## πŸ—οΈ Architecture

- **Protocol**: HTTP with chunked transfer encoding (no SSE)
- **Format**: JSON for requests/responses, NDJSON for streaming
- **Framework**: FastAPI + Uvicorn
- **Transport**: HTTP/1.1 streaming
- **Providers**: Factory pattern with modular providers

## πŸ”§ Configuration

Environment variables (optional):

- `ENABLED_PROVIDERS`: Comma-separated list (default: all)
- `OPENFDA_API_KEY`: Optional for higher FDA rate limits
- `LOG_LEVEL`: DEBUG, INFO, WARNING, ERROR

## πŸ“š Example Queries

**Check Drug Safety:**
```bash
curl -X POST .../mcp/call -H "Content-Type: application/json" \
  -d '{"tool": "openfda_get_adverse_event_summary", "arguments": {"drug_name": "Aspirin"}}'
```

**Get Preventive Care Recommendations:**
```bash
curl -X POST .../mcp/call -H "Content-Type: application/json" \
  -d '{"tool": "clinical_get_preventive_recommendations", "arguments": {"age": 50, "sex": "female"}}'
```

**Estimate Medical Costs:**
```bash
curl -X POST .../mcp/call -H "Content-Type: application/json" \
  -d '{"tool": "cms_estimate_procedure_cost", "arguments": {"procedure_name": "mri"}}'
```

## πŸ“Š Available Tools

See `/mcp/tools` endpoint for complete list with descriptions.

### OpenFDA (14 tools)
- `openfda_get_adverse_event_summary`
- `openfda_fetch_adverse_events`
- `openfda_top_reactions`
- `openfda_search_drug_labels`
- `openfda_search_ndc`
- `openfda_search_drug_recalls`
- `openfda_search_drugs_fda`
- `openfda_search_device_events`
- `openfda_search_device_recalls`
- `openfda_search_device_classifications`
- `openfda_search_510k`
- `openfda_search_pma`
- `openfda_search_food_recalls`
- `openfda_search_food_events`

### Clinical Guidelines (5 tools)
- `clinical_get_preventive_recommendations`
- `clinical_get_vaccine_schedule`
- `clinical_search_guidelines`
- `clinical_get_lifestyle_recommendations`
- `clinical_generate_care_plan`

### CMS Pricing (5 tools)
- `cms_get_medicare_fee`
- `cms_estimate_procedure_cost`
- `cms_search_procedure_codes`
- `cms_compare_facility_costs`
- `cms_estimate_out_of_pocket`

## πŸ”’ Security & Privacy

- βœ… Public APIs only (no PHI)
- βœ… No authentication required
- βœ… Rate limiting via OpenFDA API
- βœ… Stateless queries

## πŸ“– Documentation

- [GitHub Repository](https://github.com/YOUR_USERNAME/healthcare_mcps)
- [Full Documentation](https://github.com/YOUR_USERNAME/healthcare_mcps/tree/main/healthcare_api_mcp)

## πŸŽ‰ Hackathon

Built for **HuggingFace MCP 1st Birthday Hackathon - Track 1**

Demonstrates:
- HTTP streaming (no SSE)
- Factory pattern architecture
- Clean code principles
- Production-ready error handling
- Healthcare data integration

## πŸ“ License

Copyright (c) 2025. All Rights Reserved.

---

**HTTP Streaming | 24 Tools | No SSE | Production Ready**