MCP
OctoFHIR serves the Model Context Protocol at POST /mcp, over
Streamable HTTP. An agent gets tools shaped for clinical questions rather than one tool per REST
interaction. Each answer is a single JSON response.
[mcp]enabled = true # serve POST /mcp (default); when false the endpoint is 404allow_writes = false # offer write_resource (default false)toolbox = false # offer the package tools below (default false)How a tool call runs
Section titled “How a tool call runs”Each tool is a request to this server’s own HTTP stack, carrying the caller’s Authorization header.
There is no second authorization path: SMART scopes, access policies, validation and audit apply to an
agent exactly as to any other client, and a tool can do no more than its token can over REST.
POST /mcp itself does not verify the token. It only requires an Authorization header to be present;
the token is checked on the request each tool makes. The authorization you configure is therefore the
same as for a REST client: a Client with the scopes
the agent should have, and an access policy that matches it.
Authorization discovery
Section titled “Authorization discovery”A request with no Authorization header is 401, and so is a tool call whose token the server rejects, so
the client can renew it:
HTTP/1.1 401 UnauthorizedWWW-Authenticate: Bearer resource_metadata="https://fhir.example.org/.well-known/oauth-protected-resource/mcp"That document (RFC 9728) tells the client where to get a token:
GET /.well-known/oauth-protected-resource/mcp{ "resource": "https://fhir.example.org/mcp", "authorization_servers": ["https://fhir.example.org"], "bearer_methods_supported": ["header"]}authorization_servers holds auth.issuer. With auth.policy.anonymous_access enabled, a request without
the header is let through and its tool calls run as anonymous requests.
Protocol versions
Section titled “Protocol versions”| Revision | Start of a session |
|---|---|
2026-07-28 |
server/discover, no handshake |
2025-11-25 |
initialize |
2025-06-18 |
initialize |
initialize answers with the revision the client asked for, or 2025-11-25 if it asked for one the server
does not have. A request names its revision in the MCP-Protocol-Version header, in
_meta["io.modelcontextprotocol/protocolVersion"], or both. The methods are server/discover, initialize,
ping, tools/list and tools/call. A notification (no id) is 202.
| Response | When |
|---|---|
400 with -32022 |
The revision is not supported; error.data.supported lists those that are |
400 with -32001 |
The header and _meta disagree, Mcp-Method differs from the request, or on 2026-07-28 Mcp-Name differs from the tool |
400 with -32600 |
The body is not a JSON-RPC request |
403 with -32600 |
Origin is not this server |
404 with -32601 |
Unknown method |
An Origin header must match the request’s Host or the configured base URL, which guards against DNS
rebinding. Requests without Origin pass.
| Tool | Arguments | Runs |
|---|---|---|
get_capabilities |
GET /fhir/metadata?_summary=false |
|
read_resource |
resourceType, id |
GET /fhir/{type}/{id} |
search_resources |
resourceType, query |
GET /fhir/{type}?{query}. To page, call it again with the query of the next link. |
patient_summary |
patientId |
GET /fhir/Patient/{id}/$summary |
evaluate_measure |
measureId, periodStart, periodEnd, subject |
POST /fhir/Measure/{id}/$evaluate-measure |
lookup_code |
system, code |
POST /fhir/CodeSystem/$lookup |
validate_code |
valueSet, code, system |
POST /fhir/ValueSet/$validate-code, with _explain on, and inferSystem when system is absent |
validate_resource |
resource, profile |
POST /fhir/{type}/$validate; nothing is stored |
evaluate_fhirpath |
expression, resource |
POST /fhir/$fhirpath |
write_resource |
resource |
Only with mcp.allow_writes. See below. |
All but write_resource are marked read-only. tools/list tells the client it may cache the list for 5
minutes.
POST /mcpAuthorization: Bearer {token}Content-Type: application/jsonMCP-Protocol-Version: 2026-07-28Mcp-Method: tools/callMcp-Name: search_resources
{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "search_resources", "arguments": {"resourceType": "Observation", "query": "patient=123&status=final&_count=20"} }}{ "jsonrpc": "2.0", "id": 1, "result": { "resultType": "complete", "content": [{"type": "text", "text": "{\"resourceType\":\"Bundle\", ...}"}], "structuredContent": {"resourceType": "Bundle"}, "isError": false }}The FHIR response is both content text and structuredContent. A FHIR error, such as a 403 or a 404, is a
tool result with isError: true and the OperationOutcome in it, so the agent can read it. A missing or
invalid argument, or an unknown tool, is a JSON-RPC error -32602. A response larger than
search.include_limits.max_bytes is refused with the same code: narrow the request.
Package tools
Section titled “Package tools”With mcp.toolbox = true four more tools come from
fhir-toolbox. They answer from the packages in
packages.load, read again in memory at start; until that is done they are not listed.
| Tool | Arguments | What |
|---|---|---|
find_profiles |
query, type, limit |
Profiles by name, title or URL, of one resource type |
find_extensions |
query, context, limit |
Extensions, by where they may be used |
describe_profile |
profile |
The elements a profile constrains, flat |
run_view |
view, resources |
A ViewDefinition over resources given in the call, not over stored data |
They do not go through the HTTP stack: they read no stored data, so access policies have
nothing to decide. Validation and FHIRPath stay with validate_resource and evaluate_fhirpath
above, over this server’s own definitions.
Writes
Section titled “Writes”write_resource exists only with mcp.allow_writes = true. It sends one transaction to POST /fhir, under
the caller’s token, so the token needs write access to the resource type, Device and Provenance. A
resource with an id is a PUT, one without is a POST. The transaction records, per the AI Transparency
IG:
| Entry | What it holds |
|---|---|
| The resource | The AIAST label (Artificial Intelligence asserted, from v3-ObservationValue) added to meta.security |
Device |
Profile AI-Device, type Artificial-Intelligence, identifier urn:octofhir:mcp-client with the client’s name. Created only if it does not exist, so a client keeps one Device. |
Provenance |
Profile AI-Provenance, targeting the resource, with recorded, reason AIAST, and the Device as author |
The client’s name comes from the client_id claim of the token, or sub, and is unknown if neither can be
read. It is only a label: the token is checked when the transaction runs.