Exposing HAPI FHIR to AI agents through its MCP endpoint

The HAPI FHIR JPA starter can expose an MCP endpoint for AI agents, but it ships with no security or enterprise logging, so authorization, audit and data minimization come first.

On this page

What the HAPI FHIR MCP endpoint does and when teams need it

A team that wants AI agents to query FHIR data held in a HAPI FHIR server can get an MCP endpoint from the JPA server starter by setting spring.ai.mcp.server.enabled to true. With that setting, the starter exposes a default endpoint at /mcp/messages over Streamable HTTP, so an MCP-capable agent client can connect to the server and call the tools the starter provides. The switch itself is a single configuration key, but it changes who and what can reach your clinical data, so it should be treated as a change to the access surface of the server, not as a feature toggle. Teams usually need this when agents such as internal assistants or coding tools are expected to answer questions over patient, encounter or observation data that already lives in a HAPI FHIR repository.

The starter ships with no security implementation and no enterprise logging. Its README states that both must be supplied, or professional support obtained, before production use. In practice, that means the endpoint should not be exposed to any network or user population until someone has decided how each agent authenticates, what FHIR resources and search parameters it may reach, and where its requests are recorded. Confirm with your own security and compliance teams which identity provider will issue the agent's credentials, and which HAPI FHIR building blocks, such as the AuthorizationInterceptor and BALP audit logging, will enforce those decisions. The HAPI FHIR security documentation describes these as building blocks rather than a finished layer, so the design work falls to the operator.

Before enabling the setting in any shared environment, run a short review with the people who own the FHIR data, the identity platform and audit retention. Ask who the agent acts for, whether it should see the same records as the user it represents, and which data it has no reason to receive at all. Then check whether the MCP endpoint is reachable only through the paths you intend, and whether it is covered by the same logging and monitoring as the rest of the API. The sections that follow cover those controls in order. Treat the starter's default as a starting point for a lab, and complete these decisions before any clinical or production data is connected.

Where authorization, audit and minimization sit in the agent request path

The request starts at an AI agent client and passes through a reverse proxy or gateway, then an authentication layer, before reaching the MCP endpoint at /mcp/messages. The starter ships with no security implementation, so the trust boundary between the agent side and the HAPI FHIR JPA server is where authorization, consent and search narrowing must be enforced in the server's interceptors. Check that every MCP tool call passes through the same interceptors as REST requests, and that audit events from the server and proxy reach a sink your team controls before any agent is connected.

Trust boundaries and control points for agent requests to the MCP endpoint.

Configuration options for MCP exposure and when each fits

This table compares four ways to expose the MCP endpoint that the JPA server starter enables with spring.ai.mcp.server.enabled at the default /mcp/messages path. Read each row as a decision: when the option fits and what remains open for your team to close before any agent connects. The main takeaway is that enabling the flag alone leaves authentication, authorization and logging unresolved, so production use needs controls around the endpoint.

OptionWhen it fitsWhat it leaves open
MCP disabled (flag left off)Production instances where no agent use case is approved yet, and any environment handling live patient data without a reviewed access designNo agent access at all, so teams needing AI querying must use another path. Confirm the flag is unset in every deployed profile, including Helm values and container environment variables
MCP enabled on a development instance onlyBuild and evaluation work with synthetic or de-identified data, used to learn tool behavior and test promptsThe starter ships with no security implementation and no enterprise logging. Keep the instance off production networks and never load real records into it
MCP enabled behind a gateway with an identity providerProduction use where agents must authenticate as named users or services and every call passes through a controlled entry pointThe gateway protects the route, not the data. You still need HAPI FHIR authorization rules, search narrowing, audit logging and data minimization for what each identity may read
MCP enabled and restricted to internal networksOrganizations that need agents reachable from approved internal hosts only, often combined with the gateway optionInternal reachability does not stop misuse by a compromised workstation or an over-permissioned service account. Confirm network policies, ingress rules and who can reach the /mcp/messages path

Authorization, audit and data minimization to add first

The MCP endpoint inherits whatever the JPA server exposes, and the starter ships with no security implementation or enterprise logging. HAPI FHIR provides building blocks rather than one security layer, so the operator must design the agent access policy: who the agents are, what they may read, what gets logged and what leaves the server.

Authenticate every agent client

Put the MCP endpoint behind an authentication interceptor so each request maps to a named identity, not a shared service account. Decide whether agents act as their own users, as a dedicated agent principal, or on behalf of a delegated user, because that choice determines every later permission check. Confirm how the starter's Streamable HTTP endpoint at /mcp/messages passes tokens through your reverse proxy and how revocation works when an agent is retired.

HAPI FHIR security docs

Scope access with AuthorizationInterceptor

Use the AuthorizationInterceptor to define, per agent identity, which resource types and operations are allowed, such as read-only access to a limited set of resources. Write rules for the MCP path as well as the REST path, and test that a tool call cannot reach a resource the identity cannot read through the regular API. Treat default-deny as the starting point and add permissions only where a specific agent task needs them.

Narrow results with consent and search interceptors

Consent and search narrowing interceptors can restrict which records and search results an identity sees, beyond resource-level rules. This matters when an agent has legitimate access to a resource type but should only see records for a given patient list, organization or purpose. Verify each restriction with search tests, including chained searches and includes, because a query that returns a resource indirectly can bypass a rule written only for direct reads.

Log agent access with BALP

Enable BALP audit logging so every read and search made through the MCP endpoint is recorded with the agent identity, time and resource accessed. Route the events to your enterprise logging system, because the starter's README states that enterprise logging must be supplied before production use. Confirm retention, who can read the audit trail, and how you will reconstruct which records an agent touched during an incident.

Restrict CORS and exposed endpoints

Set CORS to allow only the origins your approved agent clients and web front ends use, rather than leaving the server open to any origin. Review every endpoint the starter serves alongside the MCP path, including metadata, documentation and operation endpoints, and decide which are reachable from agent networks. Keep the MCP endpoint off public networks and confirm that the reverse proxy does not forward paths the policy does not cover.

Limit types, parameters and payload size

Data minimization means deciding which resource types and search parameters agents can reach before any agent is connected. Exclude resource types that carry sensitive data the agent task does not need, and restrict search parameters that enable broad enumeration of patients. Review what the tools return, since a single search can return full resources, and decide whether the agent should receive fewer fields or fewer records per call.

Setting up the MCP endpoint in a non-production HAPI FHIR server

This sequence takes a HAPI FHIR JPA starter from a clean install to an MCP endpoint that is enabled, authenticated, audited and tested with a scoped agent identity. Each step ends with a check you can record before moving on to production planning.

  1. Deploy the JPA starter on a production-grade database

    Your platform or integration team deploys the hapi-fhir-jpaserver-starter in a non-production environment you control, connected to PostgreSQL or Microsoft SQL Server rather than the default embedded H2 database. Use the same database engine you plan to run in production so that schema, storage and connection behavior match later. The starter does not support MySQL, so confirm your database choice against the project README before you build. The step is complete when the server starts cleanly, creates its schema in the chosen database, and answers a basic metadata request at its /metadata CapabilityStatement endpoint.

  2. Enable the MCP server in configuration

    Set spring.ai.mcp.server.enabled to true in the starter configuration and restart the service. Keep this change in version-controlled configuration so the setting is reviewable and reproducible across environments. Record which image or build you deployed, since MCP behavior depends on the starter version you run. The step is complete when the application log shows the MCP server starting without configuration errors and the change is committed to your configuration repository.

  3. Confirm the MCP endpoint responds

    Send a request to the default MCP endpoint at /mcp/messages, which uses Streamable HTTP, from a host inside your test network. Use an MCP client or a simple protocol-level test to confirm the server completes its initialization handshake and lists its tools. Do not treat a successful HTTP response alone as proof, because the check must show that an MCP session works. Note the tool names the server exposes so you can review them in later steps. The step is complete when a client session initializes and the tool list matches what you expect from the starter version you deployed.

  4. Add authentication and authorization

    The security team, working with the platform team, places authentication in front of the MCP endpoint and applies authorization rules that limit which resources and search operations an agent can use. HAPI FHIR provides building blocks such as authentication interceptors and the AuthorizationInterceptor, but it does not supply a single complete security layer, so you must design and configure these controls for your environment. Decide in advance which FHIR resource types and compartments the agent may read, and confirm that the MCP tools respect the same rules as the REST API. The step is complete when an unauthenticated request is refused and a request with a test credential is limited to the resources you approved.

  5. Enable audit logging for MCP and FHIR access

    Turn on audit logging so every agent session and every resource access through MCP leaves a record that your security team can review. HAPI FHIR offers BALP audit logging as a building block, and the starter ships without enterprise logging, so you must choose the log destination and retention with your logging team. Confirm which fields are captured, including the client identity, the resource accessed and the time, and check that the records do not contain data beyond what your policy allows. The step is complete when a test query by the agent appears in the audit destination with the expected identity and resource details.

  6. Test with a scoped agent identity

    Create a dedicated identity for the agent in your identity provider, with the smallest set of permissions needed for the test use case, and run the agent or an MCP client under that identity only. Attempt both permitted and forbidden queries, including broad searches that could return more data than the agent needs, and check that the server limits results as designed. Record the results, any unexpected data exposure and any tool that bypasses the authorization rules. The step is complete when the permitted queries succeed, the forbidden queries are refused, and the audit log matches what you observed.

  7. Plan the production move

    Only after the earlier checks pass, the security, compliance and platform owners write down the decisions still open: identity provider integration, data minimization rules, log retention, network exposure, backup and recovery, and who approves each agent. Ask for professional support or a security review where your policy requires it, since the starter's README states that security and enterprise logging must be supplied before production use. Confirm the production scope in writing before any production configuration changes. The step is complete when a signed-off production plan lists each control, its owner and the evidence that will show it works.

Operational risks once agents can query FHIR data

Once an AI agent can call the MCP endpoint, the agent becomes another client of your FHIR server, with its own failure modes. The cards below cover the risks we see most often in this setup and the control the operator must put in place for each, since the starter ships without a security layer.

Over-broad queries from prompt injection

A document, note or search result the agent reads can carry instructions that push it to run searches it was never asked to run, such as enumerating every Patient in the system. The agent does not know which requests are legitimate, so the server must decide. Own the control at the server: an AuthorizationInterceptor rule that limits each agent identity to specific resource types and compartments, plus search narrowing so a broad query returns only what that identity may see. Test this with planted instructions in fixture data before go-live.

HAPI FHIR security docs

Bulk retrieval of patient data

A single agent session can page through search results and pull large volumes of patient records faster than any human workflow would. Set limits on result counts and on how many calls one identity may make in a window, and decide whether agents may reach resource types that support history or bulk export at all. Confirm with the vendor and in your own testing which search parameters and page sizes the MCP tools accept, because the limits you need may have to be enforced in front of the endpoint.

Credentials in agent configuration

Agent clients store tokens or client secrets in configuration files, environment variables or chat tool settings, and those files are often copied between laptops and repositories. Keep credentials in a secrets manager, issue short-lived tokens per agent, and scope each token to one agent identity. Make sure the endpoint is not reachable without authentication, since the starter's default configuration does not add it. Rotate any credential that appears in a repository, log or ticket.

Personal health information in logs

Request and response bodies from agent sessions can end up in application logs, reverse proxy logs, APM traces and chat transcripts kept by the agent platform. Each copy is a store of personal health information with its own retention. Decide what the server logs, which fields are masked, and how long each log tier is kept, and confirm that the BALP audit trail is configured separately from debug logging. Check the retention settings of any third-party agent platform that stores transcripts.

Audit trail that names no owner

When a record is read through an agent, the audit entry may show only a shared service account, which makes it impossible to say which user prompted the access or why. Require that each agent session carry the identity of the human user who started it, and record both the agent identity and that user in audit events. Assign a named owner for each agent deployment who reviews access logs on a set schedule and can revoke the agent's access.

Questions teams ask before exposing HAPI FHIR to AI agents

How much does it cost to expose HAPI FHIR to AI agents?

The cost depends on how many controls you need around the endpoint, so no single figure applies. Turning on MCP in the starter is a configuration change, but the work that takes time is authorization design, identity integration, audit logging, data minimization and testing. Costs split into one-time work (design, build, testing, documentation) and recurring work (patching the server, reviewing access, rerunning tests after upgrades). Ask any partner for a written quote that lists each control, who builds it, what is tested and what is handed over. A quote should also state which items are excluded.

How long does securing an MCP endpoint on HAPI FHIR take?

Duration depends on your environment more than on the MCP setting itself. Teams with an existing identity provider, a documented FHIR access model and a logging pipeline usually finish faster than teams that must define roles, consent rules and audit requirements first. Plan for separate phases: discovery of what agents should read, identity and access design, implementation in a non-production environment, testing and a controlled release. Confirm the timeline against your own change-control process and any review board that must approve a new access path to patient data.

Can our internal team expose HAPI FHIR to AI agents without a partner?

Yes, if your team has the skills to do it, and many do. The starter ships with no security implementation and no enterprise logging, and its README says both must be supplied, or professional support obtained, before production use. Your team needs people who understand FHIR resource and search models, the HAPI FHIR authorization and audit building blocks, your identity provider, and secure testing of AI tools. Be honest about gaps in those areas. A partner can cover the parts your team lacks, or provide an independent review of the design.

What must our team provide before an implementation starts?

Expect to provide FHIR data model knowledge, access to the identity provider, and a written list of compliance requirements. On the FHIR side, someone must explain which resource types, search parameters and compartments agents may use, and which fields are sensitive. On the identity side, you need administrator access or a named contact for the identity provider, its client configuration, and group or role structures. On the compliance side, bring the obligations your privacy, security and records teams already apply to this data. Agree on who approves access decisions before work begins.

Which controls should we put around the MCP endpoint before enabling it?

Put authentication, authorization and audit logging in place before enabling the endpoint in any shared environment. Authentication confirms the caller, authorization limits which resources and operations are allowed, and audit logging records what was accessed and by whom. HAPI FHIR provides building blocks for these, including authentication interceptors, the AuthorizationInterceptor, consent and search narrowing interceptors and BALP audit logging, but it does not provide a single complete security layer. Data minimization, such as limiting returned fields and resource types, should be designed alongside them. Confirm each control against your own threat model.

What goes wrong when AI agents query FHIR data without limits?

The most common problems are over-broad access, weak audit trails and sensitive data leaving the intended context. An agent with a broad token can search far more patient data than a task needs, and a language model may repeat that data in outputs that other users see. Missing audit logs make it hard to answer who retrieved which records. Test prompt injection, tool permission misuse and credential handling as part of the rollout, since an agent can be steered into requests a user never intended. Each failure mode should map to a specific control and a test.

Does exposing MCP change our compliance obligations?

It does not remove or replace your obligations, but it adds a new access path that auditors and privacy teams will ask about. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications, and independent auditors or certification bodies make those determinations. Ask your compliance lead which regulations and internal policies apply to AI access to clinical data, and document how the endpoint meets them. Confirm the requirements with your legal and privacy teams before rollout.

Limits to confirm in your environment before production

The starter's MCP support is new enough that its behavior should be measured, not assumed. Each card below names one limit to confirm against the upstream README and your own test results before any agent connects to patient data.

Exact MCP tools and resources

Confirm which MCP tools and resources your starter version exposes, and which FHIR resource types, search parameters and operations an agent can reach through them. Coverage can differ from what the REST API allows, so compare the two. Record the list from your running build, because a tool set that changes between releases can widen what an agent sees without any change to your code. Ask the vendor or the README maintainers for the tool list for your exact version.

Starter README

Java and JDK requirements

Check the JDK your chosen HAPI FHIR release requires before you pin a version. The core library and the JPA starter can move to newer Java baselines between releases, and an MCP-enabled build inherits those requirements along with the Spring Boot stack. Confirm the requirement in the versions documentation for the release you deploy, and test the MCP endpoint on the same JDK image that production runs.

Required for 8.2.0
JDK 17
HAPI FHIR versions

Authentication flow support

Determine whether the MCP endpoint honors the authentication and authorization setup you rely on for the REST API, such as bearer tokens from your identity provider. The starter ships without a security implementation, so the endpoint may be reachable by any caller that can reach the network path unless you add controls. Test with a token that has narrow scope and confirm that a denied request is refused on the MCP path as well as on REST.

Behavior behind your reverse proxy

Streamable HTTP sessions depend on headers, timeouts and buffering that your reverse proxy or API gateway may alter. Confirm that session identifiers survive the proxy, that long-lived streams are not cut by idle timeouts, and that the path /mcp/messages is routed only where you intend. Verify that the forwarded client address and authentication headers reach the server, since your audit trail depends on them.

Client transport compatibility

Each MCP client your teams use must speak Streamable HTTP as the starter exposes it. Some clients support only older transports, so an agent tool may appear to connect while failing on the first call. Test every client in your approved list against your deployed endpoint, record the client version, and note any client that needs a bridge or a different configuration before you add it to the rollout.

Logging and data exposure in tests

Run a test session and review what the server logs, including tool arguments, returned FHIR payloads and identifiers. The starter does not provide enterprise logging, so default logs may capture patient data or be incomplete for audit. Confirm where logs are written, who can read them, and how long they are kept before any real records are queried through an agent.

What evidence the security and compliance team will ask for

DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies make those judgments. For an MCP endpoint on a HAPI FHIR server, the reviewer's question is usually narrower than whether the platform is compliant: can the operator show who or what reached patient data through the agent, under which rules, and what was returned. The operator owns the answers to that question, and the evidence has to be produced from the operator's own configuration, logs and test records.

Expect reviewers to ask for four artifacts. The first is the access rule set in force for the agent identity: the AuthorizationInterceptor configuration, the scopes or roles granted to the agent's credentials, and the authentication interceptor that issues or validates them. The second is the audit trail, showing each MCP tool call tied to a named principal, with the resources read and the time, retained for a period your policy sets. The third is data minimization test results: evidence that the agent sees only the resource types, search parameters and fields it needs, demonstrated by running the agent's typical and adversarial queries against a non-production copy. The fourth is the agent threat model, covering prompt injection through returned FHIR content, over-broad tool use and credential exposure in agent memory or logs. Confirm with your security team which of these they already have a template for, because the threat model often needs the most work.

How DeployOpen scopes and delivers an MCP-enabled HAPI FHIR setup

DeployOpen starts with a fixed-scope written agreement that names the agent clients, the FHIR resource types and operations they may reach, the authorization model, the audit destination and the test evidence the client expects at the end. Nothing is built until the client's security, compliance and clinical owners have signed off on that scope. Work is carried out inside the client's own cloud accounts, data centers or private networks, so the HAPI FHIR JPA server, its database, its logs and its credentials stay under the client's control. Because the starter ships with no security implementation and no enterprise logging, the written scope has to state who supplies those pieces, and DeployOpen treats that as the first deliverable rather than an afterthought.

The build then covers the controls the starter leaves open. DeployOpen implements authentication in front of the /mcp/messages endpoint, maps agent identities to roles through the AuthorizationInterceptor and search narrowing, and decides which resource types and fields an agent may read at all. Audit logging is designed so that every agent request can be tied to a named user or service identity, a tool call and a patient context. Credentials for agent clients are scoped, rotated and stored outside the application configuration. Each control is then tested from the agent's side, including prompt injection attempts that try to widen a query, tool misuse, data exposure through search results and credential leakage through prompts or logs.

Retainer support is offered where the client wants it after go-live. Under a retainer, DeployOpen can retest the agent path after HAPI FHIR upgrades or agent client changes, review audit output, and update permissions as new use cases appear. Before signing, ask DeployOpen to name each deliverable, the test evidence format, the retest conditions and who owns the agent client configuration after handover. Your own compliance team will decide what the evidence is worth; DeployOpen prepares the controls and records for that review but does not issue audit reports or certifications.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.