尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

MCP Toolbox cloud-healthcare 预置配置详解:为 LLM 接入 Google Cloud Healthcare API 的 15 个 FHIR/DICOM 工具

MCP Toolbox cloud-healthcare 预置配置详解:为 LLM 接入 Google Cloud Healthcare API 的 15 个 FHIR/DICOM 工具 MCP Toolbox cloud-healthcare 预置配置详解为 LLM 接入 Google Cloud Healthcare API 的 15 个 FHIR/DICOM 工具【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox本篇指南基于 MCP Toolbox for Databases 仓库中的cloud-healthcare预置配置prebuilt config文档展开讲清楚如何通过一条--prebuilt cloud-healthcare命令为 LLM Agent 挂载访问 Google Cloud Healthcare API 的 15 个只读工具涵盖数据集元数据、FHIR 资源检索、DICOM 影像搜索与渲染并逐层剖析源码中的凭据解析、store 白名单校验、FHIR 翻页 URL 安全校验等关键实现读完即可在自己的 MCP 部署中直接复用该配置并理解其安全边界。预置配置是什么--prebuilt cloud-healthcareMCP Toolbox 支持预置工具配置prebuilt tools configuration不需要手写kind: sourcekind: tool的 YAML直接用--prebuilt传入一个由 source 类型决定的名字即可加载对应的一组工具。Cloud Healthcare API 集成对应的--prebuilt值为cloud-healthcare例如./toolbox --prebuilt cloud-healthcare--prebuilt还支持通过source/toolset后缀只加载其中某一个工具集toolsetCloud Healthcare 预置配置定义了三个 toolset因此可以写成# 只加载 FHIR 相关工具 ./toolbox --prebuilt cloud-healthcare/cloud_healthcare_fhir_tools需要说明的前提预置配置面向的是构建期场景agent 协助受信任的开发者搭建工具官方文档明确提示其安全性不足以支撑运行期场景agent 可能面对不受信任的调用方。预置配置展开后的完整 YAML 定义在 internal/prebuiltconfigs/tools/cloud-healthcare.yaml 中其 source 部分等价于kind: source name: healthcare-source type: cloud-healthcare project: ${CLOUD_HEALTHCARE_PROJECT} region: ${CLOUD_HEALTHCARE_REGION} dataset: ${CLOUD_HEALTHCARE_DATASET} useClientOAuth: ${CLOUD_HEALTHCARE_USE_CLIENT_OAUTH:false}可以看到预置配置通过环境变量注入连接参数useClientOAuth缺省为false。环境变量与 IAM 权限要求环境变量预置配置cloud-healthcare使用以下环境变量环境变量必填说明CLOUD_HEALTHCARE_PROJECT是GCP 项目 IDCLOUD_HEALTHCARE_REGION是Cloud Healthcare API 数据集所在区域CLOUD_HEALTHCARE_DATASET是Cloud Healthcare API 数据集 IDCLOUD_HEALTHCARE_USE_CLIENT_OAUTH否若为true转发客户端的 OAuth access token 用于认证默认falsesource 侧对应的字段定义见 internal/sources/cloudhealthcare/cloud_healthcare.gotype Config struct { // Healthcare configs Name string yaml:name validate:required Type string yaml:type validate:required Project string yaml:project validate:required Region string yaml:region validate:required Dataset string yaml:dataset validate:required AllowedFHIRStores []string yaml:allowedFhirStores AllowedDICOMStores []string yaml:allowedDicomStores UseClientOAuth bool yaml:useClientOAuth }预置配置只暴露了 project/region/dataset/useClientOAuth 四个环境变量allowedFhirStores与allowedDicomStores是 source 的可选字段用于把工具可访问的 store 限制在指定列表内详见下文store 白名单一节手写 YAML 时可利用预置配置则不开放。两种认证方式默认ADCToolbox 使用 Application Default Credentials 调用google.FindDefaultCredentials(ctx, healthcare.CloudHealthcareScope)获取默认凭据并构造healthcare.Service要求凭据具备 Cloud Healthcare API 的 OAuth scope。客户端 OAuthuseClientOAuth: trueToolbox 改为从工具调用请求的Authorization头中解析 Bearer token以调用者身份代其查询 Cloud Healthcare APIon-behalf-of 认证。各工具在Invoke中通过accessToken.ParseBearerToken()取 token例如 cloudhealthcaregetdataset。采用此方式时最终执行查询的身份必须被授予相应 IAM 权限。IAM 角色执行预置配置中的工具需要为认证身份授予角色说明Healthcare FHIR Resource Readerroles/healthcare.fhirResourceReader读取与搜索 FHIR 资源Healthcare DICOM Viewerroles/healthcare.dicomViewer从 DICOM store 检索 DICOM 影像工具全集15 个工具与 3 个 toolset预置配置定义了 15 个工具完整定义见 internal/prebuiltconfigs/tools/cloud-healthcare.yaml并按用途划分为三个 toolsettoolset包含工具cloud_healthcare_dataset_toolsget_dataset、list_dicom_stores、list_fhir_storescloud_healthcare_fhir_toolsget_fhir_store、get_fhir_store_metrics、get_fhir_resource、fhir_patient_search、fhir_patient_everything、fhir_fetch_pagecloud_healthcare_dicom_toolsget_dicom_store、get_dicom_store_metrics、search_dicom_studies、search_dicom_series、search_dicom_instances、retrieve_rendered_dicom_instance数据集类工具工具类型tool type功能get_datasetcloud-healthcare-get-dataset获取数据集详情无参数list_dicom_storescloud-healthcare-list-dicom-stores列出数据集中的 DICOM store受allowedDicomStores过滤list_fhir_storescloud-healthcare-list-fhir-stores列出数据集中的 FHIR store受allowedFhirStores过滤get_dataset的实现非常直接GetDataset 用projects/{project}/locations/{region}/datasets/{dataset}命名调用svc.Projects.Locations.Datasets.Get。列表工具在返回前会按白名单过滤见 ListFHIRStores。FHIR 类工具工具功能关键参数get_fhir_store获取指定 FHIR store 的详情storeIDget_fhir_store_metrics获取 FHIR store 的指标数据storeIDget_fhir_resource从 FHIR store 读取一个 FHIR 资源storeID、资源类型、资源 IDfhir_patient_search按条件搜索 Patient 资源storeIDfhir_patient_everything检索与指定患者相关的全部资源FHIR$everythingstoreID、patientIDfhir_fetch_page拉取 FHIR 搜索结果的某一页_pageToken翻页FHIR 分页 URL其中两个有代表性的 source 层实现fhir_patient_everything拼接.../fhirStores/{store}/fhir/Patient/{patient}/$everything并调用Fhir.PatientEverything见 FHIRPatientEverything。fhir_patient_search以{ResourceType: Patient}作为搜索体调用Fhir.SearchType见 FHIRPatientSearch。fhir_fetch_page是 15 个工具里安全处理最重的一个后面单独展开。DICOM 类工具工具功能检索参数DICOM 标签get_dicom_store获取 DICOM store 详情storeIDget_dicom_store_metrics获取 DICOM store 指标storeIDsearch_dicom_studies按条件搜索检查Study见下方参数说明search_dicom_series按条件搜索序列Series同上search_dicom_instances按条件搜索实例Instance同上retrieve_rendered_dicom_instance获取渲染后的 DICOM 实例JPEGBase64 编码返回storeID、study、series、sopInstanceUID、frame以search_dicom_studies为例cloudhealthcaresearchdicomstudies.go其参数集合为参数类型说明StudyInstanceUIDstring检查的 UIDPatientNamestring患者姓名PatientIDstring患者 IDAccessionNumberstring检查的申请编号ReferringPhysicianNamestring申请医生姓名StudyDatestring检查日期格式YYYYMMDD也支持范围YYYYMMDD-YYYYMMDDfuzzymatchingbool默认false患者姓名模糊匹配对查询值与存储值做分词归一化任一查询 token 是任一存储 token 的前缀即命中如PatientNameJohn^Doe时jo、Do、John Doe均可匹配ohn不匹配includefieldstring 数组需要在响应中额外返回的 attributeIDDICOM tag 或关键字设为[all]返回全部 tagstoreIDstring目标 DICOM store ID若 source 只锁定一个 store 则自动省略该参数这些检索条件如何变成真正的 API 查询参数由 common/util.go 中的ParseDICOMSearchParameters统一处理includefield数组被逗号连接后作为查询参数fuzzymatching转成布尔字符串其余按 key 透传。source 层的 SearchDICOM 再根据 tool type 分发到SearchForInstances/SearchForSeries/SearchForStudies三个 DICOMweb 端点。retrieve_rendered_dicom_instance的 source 实现见 RetrieveRenderedDICOMInstance请求studies/{study}/series/{series}/instances/{sop}/frames/{frame}/rendered端点Accept: image/jpeg把 JPEG 响应体 Base64 编码后返回给模型方便多模态 Agent 直接看影像。源码纵览认证、白名单与 FHIR 翻页 URL 校验启动时的存在性校验cloud-healthcaresource 在init()中向 sources 注册表 注册类型名Initialize阶段cloud_healthcare.go#L83-L143会做三件事用projects/.../datasets/{dataset}调一次FhirStores.Get验证数据集存在不存在则报dataset %s not found逐一验证allowedFhirStores中每个 store 存在逐一验证allowedDicomStores中每个 store 存在。store 白名单如何在运行时生效运行时所有带storeID参数的工具先经过 ValidateAndFetchStoreID若 source 只允许一个 store则直接返回该 store并省略工具 schema 里的storeID参数若允许多个则校验调用方传入的storeID必须在白名单内否则报store ID %s is not in the list of allowed stores。列表类工具在结果集层面过滤ListFHIRStores 只保留Name末尾 ID 命中白名单的条目。这套机制意味着即使 Agent 幻觉出一个不存在的 store ID也会在到达 GCP 之前被拒绝。fhir_fetch_page的 URL 安全校验fhir_fetch_page接收的是 FHIR 搜索结果响应里的下一页 URL属于用户可控的完整 URL因此 validateFHIRPageURL 做了严格的逐段校验协议必须是httpshost 必须在白名单内源码中仅允许healthcare.googleapis.com与healthcare.mtls.googleapis.com两个 host见 allowedFHIRHosts防止 SSRF路径必须形如v{N}/projects/{project}/locations/{region}/datasets/{dataset}/fhirStores/{store}/fhir/...且 project、region、dataset 必须与 source 配置一致FHIR store 还必须通过白名单校验重定向同样受约束FHIRFetchPage 给httpClient.CheckRedirect挂了同一个校验函数并限制最多 10 次跳转。认证客户端的选择也在此方法内完成useClientOAuth为true时用客户端 Bearer token 构造oauth2.NewClient否则用google.DefaultClientADC。与手写配置的对应关系如果不用--prebuilt等价的手写 source 配置如下摘自 source.mdADC 方式kind: source name: my-healthcare-source type: cloud-healthcare project: my-project-id region: us-central1 dataset: my-healthcare-dataset-id # allowedFhirStores: # Optional: Restricts tool access to a specific list of FHIR store IDs. # - my_fhir_store_1 # allowedDicomStores: # Optional: Restricts tool access to a specific list of DICOM store IDs. # - my_dicom_store_1 # - my_dicom_store_2客户端 OAuth 方式则加useClientOAuth: true。source 的完整字段参考表含allowedFhirStores、allowedDicomStores、useClientOAuth的语义说明见 source.md 的 Reference 一节每个工具的独立文档位于 docs/en/integrations/cloudhealthcare/tools/。适用前提与限制预置配置假设 GCP 环境中已存在目标 project/region/datasetsource 启动即校验存在性配置错误会在启动阶段直接失败而非运行期暴露。全部 15 个工具均为读取/检索语义数据集信息、store 列表、FHIR 资源读取与搜索、DICOM 搜索与渲染预置配置不提供写入类工具。useClientOAuth依赖调用方在请求中携带有效 Bearer token缺 token 时工具会以 401 类错误返回见各工具Invoke中ParseBearerToken的失败分支。--prebuilt定位为构建期快捷方式面向运行期、需要细粒度权限控制的部署建议改用手写 YAML 配合allowedFhirStores/allowedDicomStores白名单。相关文件索引文件说明internal/prebuiltconfigs/tools/cloud-healthcare.yamlcloud-healthcare预置配置完整定义source 15 工具 3 toolsetinternal/sources/cloudhealthcare/cloud_healthcare.gosource 实现认证、白名单、FHIR 翻页 URL 校验internal/tools/cloudhealthcare/common/util.gostoreID 校验与 DICOM 检索参数解析internal/tools/cloudhealthcare/15 个工具各自的实现与测试docs/en/integrations/cloudhealthcare/source.mdsource 字段参考与手写配置示例docs/en/reference/cli.md--prebuilt参数与 toolset 后缀语法说明tests/cloudhealthcare/集成测试含 MCP 端到端用例【免费下载链接】mcp-toolboxMCP Toolbox for Databases is an open source MCP server for databases.项目地址: https://gitcode.com/GitHub_Trending/ge/mcp-toolbox创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表