Skip to content

Commit 773f5ae

Browse files
authored
Simplify Auth Flow in MCP with FHIR server (#9)
* refactor: update OAuth flow with FHIR server This commit merges the existing separate auth flows into single auth flow with FHIR server. * refactor: update OAuth configuration structure in test cases and remove deprecated tests * refactor: update env variable naming, modify test cases and update readme * refactor: update environment variable naming, update readme and fix test cases * refactor: rename scopes property in ServerConfigs and tests, commented out optional env variables.
1 parent 1ebbfe2 commit 773f5ae

17 files changed

+380
-1199
lines changed

.env.example

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
HEALTHCARE_MCP_HOST="localhost"
2-
HEALTHCARE_MCP_PORT="8000"
1+
FHIR_MCP_HOST="localhost"
2+
FHIR_MCP_PORT="8000"
33
# (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
4+
# FHIR_MCP_SERVER_URL=""
5+
# Timeout from MCP server to FHIR server, in seconds
6+
# FHIR_MCP_REQUEST_TIMEOUT=60
7+
8+
FHIR_SERVER_CLIENT_ID=""
9+
FHIR_SERVER_CLIENT_SECRET=""
10+
FHIR_SERVER_BASE_URL=""
11+
FHIR_SERVER_SCOPES=""
1312
# (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=""
13+
# FHIR_SERVER_ACCESS_TOKEN=""

README.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,42 +80,30 @@ You can customize the behavior of the MCP server using the following command-lin
8080
- Accepted values: DEBUG, INFO, WARN, ERROR (case-insensitive)
8181
- Default: INFO
8282

83-
- **--disable-mcp-auth**
84-
- Description: Disables OAuth2-based authentication between the MCP client (e.g., Claude Desktop or VSCode) and the MCP server.
85-
- Type: Flag (no value required)
86-
- Default: False (authentication enabled)
87-
88-
- **--disable-fhir-auth**
89-
- Description: Disables OAuth2-based authentication between the MCP server and the FHIR server.
83+
- **--disable-auth**
84+
- Description: Disables the security of the MCP Server. Allows you to connect with openly available FHIR servers.
9085
- Type: Flag (no value required)
9186
- Default: False (authentication enabled)
9287

9388
Sample Usages:
9489

9590
```shell
96-
uv run fhir-mcp-server --transport streamable-http --log-level DEBUG --disable-mcp-auth --disable-fhir-auth
91+
uv run fhir-mcp-server --transport streamable-http --log-level DEBUG --disable-auth
9792
```
9893

9994
### Environment Variables
10095

10196
**MCP Server Configurations:**
102-
- `HEALTHCARE_MCP_HOST`: The hostname or IP address the MCP server should bind to (e.g., 0.0.0.0 for all interfaces, or localhost for local-only access).
103-
- `HEALTHCARE_MCP_PORT`: The port on which the MCP server will listen for incoming client requests (e.g., 8000).
104-
105-
**MCP Server OAuth2 Configuration (MCP Client ↔ MCP Server):**
106-
These variables are used when securing communication between an MCP client (like Claude Desktop or VSCode) and the MCP server via OAuth2 Authorization Code Grant flow.
107-
108-
- `HEALTHCARE_MCP_OAUTH__CLIENT_ID`: The OAuth2 client ID registered with your Identity Provider to authenticate MCP clients.
109-
- `HEALTHCARE_MCP_OAUTH__CLIENT_SECRET`: The OAuth2 client secret used to verify the MCP client during the token exchange process.
110-
- `HEALTHCARE_MCP_OAUTH__METADATA_URL`: The URL to the Identity Provider’s OAuth2 discovery document (usually ending in .well-known/openid-configuration). Used to dynamically fetch token and authorization endpoints.
97+
- `FHIR_MCP_HOST`: The hostname or IP address the MCP server should bind to (e.g., `localhost` for local-only access, or `0.0.0.0` for all interfaces).
98+
- `FHIR_MCP_PORT`: The port on which the MCP server will listen for incoming client requests (e.g., `8000`).
11199

112-
**FHIR Backend Configuration (MCP ServerFHIR Server):**
113-
These variables configure the MCP server’s secure connection with the FHIR backend using authorization code grant flow.
100+
**MCP Server OAuth2 with FHIR server Configuration (MCP ClientMCP Server):**
101+
These variables configure the MCP client's secure connection to the MCP server, using the OAuth2 authorization code grant flow with a FHIR server.
114102
115-
- `HEALTHCARE_MCP_FHIR__CLIENT_ID`: The OAuth2 client ID used by the MCP server to authenticate itself to the FHIR server.
116-
- `HEALTHCARE_MCP_FHIR__CLIENT_SECRET`: The client secret corresponding to the FHIR client ID. Used during token exchange.
117-
- `HEALTHCARE_MCP_FHIR__BASE_URL`: The base URL of the FHIR server (e.g., https://hapi.fhir.org/baseR4). This is used to generate tool URIs and to route FHIR requests.
118-
- `HEALTHCARE_MCP_FHIR__SCOPE`: A space-separated list of OAuth2 scopes to request from the FHIR authorization server (e.g., user/Patient.read user/Observation.read).
103+
- `FHIR_SERVER_CLIENT_ID`: The OAuth2 client ID used to authorize MCP clients with the FHIR server.
104+
- `FHIR_SERVER_CLIENT_SECRET`: The client secret corresponding to the FHIR client ID. Used during token exchange.
105+
- `FHIR_SERVER_BASE_URL`: The base URL of the FHIR server (e.g., `https://hapi.fhir.org/baseR4`). This is used to generate tool URIs and to route FHIR requests.
106+
- `FHIR_SERVER_SCOPES`: A space-separated list of OAuth2 scopes to request from the FHIR authorization server (e.g., `user/Patient.read user/Observation.read`).
119107
120108
121109
## Usage

src/fhir_mcp_server/oauth/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
# specific language governing permissions and limitations
1515
# under the License.
1616

17-
from .client_provider import FHIRClientProvider
1817
from .common import handle_successful_authentication, handle_failed_authentication
1918
from .server_provider import OAuthServerProvider
20-
from .types import FHIROAuthConfigs, ServerConfigs, OAuthToken
19+
from .types import ServerConfigs, OAuthToken
2120

2221
__all__ = [
23-
"FHIRClientProvider",
24-
"FHIROAuthConfigs",
2522
"handle_successful_authentication",
2623
"handle_failed_authentication",
2724
"OAuthServerProvider",

src/fhir_mcp_server/oauth/client_provider.py

Lines changed: 0 additions & 283 deletions
This file was deleted.

0 commit comments

Comments
 (0)