Skip to content

Commit 61f5809

Browse files
feat: initial implementation and project setup for Python-based FHIR MCP server
Establish project structure and environment configuration Implement core FHIR MCP server logic and OAuth modules Add utility functions and supporting files
1 parent ed0d9c8 commit 61f5809

File tree

15 files changed

+2751
-23
lines changed

15 files changed

+2751
-23
lines changed

.env.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
HEALTHCARE_MCP_HOST="localhost"
2+
HEALTHCARE_MCP_PORT="8000"
3+
# (Optional) If set, this value will be used as the server's base URL instead of generating it from host and port
4+
HEALTHCARE_MCP_SERVER_URL=""
5+
6+
7+
HEALTHCARE_MCP_FHIR__CLIENT_ID=""
8+
HEALTHCARE_MCP_FHIR__CLIENT_SECRET=""
9+
HEALTHCARE_MCP_FHIR__BASE_URL=""
10+
HEALTHCARE_MCP_FHIR__SCOPE=""
11+
# Timeout for FHIR server requests, in seconds
12+
HEALTHCARE_MCP_FHIR__TIMEOUT=60
13+
# (Optional) If set, the authorization flow will be skipped and this access token will be used directly
14+
HEALTHCARE_MCP_FHIR__ACCESS_TOKEN=""
15+
16+
17+
HEALTHCARE_MCP_OAUTH__CLIENT_ID=""
18+
HEALTHCARE_MCP_OAUTH__CLIENT_SECRET=""
19+
HEALTHCARE_MCP_OAUTH__METADATA_URL=""
20+
HEALTHCARE_MCP_OAUTH__SCOPE=""

.gitignore

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
# Compiled class file
2-
*.class
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
38

4-
# Log file
5-
*.log
9+
# Virtual environments
10+
.venv
611

7-
# BlueJ files
8-
*.ctxt
12+
# IDE specific
13+
.vscode/
14+
.idea/
915

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
12-
13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
21-
22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
24-
replay_pid*
16+
# Environment variables
17+
.env
18+
*.env

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

README.md

Lines changed: 200 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,200 @@
1-
# fhir-mcp-server
2-
This server lets you interact with Fast Healthcare Interoperability Resources (FHIR) resources on a specified FHIR server.
1+
# Model Context Protocol (MCP) Server for Fast Healthcare Interoperability Resources (FHIR)
2+
3+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/wso2/fhir-mcp-server/blob/main/LICENSE)
4+
[![Get Support on Stack Overflow](https://img.shields.io/badge/stackoverflow-wso2-orange)](https://stackoverflow.com/questions/tagged/wso2)
5+
[![Join the community on Discord](https://img.shields.io/badge/Join%20us%20on-Discord-%23e01563.svg)](https://discord.com/invite/wso2)
6+
[![X](https://img.shields.io/twitter/follow/wso2.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=wso2)
7+
8+
## Overview
9+
10+
The MCP Server for FHIR is a Python-based service that provides seamless, standardized access to FHIR data from any compatible FHIR server. Designed for developers, integrators, and healthcare innovators, this server acts as a bridge between modern AI/LLM tools and healthcare data, making it easy to search, retrieve, and analyze clinical information.
11+
12+
**Key features:**
13+
- **Flexible Integration:** Use the server from the command line, in Docker, or directly within tools like VS Code, Claude Desktop, and MCP Inspector.
14+
- **Natural Language FHIR Search:** Query for patients, allergies, immunizations, care plans, and more using simple prompts or programmatic requests.
15+
- **Configurable & Secure:** Easily connect to any FHIR server, with support for environment-based configuration and secure access tokens.
16+
- **Developer Friendly:** Quick setup with modern Python tooling (`uv`), clear documentation, and ready-to-use integration examples for rapid prototyping and deployment.
17+
18+
Whether you are building healthcare applications, integrating with AI assistants, or exploring clinical datasets, the MCP server provides a robust foundation for accessing and working with FHIR data in a standardized, extensible way.
19+
20+
## Prerequisites
21+
- Python 3.8+
22+
- [uv](https://github.com/astral-sh/uv) (for dependency management)
23+
- An accessible FHIR server (defaults to the public HAPI FHIR test server)
24+
25+
## Setup
26+
27+
1. **Clone the repository:**
28+
```bash
29+
git clone <repository_url>
30+
cd <repository_directory>
31+
```
32+
2. **Create a virtual environment and install dependencies:**
33+
```bash
34+
uv venv
35+
source .venv/bin/activate
36+
uv pip sync requirements.txt
37+
```
38+
Or with pip:
39+
```bash
40+
python -m venv .venv
41+
source .venv/bin/activate
42+
pip install -r requirements.txt
43+
```
44+
3. **Configure Environment Variables:**
45+
Copy the example file and customize if needed:
46+
```bash
47+
cp .env.example .env
48+
```
49+
50+
## Usage
51+
52+
Run the server:
53+
```bash
54+
uv run fhir-mcp-server
55+
```
56+
57+
You can also run the server directly from the PyPI package (without cloning the repository) using:
58+
59+
```bash
60+
uvx fhir-mcp-server
61+
```
62+
63+
## VS Code Integration
64+
Add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P and typing Preferences: Open User Settings (JSON).
65+
66+
<table>
67+
<tr><th>Streamable HTTP</th><th>stdio</th></tr>
68+
<tr valign=top>
69+
<td>
70+
71+
```json
72+
"mcp": {
73+
"servers": {
74+
"fhir": {
75+
"command": "npx",
76+
"args": [
77+
"-y",
78+
"mcp-remote",
79+
"http://localhost:8000/mcp"
80+
]
81+
}
82+
}
83+
}
84+
```
85+
</td>
86+
<td>
87+
88+
```json
89+
"mcp": {
90+
"servers": {
91+
"fhir": {
92+
"command": "uv",
93+
"args": [
94+
"--directory",
95+
"/path/to/fhir-mcp-server",
96+
"run",
97+
"fhir-mcp-server",
98+
"--transport",
99+
"stdio"
100+
],
101+
"env": {
102+
"HEALTHCARE_MCP_FHIR__ACCESS_TOKEN": "Your FHIR Access Token"
103+
}
104+
}
105+
}
106+
}
107+
```
108+
</td>
109+
</tr>
110+
</table>
111+
112+
## Claude Desktop Integration
113+
Add the following JSON block to your Claude Desktop settings to connect to your local MCP server.
114+
- Launch the Claude Desktop app, click on the Claude menu in the top bar, and select "Settings…".
115+
- In the Settings pane, click “Developer” in the left sidebar. Then click "Edit Config". This will open your configuration file in your file system. If it doesn’t exist yet, Claude will create one automatically at:
116+
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
117+
- Windows: %APPDATA%\Claude\claude_desktop_config.json
118+
- Open the claude_desktop_config.json file in any text editor. Replace its contents with the following JSON block to register the MCP server:
119+
120+
<table>
121+
<tr><th>Streamable HTTP</th><th>stdio</th></tr>
122+
<tr valign=top>
123+
<td>
124+
125+
```json
126+
{
127+
"mcpServers": {
128+
"fhir": {
129+
"command": "npx",
130+
"args": [
131+
"-y",
132+
"mcp-remote",
133+
"http://localhost:8000/mcp"
134+
]
135+
}
136+
}
137+
}
138+
```
139+
</td>
140+
<td>
141+
142+
```json
143+
{
144+
"mcpServers": {
145+
"fhir": {
146+
"command": "uv",
147+
"args": [
148+
"--directory",
149+
"/path/to/fhir-mcp-server",
150+
"run",
151+
"fhir-mcp-server",
152+
"--transport",
153+
"stdio"
154+
],
155+
"env": {
156+
"HEALTHCARE_MCP_FHIR__ACCESS_TOKEN": "Your FHIR Access Token"
157+
}
158+
}
159+
}
160+
}
161+
```
162+
</td>
163+
</tr>
164+
</table>
165+
166+
## MCP Inspector Integration
167+
Follow these steps to get the MCP Inspector up and running:
168+
169+
- Open a terminal and run the following command:
170+
171+
`npx -y @modelcontextprotocol/inspector`
172+
173+
- In the MCP Inspector interface:
174+
<table>
175+
<tr><th>Streamable HTTP</th><th>stdio</th></tr>
176+
<tr valign=top>
177+
<td>
178+
179+
- Transport Type: `Streamable HTTP`
180+
- URL: `http://localhost:8000/mcp`
181+
</td>
182+
<td>
183+
184+
- Transport Type: `STDIO`
185+
- Command: `uv`
186+
- Arguments: `--directory /path/to/fhir-mcp-server run fhir-mcp-server --transport stdio`
187+
</td>
188+
</tr>
189+
</table>
190+
191+
Make sure your MCP server is already running and listening on the above endpoint.
192+
193+
Once connected, MCP Inspector will allow you to visualize tool invocations, inspect request/response payloads, and debug your tool implementations easily.
194+
195+
## Example Prompts
196+
- Get allergy history for patient 53373
197+
- Fetch the immunization records for patient ID 53373
198+
- List all active care plans for patient 22
199+
- Provide a consolidated report for patient 53373 that includes their complete allergy history as well as all available immunization records, organized by date and highlighting any critical alerts
200+
- Retrieve all active care plans for patient ID 22 and present them in a markdown table showing each plan’s ID, title, status, intent, and start date

pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[project]
2+
authors = [
3+
{name = "WSO2", email = "[email protected]"},
4+
]
5+
classifiers = [
6+
"Development Status :: 4 - Beta",
7+
"Programming Language :: Python :: 3",
8+
"Programming Language :: Python :: 3.12",
9+
"Intended Audience :: Developers",
10+
"Operating System :: OS Independent",
11+
]
12+
dependencies = [
13+
"mcp[cli]>=1.9.1",
14+
"aiohttp>=3.12.13",
15+
"fhirpy>=2.0.15",
16+
]
17+
description = "A Model Context Protocol (MCP) server that provides seamless, standardized access to Fast Healthcare Interoperability Resources (FHIR) data from any compatible FHIR server. Designed for easy integration with AI tools, developer workflows, and healthcare applications, it enables natural language and programmatic search, retrieval, and analysis of clinical data."
18+
keywords = [
19+
"fhir",
20+
"healthcare",
21+
"mcp",
22+
"model-context-protocol",
23+
"llm",
24+
]
25+
license = "Apache-2.0"
26+
license-files = ["LICEN[CS]E*"]
27+
name = "fhir-mcp-server"
28+
readme = {file = "README.md", content-type = "text/markdown"}
29+
requires-python = ">=3.12"
30+
version = "1.0.0"
31+
32+
[build-system]
33+
build-backend = "hatchling.build"
34+
requires = ["hatchling"]
35+
36+
[tool.hatch.build.targets.wheel]
37+
packages = ["src/fhir_mcp_server"]
38+
39+
[project.scripts]
40+
fhir-mcp-server = "fhir_mcp_server.server:main"
41+
42+
[[tool.uv.index]]
43+
name = "pypi"
44+
publish-url = "https://upload.pypi.org/legacy/"
45+
url = "https://pypi.org/simple/"
46+
47+
[project.urls]
48+
"Bug Tracker" = "https://github.com/wso2/fhir-mcp-server/issues"
49+
"Documentation" = "https://github.com/wso2/fhir-mcp-server/blob/development/README.md"
50+
"Homepage" = "https://github.com/wso2/fhir-mcp-server"

requirements.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
aiohappyeyeballs==2.6.1
2+
aiohttp==3.12.2
3+
aiosignal==1.3.2
4+
annotated-types==0.7.0
5+
anyio==4.9.0
6+
attrs==25.3.0
7+
certifi==2025.4.26
8+
charset-normalizer==3.4.2
9+
click==8.2.1
10+
fhirpy==2.0.15
11+
frozenlist==1.6.0
12+
h11==0.16.0
13+
httpcore==1.0.9
14+
httpx==0.28.1
15+
httpx-sse==0.4.0
16+
idna==3.10
17+
markdown-it-py==3.0.0
18+
mcp==1.9.1
19+
mdurl==0.1.2
20+
multidict==6.4.4
21+
propcache==0.3.1
22+
pydantic==2.11.5
23+
pydantic-core==2.33.2
24+
pydantic-settings==2.9.1
25+
pygments==2.19.1
26+
python-dotenv==1.1.0
27+
python-multipart==0.0.20
28+
pytz==2025.2
29+
requests==2.32.3
30+
rich==14.0.0
31+
shellingham==1.5.4
32+
sniffio==1.3.1
33+
sse-starlette==2.3.5
34+
starlette==0.46.2
35+
typer==0.16.0
36+
typing-extensions==4.13.2
37+
typing-inspection==0.4.1
38+
urllib3==2.4.0
39+
uvicorn==0.34.2
40+
yarl==1.20.0

src/fhir_mcp_server/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com/) All Rights Reserved.
2+
3+
# WSO2 LLC. licenses this file to you under the Apache License,
4+
# Version 2.0 (the "License"); you may not use this file except
5+
# in compliance with the License.
6+
# You may obtain postgres_pgvector copy of the License at
7+
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
10+
# Unless required by applicable law or agreed to in writing,
11+
# software distributed under the License is distributed on an
12+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13+
# KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations
15+
# under the License.

0 commit comments

Comments
 (0)