MCP Access with an Organization API Token
Instead of a patient's OAuth access token, your backend can call the MCP endpoint with your organization's API token. Use this when your own service, rather than an AI agent acting for the patient, needs to call MCP tools for patients who have already consented to share data with your organization.
Each request names a patient and one of your organization's AI projects. The patient must have an active consent to share data on that project. Consent on any other project, such as a research or test project, does not grant MCP access. If the patient withdraws consent, or the consent expires, requests for that patient are rejected.
1. Generate an API token
Generate a token from your API Key and Secret:
curl -X POST "https://api.healthex.io/v1/auth/token" \
-H "Content-Type: application/json" \
-d '{
"apiKey": "{your_api_key}",
"apiSecret": "{your_api_secret}"
}'
See the Authentication guide for details. The token is valid for 24 hours. Deleting the API key stops all of its tokens from working immediately.
2. Call MCP for a patient
Send the API token as the bearer token, and name the patient and project in headers:
curl -X POST "https://api.healthex.io/mcp" \
-H "Authorization: Bearer {api_token}" \
-H "X-HealthEx-Patient-Id: {patientId}" \
-H "X-HealthEx-Project-Id: {projectId}" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_health_summary",
"arguments": {}
}
}'
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer {api_token} |
X-HealthEx-Patient-Id | Yes | The HealthEx patient ID. |
X-HealthEx-Project-Id | Yes | One of your organization's active AI projects that the patient has consented to. |
The project determines which consent applies to the request, for example for the get_consent_record tool. On a project with PHI turned off, only test patients can be accessed.
Requests are one message each
Send one JSON-RPC message per HTTP request. JSON-RPC batch requests (an array body) are rejected with 400 and error code -32600. This applies to patient OAuth tokens too.
Errors
| Status | code | Cause |
|---|---|---|
400 | invalid_request | X-HealthEx-Patient-Id or X-HealthEx-Project-Id is missing, empty or malformed. |
401 | invalid_token | The API token is invalid, expired, or its API key was deleted. |
403 | client_type_not_allowed | The API key's type cannot read patient data. |
403 | invalid_project | X-HealthEx-Project-Id is not an active AI project of your organization. |
403 | invalid_patient | X-HealthEx-Patient-Id has never consented to this project, or is not a HealthEx patient. The two cases return the same response. |
403 | consent_revoked | The patient consented to this project, but the consent was revoked or has expired. |
403 | patient_not_authorized | The project has PHI turned off and the patient is not a test patient. |
500 | consent_check_failed | Consent could not be evaluated. Retry the request; your token is still valid. |
Error bodies have the same shape as for patient OAuth tokens: { "error": "<message>", "code": "<code>" }. Match on code, not on the error text. For invalid_token and invalid_request, the WWW-Authenticate header also carries the standard bearer error, for example Bearer error="invalid_request", resource_metadata="…".