agentleFS
u9401066u9401066/medical-calc-mcp/.github/copilot-instructions.md

medical-calc-mcp

Copilot instructions4 starsChanged 8 months agoApache-2.0View on GitHub

Medical Calculator MCP Server - 醫學計算工具 MCP 伺服器 為 AI Agent 提供經過驗證的醫學計算工具 位置: src/domain/services/calculators/[specialty]/ 位置: src/domain/services/calculators/__init__.py 位置: src/infrastructure/mcp/handlers/calculators/[specialty].py 關鍵: 使用 Literal + Field 約束參數 位置: tests/test_[specialty].py

The file

Files
copilot-instructions.md

Copilot Instructions for Medical Calculator MCP

Medical Calculator MCP Server - 醫學計算工具 MCP 伺服器 為 AI Agent 提供經過驗證的醫學計算工具

📊 專案概況

指標數值
計算器數量151 (涵蓋 31 個專科)
Unified MCP Tools6 (3 發現工具 + 3 計算工具)
測試數量2073+
測試覆蓋率92%
文獻引用244 PMIDs, 205 DOIs (100% 覆蓋)
架構DDD Onion + FastMCP
Python 版本3.11+
套件管理uv

🛠️ 開發環境

# 安裝依賴
uv sync

# 執行測試
uv run pytest

# 執行型別檢查 (必須通過 --strict)
uv run mypy --no-incremental --strict src tests

# 執行 Lint 檢查
uv run ruff check .

# 計算工具數量
uv run python scripts/count_tools.py

# 計算引用文獻數量
uv run python scripts/count_references.py

# 啟動 MCP 伺服器 (stdio)
uv run python -m src.main

# 啟動 MCP 開發模式
uv run mcp dev src/main.py

# 啟動 REST API
uv run python src/main.py --mode api --port 8080

📁 專案結構

src/
├── domain/           # 核心業務邏輯 (無依賴)
│   ├── entities/     # ScoreResult, ToolMetadata
│   ├── services/     # BaseCalculator, ToolRegistry
│   │   └── calculators/  # 151 個計算器實作
│   ├── validation/   # ParameterValidator, BoundarySpec
│   └── value_objects/    # Unit, Reference, Interpretation
├── application/      # 用例層
│   └── use_cases/    # DiscoveryUseCase, CalculateUseCase
├── infrastructure/   # 基礎設施層
│   ├── mcp/          # MCP Server, Handlers
│   │   └── handlers/ # 按專科分類的 handlers
│   └── api/          # REST API (FastAPI)
└── shared/           # 共用工具

🔧 新增計算器標準流程

1. 建立 Calculator (Domain Layer)

位置: src/domain/services/calculators/[specialty]/

from ..base import BaseCalculator
from ...entities.score_result import ScoreResult
from ...entities.tool_metadata import ToolMetadata
from ...value_objects.reference import Reference
from ...value_objects.tool_keys import LowLevelKey, HighLevelKey, Specialty

class MyCalculator(BaseCalculator):
    @property
    def tool_id(self) -> str:
        return "my_calculator"

    @property
    def metadata(self) -> ToolMetadata:
        return ToolMetadata(...)

    @property
    def references(self) -> list[Reference]:
        return [Reference(citation="...", doi="...", pmid="...", year=2020)]

    def calculate(self, param1: float, param2: str) -> ScoreResult:
        # 實作計算邏輯
        pass

2. 註冊 Calculator

位置: src/domain/services/calculators/__init__.py

3. 建立 MCP Handler

位置: src/infrastructure/mcp/handlers/calculators/[specialty].py

關鍵: 使用 Literal + Field 約束參數

from typing import Annotated, Literal
from pydantic import Field

@mcp.tool()
def calculate_my_tool(
    sex: Annotated[Literal["male", "female"], Field(description="性別 Sex")],
    age: Annotated[int, Field(ge=18, le=120, description="年齡 Age | years")],
) -> dict[str, Any]:
    """🏥 工具名稱: 說明"""
    pass

4. 撰寫測試

位置: tests/test_[specialty].py

🔍 工具發現 API (6 個核心工具)

工具功能
discover(by, value)統一發現入口 (specialty/context/keyword)
get_related_tools(tool_id)圖譜關聯工具
find_tools_by_params(params)反向查詢可用工具
get_tool_schema(tool_id)取得參數規格
calculate(tool_id, params)執行計算
calculate_batch(calculations)批次計算

🏥 專科分類 (26 專科, 128 計算器)

專科數量例子
Critical Care18SOFA, APACHE II, qSOFA, NEWS2, RASS, SIRS
Cardiology11GRACE, CHA₂DS₂-VASc, HAS-BLED, Framingham
Emergency9GCS, Wells DVT/PE, PERC Rule, Shock Index
Anesthesiology8ASA, RCRI, Mallampati, MABL, STOP-BANG
Neurology7NIHSS, ABCD2, Hunt-Hess, ICH Score
Psychiatry7PHQ-9, GAD-7, MADRS, HAM-D
Geriatrics7Barthel, MoCA, MMSE, CFS
Nephrology6CKD-EPI, FENa, Serum Osmolality
Pediatrics6APGAR, PEWS, pSOFA, PIM3
Surgery/Trauma6ISS, TRISS, Caprini VTE, Parkland
Endocrinology6FINDRISC, FRAX
Pain Medicine1MME Calculator
其他36肝臟、肺臟、血液、皮膚等

📋 臨床工作流程範例

敗血症評估

qSOFA → SOFA → RASS → CAM-ICU

術前評估

ASA-PS → RCRI → Mallampati → STOP-BANG

上消化道出血

Glasgow-Blatchford → AIMS65 → Rockall

⚠️ 品質要求

  • 型別: mypy --strict 通過
  • Lint: ruff check 通過
  • 測試: 每個計算器需有單元測試
  • 文獻: 每個計算器需有 PMID/DOI 引用
  • 雙語: Description 需中英雙語

📚 關鍵文件

文件說明
README.md專案完整說明
CONTRIBUTING.md開發標準
ROADMAP.md發展路線圖
docs/DEPLOYMENT.md部署指南

回應風格

  • 使用繁體中文
  • 遵循 DDD 架構原則
  • 確保所有計算器有文獻引用

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.