内容
# 个人健康MCP
从タニタ ヘルスプラネット API获取体组成数据(体重、体脂肪率),并作为MCP工具提供给Claude Desktop等AI代理。
## 设置
### 1. 安装
```bash
pip install -e .
```
### 2. 创建.env文件
```bash
cp .env.example .env
```
编辑.env文件,设置`HEALTH_PLANET_CLIENT_ID`、`HEALTH_PLANET_CLIENT_SECRET`和`HEALTH_PLANET_REDIRECT_URI`。
### 3. 初次认证
```bash
python -m health_mcp.tanita.auth
```
在浏览器中打开显示的URL,点击“允许访问”,然后粘贴重定向URL,.env文件将保存令牌。
### 4. 在Claude Desktop上注册MCP服务器
在`claude_desktop_config.json`中添加以下内容。在`command`中指定venv内Python执行文件的完整路径。
**Windows:**
```json
{
"mcpServers": {
"personal-health": {
"command": "C:/Users/<username>/path/to/personal-health-mcp/venv/Scripts/python.exe",
"args": ["-m", "health_mcp.server"]
}
}
}
```
**macOS / Linux:**
```json
{
"mcpServers": {
"personal-health": {
"command": "/path/to/personal-health-mcp/venv/bin/python",
"args": ["-m", "health_mcp.server"]
}
}
}
```
> 不需要指定`cwd`。服务器将根据`__file__`自动解析项目根目录。
## MCP工具列表
| 工具 | 说明 |
|---|---|
| `get_latest_body_composition` | 获取最新的体重和体脂肪率(最近30天) |
| `get_body_composition` | 获取指定期间(最多92天)的体组成数据 |
| `get_measurements_range` | 确认缓存内数据的时间范围和数据量 |
| `get_profile` | 获取出生日期、身高和性别 |
| `list_available_metrics` | 显示可获取的指标列表 |
## 重新获取个人资料
如果在タニタ应用程序中更改了个人资料信息:
```bash
python -m health_mcp.tanita.auth --reset-profile
```
## 开发
```bash
pip install -e ".[dev]"
pytest # 测试
mypy src # 类型检查
ruff check src # 代码检查
```