内容
# 家谱 MCP 服务器
<p align="center">
<img src="logo.png" alt="家谱生成器" width="128">
</p>
<p align="center">
<a href="https://lobehub.com/mcp/zzgael-pedigree-mcp"><img src="https://lobehub.com/badge/mcp/zzgael-pedigree-mcp" alt="MCP 徽章"></a>
<a href="https://github.com/zzgael/pedigree-mcp/actions/workflows/ci.yml"><img src="https://github.com/zzgael/pedigree-mcp/actions/workflows/ci.yml/badge.svg" alt="持续集成"></a>
<a href="https://www.npmjs.com/package/pedigree-mcp"><img src="https://img.shields.io/npm/v/pedigree-mcp.svg" alt="npm 版本"></a>
<a href="https://www.npmjs.com/package/pedigree-mcp"><img src="https://img.shields.io/npm/dm/pedigree-mcp.svg" alt="npm 下载量"></a>
<a href="https://github.com/zzgael/pedigree-mcp/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/pedigree-mcp.svg" alt="许可证"></a>
<a href="https://pubmed.ncbi.nlm.nih.gov/18792771/"><img src="https://img.shields.io/badge/Bennett%202008%2F2022-100%25%20Compliant-brightgreen.svg" alt="Bennett 标准"></a>
</p>
<p align="center">
一个用于生成家谱树图的 MCP(模型上下文协议)服务器,使用标准的遗传符号,按照 <a href="https://onlinelibrary.wiley.com/doi/full/10.1007/s10897-008-9169-9">Bennett 2008/2022 NSGC 指南</a>。
</p>
<p align="center">
<img src="example.png" alt="家谱示例" width="700">
</p>
<p align="center">
<em>BRCA1 遗传性乳腺癌/卵巢癌家族史,展示:3 代,受影响个体合并病症,MZ 同卵双胞胎,携带者状态,死亡指标,家系核心成员 + 咨询者标记,基因检测结果(BRCA1+/BRCA1-)</em>
</p>
## 安装
将以下内容添加到您的 MCP 客户端配置中(例如 Claude Desktop):
```json
{
"mcpServers": {
"pedigree": {
"command": "npx",
"args": ["pedigree-mcp"],
"env": {}
}
}
}
```
### 从源代码构建
如果您更喜欢从源代码构建:
```bash
git clone https://github.com/zzgael/pedigree-mcp.git
cd pedigree-mcp
npm install
npm run build
```
然后在您的 MCP 客户端配置中使用:
```json
{
"mcpServers": {
"pedigree": {
"command": "node",
"args": ["/absolute/path/to/pedigree-mcp/dist/index.js"],
"env": {}
}
}
}
```
## 功能
### Bennett 2008 标准合规
本实现遵循 [NSGC 标准化人类家谱命名法](https://pubmed.ncbi.nlm.nih.gov/18792771/):
| 符号 | 描述 | 属性 |
|--------|-------------|----------|
| 方形 | 男性 | `sex: "M"` |
| 圆形 | 女性 | `sex: "F"` |
| 菱形 | 未知性别 | `sex: "U"` |
| 填充形状 | 受影响个体 | `conditions: [...]` |
| 对角线 | 已故 | `status: 1` |
| 箭头(左下) | 家系核心成员 | `proband: true` |
| 双箭头(左下) | 咨询者(寻求咨询的人) | `consultand: true` |
| 括号 [ ] | 领养 | `noparents: true` |
| 双线 | 血缘关系 | 自动从共享祖先检测 |
| 双线上的文本 | 血缘关系程度 | `consanguinity_degree: "1st cousins"` |
| 水平条 | MZ(同卵)双胞胎 | `mztwin: "group_id"` |
| 对角线 | DZ(异卵)双胞胎 | `dztwin: "group_id"` |
| 中心点 | 携带者状态 | `carrier: true` |
| 外框点 | 必定携带者(推断) | `obligate_carrier: true` |
| 符号内"P" | 怀孕 | `pregnant: true` |
| "P" + 周数标签 | 怀孕持续时间 | `pregnant: true, terminated_age: 12` |
| 小三角形 | 早期妊娠丢失(<20 周) | `terminated: true, terminated_age: 8` |
| 大三角形 | 死胎(≥20 周) | `terminated: true, terminated_age: 24` |
| 符号下"EP" | 异位妊娠 | `ectopic: true` |
| 交叉线(X) | 不孕不育 | `infertility: true` |
| 线条上的哈希标记 | 离婚/分居 | `divorced: true` |
| 后代线条 | 自愿不生孩子 | `no_children_by_choice: true` |
| 右上角"A" | 阿什肯纳兹血统 | `ashkenazi: 1` |
| 左上角 "*" | 基因预期 | `anticipation: true` |
| "d. XXy" 标签 | 死亡年龄(自动计算) | `yob: 1950, yod: 2020, status: 1` |
| 箭头 + "OUT" 标签 | 领养 OUT(被送养) | `adoption_type: "out"` |
| 虚线括号 | 寄养(临时) | `adoption_type: "foster"` |
| 罗马数字 I, II, III | 兄弟姐妹出生顺序 | `birth_order: 1`(显示为"I") |
| "E" 标记(蓝色) | ART - 卵子捐赠受孕 | `art_type: "egg_donor"` |
| "S" 标记(蓝色) | ART - 精子捐赠受孕 | `art_type: "sperm_donor"` |
| "Em" 标记(蓝色) | ART - 胚胎捐赠受孕 | `art_type: "embryo_donor"` |
| "GC" 标记(蓝色) | ART - 代孕(代理母亲) | `art_type: "surrogate"` |
| "SAB" 标签 | 妊娠结果 - 自发流产 | `pregnancy_outcome: "miscarriage"` |
| "TOP" 标签 | 妊娠结果 - 终止妊娠 | `pregnancy_outcome: "induced_termination"` |
| "SB" 标签 | 妊娠结果 - 死胎 | `pregnancy_outcome: "stillbirth"` |
| "Het" 标签(绿色) | 基因拷贝数 - 杂合子 | `gene_copy_number: "heterozygous"` |
| "Hom" 标签(绿色) | 基因拷贝数 - 纯合子 | `gene_copy_number: "homozygous"` |
| "CH" 标签(绿色) | 基因拷贝数 - 复发杂合子 | `gene_copy_number: "compound_heterozygous"` |
| 虚线伴侣线 | 未婚/同居伴侣 | `relationship_type: "unmarried"` |
### 病症(Bennett 标准 - 自由文本)
按照 Bennett 2008 标准,病症使用 **自由文本** 记录。只需提供一个包含任何疾病/病症名称的 `conditions` 数组:
```json
{
"conditions": [
{ "name": "乳腺癌", "age": 42 },
{ "name": "卵巢癌", "age": 55 }
]
}
```
**示例:**
- `{ "name": "亨廷顿病", "age": 45 }`
- `{ "name": "2 型糖尿病" }`(无年龄 = 仅受影响状态)
- `{ "name": "囊性纤维化" }`
- `{ "name": "遗传性血色病", "age": 38 }`
**颜色自动从基于唯一病症名称的调色板中分配**。多个病症显示为象限(男性)或饼图(女性)。
### 基因检测结果
支持 **任何基因** - 使用模式 `{gene}_gene_test`:
```json
{
"brca1_gene_test": { "type": "T", "result": "P" },
"htt_gene_test": { "type": "T", "result": "P" },
"apoe_gene_test": { "type": "S", "result": "N" }
}
```
基因检测结果代码:
- **type**: `T`(已检测),`S`(筛查),`-`(未知)
- **result**: `P`(阳性),`N`(阴性),`-`(未知/变异体)
标签显示为:`BRCA1+`(阳性),`HTT-`(阴性)
## 工具
### `get_pedigree_documentation`
返回有关家谱数据格式的综合文档。**在生成家谱之前始终调用此函数**。
### `generate_pedigree`
生成 PNG 或 SVG 格式的家谱树。
**参数:**
| 参数 | 类型 | 默认值 | 描述 |
|-----------|------|---------|-------------|
| `dataset` | `Individual[]` | 必需 | 家族成员数组 |
| `width` | `number` | 800 | 图像宽度(像素) |
| `height` | `number` | 600 | 图像高度(像素) |
| `symbol_size` | `number` | 35 | 节点直径(像素) |
| `background` | `string` | #ffffff | 背景颜色 |
| `labels` | `string[]` | ['age'] | 要显示的属性 |
| `format` | `'png' \| 'svg'` | 'png' | 输出格式:png(base64 图像)或 svg(XML 文本) |
## 数据格式
### 个体对象
```typescript
interface Individual {
// 必需
name: string; // 唯一 ID(最多 7 个字符)
sex: "M" | "F" | "U"; // 男性,女性,未知
// 身份
display_name?: string; // 用于显示的人性化名称(最多 13 个字符)
top_level?: boolean; // 创始人(无父母)
proband?: boolean; // 家系核心成员
// 关系
mother?: string; // 母亲的名字(必须存在于数据集中)
father?: string; // 父亲的名字(必须存在于数据集中)
// 人口统计
age?: number; // 当前年龄
yob?: number; // 出生年份
status?: number; // 0 = 存活,1 = 已故
// 双胞胎(Bennett 标准)
mztwin?: string; // MZ 双胞胎组 ID(同卵)
dztwin?: string; // DZ 双胞胎组 ID(异卵)
// 特殊指标(Bennett 标准)
carrier?: boolean; // 携带者状态(中心点)
pregnant?: boolean; // 当前怀孕(符号内"P")
terminated?: boolean; // 死胎/流产(小三角形)
divorced?: boolean; // 与伴侣离婚(哈希标记)
noparents?: boolean; // 领养(符号周围的括号)
// 病症(Bennett 标准 - 自由文本)
conditions?: Array<{
name: string; // 任何病症: "乳腺癌", "亨廷顿病", 等
age?: number; // 诊断/发病年龄
}>;
// 基因检测(模式:{gene}_gene_test)
brca1_gene_test?: { type: "-"|"S"|"T", result: "-"|"P"|"N" };
brca2_gene_test?: { type: "-"|"S"|"T", result: "-"|"P"|"N" };
// ... 任何基因检测
}
```
## 示例
**📸 [查看所有 21 个场景示例 →](EXAMPLES.md)**
查看标准家谱场景的完整图库,演示 Bennett 2008/2022 合规性,包括性别多样性、双胞胎、血缘关系、ART 指标和复杂的多代家庭。
### 基本三代家谱
```json
[
{"name": "MGF", "sex": "M", "top_level": true},
{"name": "MGM", "sex": "F", "top_level": true, "conditions": [{"name": "乳腺癌", "age": 55}]},
{"name": "Mother", "sex": "F", "mother": "MGM", "father": "MGF", "conditions": [{"name": "乳腺癌", "age": 42}]},
{"name": "Father", "sex": "M", "top_level": true},
{"name": "Proband", "display_name": "Sarah", "sex": "F", "mother": "Mother", "father": "Father", "proband": true, "age": 25, "brca1_gene_test": {"type": "T", "result": "P"}}
]
```
### 神经系统疾病家谱
```json
[
{"name": "GF", "sex": "M", "top_level": true, "status": 1, "conditions": [{"name": "亨廷顿病", "age": 52}]},
{"name": "GM", "sex": "F", "top_level": true},
{"name": "Father", "sex": "M", "mother": "GM", "father": "GF", "conditions": [{"name": "亨廷顿病", "age": 48}]},
{"name": "Mother", "sex": "F", "top_level": true},
{"name": "Proband", "sex": "M", "mother": "Mother", "father": "Father", "proband": true, "age": 25, "carrier": true}
]
```
### 双胞胎示例
```json
[
{"name": "Dad", "sex": "M", "top_level": true},
{"name": "Mom", "sex": "F", "top_level": true},
{"name": "Twin1", "sex": "M", "mother": "Mom", "father": "Dad", "mztwin": "mz1"},
{"name": "Twin2", "sex": "M", "mother": "Mom", "father": "Dad", "mztwin": "mz1"},
{"name": "DZTwin1", "sex": "M", "mother": "Mom", "father": "Dad", "dztwin": "dz1"},
{"name": "DZTwin2", "sex": "F", "mother": "Mom", "father": "Dad", "dztwin": "dz1"}
]
```
### 具有 Bennett 功能的复杂家庭
```json
[
{"name": "GF", "sex": "M", "top_level": true, "status": 1},
{"name": "GM", "sex": "F", "top_level": true, "carrier": true},
{"name": "Father", "sex": "M", "mother": "GM", "father": "GF", "divorced": true},
{"name": "Mother", "sex": "F", "top_level": true},
{"name": "Child1", "sex": "F", "mother": "Mother", "father": "Father", "proband": true, "noparents": true},
{"name": "Loss", "sex": "U", "mother": "Mother", "father": "Father", "terminated": true}
]
```
## 开发
```bash
# 安装依赖
npm install
# 以开发模式运行(监听)
npm run dev
# 运行所有测试
npm test
# 构建生产版本
npm run build
# 类型检查
npx tsc --noEmit
```
## 测试
- **159 个测试**,涵盖:
- 验证(父引用,性别约束)
- SVG 渲染(所有符号类型,指标)
- 病症标记和多病症饼图
- 基因检测格式化
- 双胞胎渲染(MZ 带条,DZ 不带)
- 血缘关系检测
- Bennett 2008 合规性(携带者,怀孕,终止,离婚)
- 边缘情况(深家谱,宽世代,半兄弟姐妹)
## 参考
- [Bennett 等人 2008 - 标准人类家谱命名法](https://pubmed.ncbi.nlm.nih.gov/18792771/)
- [Bennett 等人 2022 - 性别和性别包容性更新](https://pubmed.ncbi.nlm.nih.gov/36106433/)
- [爱荷华州人类遗传学 - 如何绘制家谱](https://humangenetics.medicine.uiowa.edu/resources/how-draw-pedigree)
## 许可证
MIT 许可证 - 请参阅 [LICENSE](LICENSE)