Skip to main content
Glama
fhir-patient-consent-mcp-server

fhir-patient-consent-mcp-server

by scollard001

fhir-patient-consent-mcp-server

一个 MCP 服务器,让模型可以询问关于患者、患者的胰岛素泵,以及哪些人已获同意查看这些数据的问题——所有数据都实时来自 FHIR (R4) 数据存储。本服务器不保存任何数据;每一个回答都是一次实时的 FHIR REST 查询。

它是 fhir-consent-service(一个将 Patient/Device/Consent 写入 FHIR 的 Spring Boot API)的配套服务,但与它没有任何代码依赖。本服务器只依赖 FHIR 的传输格式,因此可用于任何 FHIR R4 端点。

工具

工具

用途

find_patient

按 MRN 和/或姓氏查找患者

get_patient

按 FHIR id 获取某位患者的人口学信息

get_patient_devices

列出患者的设备(通过 SNOMED CT 469756000 标记出胰岛素泵)

get_patient_consents

列出患者的数据共享同意(合作方、目的、数据类别、时间段)

check_partner_consent

授权检查:合作方 X 当前是否对患者 Y 拥有有效同意?

Related MCP server: FHIR MCP Server

资源

fhir-chart://{patientId} —— 一个为患者聚合的 JSON“病历”(人口学资料 + 设备 + 有效同意),目的是让宿主应用直接将其附加到上下文中,而不是由模型通过多次工具调用来组装。参见 docs/architecture.md,了解为什么它是一个资源而不是第六个工具。

设置

npm install
npm run build

将其指向一个 FHIR 服务器

export FHIR_BASE_URL=http://localhost:8081/fhir   # default shown
export FHIR_AUTH_TOKEN=...                         # optional bearer token

要获得可供查询的数据,最简单的方法是:运行 fhir-consent-service 的 docker compose up -d(会在 :8081 上启动一个本地 HAPI FHIR JPA 服务器),然后通过它的 REST API 创建患者、设备与同意(consent),再在这里查询同一个数据存储。

直接运行(用于 stdio 测试)

npm run dev

将其注册到 MCP 客户端

对于 Claude Desktop / Claude Code,加入你的 MCP 配置:

{
  "mcpServers": {
    "fhir-patient-consent": {
      "command": "node",
      "args": ["/absolute/path/to/fhir-patient-consent-mcp-server/dist/index.js"],
      "env": {
        "FHIR_BASE_URL": "http://localhost:8081/fhir"
      }
    }
  }
}

先运行 npm run build,确保 dist/index.js 存在。

连接后可以问的示例问题

  • "查找 MRN 为 MRN-778001 的患者。"

  • "患者 123 用的是哪款胰岛素泵?序列号是多少?"

  • "GlucoVue Remote Monitoring 是否已获同意查看患者 123 的设备数据?"

  • "显示患者 123 的完整病历。" (调用 fhir-chart:// 资源)

测试

npm test

单元测试覆盖映射层(src/mappers/*.ts),包括 isConsentActiveForPartner 中的同意授权逻辑——特别是它如何处理已撤销的同意、尚未开始/已过期的时间段,以及开放日期(缺少 end)的时间段,因为这些情况最容易在细节上出错。

本仓库中没有针对真实 FHIR 服务器的集成测试(这一点与使用 Testcontainers 的 fhir-consent-service 不同),因为本服务器没有可写入的数据路径来注入种子数据——它必须依赖那个仓库(或复制其资源创建逻辑)仅仅为了搭建测试夹具。如果这个仓库将来加入了数据种子脚本,届时再补上即可。

注意: 本仓库是在无法访问 npm 注册表的沙箱环境中编写的,因此 npm install / npm run build / npm test 实际上都没有在这里执行过。代码以 @modelcontextprotocol/sdk@^1.12 为目标;如果你所安装的版本中,SDK 的 server.tool(...) / server.resource(...) 签名已改为 registerTool / registerResource,修复方式只是机械性的——请查看 SDK 自带的 README/CHANGELOG。

项目结构

src/
├── index.ts              Server entry point, registers all tools/resources
├── fhirClient.ts          Thin fetch-based FHIR REST client
├── tools/                 One file per MCP tool
├── resources/             One file per MCP resource
├── mappers/                FHIR JSON -> summary objects + consent auth logic
└── util/results.ts        Shared tool-result formatting helpers

安全说明

本服务器不会对 PHI 做任何脱敏处理,只会把 FHIR 服务器返回的内容直接透传。如果要在真实患者数据上部署,请把访问控制放在 FHIR 服务器本身(本服务器会把 FHIR_AUTH_TOKEN 作为 Bearer 令牌转发,但不负责令牌的获取/刷新),并认真考虑哪些内容应当或根本不应当暴露给 MCP 客户端。

许可证

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables LLM-based agents and MCP-compatible clients to query and manipulate clinical data through natural-language prompts by providing full CRUD operations on FHIR resources, document ingestion, semantic search, and LOINC terminology lookup.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables LLM-based agents and MCP-compatible clients to query and manipulate FHIR-compliant clinical data through natural-language prompts, with CRUD operations, document ingestion, semantic search, and terminology lookup.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables LLM-based agents and MCP-compatible clients to query and manipulate clinical data on a FHIR-compliant backend using natural-language prompts, with full CRUD operations, document ingestion, semantic search, and LOINC terminology support.
      -