Skip to main content
Glama

Sapphire User MCP Server

一个基于 Python 的 Model Context Protocol (MCP) 服务器,用于将 Sapphire Wellness App 的用户画像数据提供给 AI 助手——包括健康警报、个性化推荐和合作伙伴服务订阅。

公开的工具

工具

描述

begin_user_alerts

由指标阈值触发的健康警报(生命体征异常、活动量过低等)

get_user_commendations

按相关度评分排序的个性化合作伙伴服务推荐

get_user_subscriptions

包含完整服务详情(有效订阅的)

Related MCP server: sapphire-user-mcp

架构

Agent Container
      │  HTTP SSE
      ▼
sapphire-user-mcp:10003
      │
      ├──httpx──▶  User Profile API:8091
      │
      └──httpx──▶  Partner Service API:8085
  • 传输方式 — HTTP SSE:多容器部署所必需(stdio 只在 agent 将 MCP Server 作为子进程启动时才有效)

  • 上游 API — 所有工具均调用 HTTP 上的 REST API,不做直连数据库

  • 框架 — FastMCP,使用 Pydantic v2 response models

项目结构

SAPPHIRE-USER-MCP/
├── sapphire_user/
│   ├── server.py           # FastMCP app + SSE entry point
│   ├── config.py           # Settings (API URLs, HOST, PORT via env)
│   ├── models/             # Pydantic response models
│   │   ├── alerts.py
│   │   ├── recommendations.py
│   │   ├── partner_service.py
│   │   └── subscriptions.py
│   └── tools/              # MCP tool definitions
│       ├── alerts.py
│       ├── recommendations.py
│       └── subscriptions.py
├── pyproject.toml
├── Dockerfile
└── .env.example

前提条件

  • Python 3.11+

  • 一个正在运行的 Sapphire User Particle API(默认:http://localhost:8091)

  • 一个正在运行的 Sapphire Partner Service API(默认:http://localhost:8085)

快速开始

本地开发

# 1. Create and activate a virtual environment
python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS / Linux
source .venv/bin/activate

# 2. Install dependencies
pip install -e .

# 3. Configure environment
cp .env.example .env
# Edit .env — set USER_PROFILE_API_BASE_URL and PARTNER_SERVICE_API_BASE_URL

# 4. Run the server
python -m sapphire_user.server
# Server starts at http://0.0.0.0:8001

容器化(Docker)

# Build the image
docker build -t sapphire-user-mcp .

# Run the container
docker run -p 10003:10003 --env-file .env sapphire-user-mcp

MCP Server 将在 http://localhost:10003/sse 上可用。

如需连接你的 agent 容器,请设置:

MCP_SERVER_URL=http://sapphire-user-mcp:10003/sse

配置

所有配置均从环境变量(或 .env 文件)读取:

变量

默认值

描述

HOST

0.0.0.0

MCP Server 绑定地址

PORT

8001

MCP Server 绑定端口

USER_PROFILE_API_BASE_URL

http://localhost:8091

Sapphire User Profile API 基础 URL

PARTNER_SERVICE_API_BASE_URL

http://localhost:8085

Sapphire Partner 基础 URL

工具参考

所有工具都接受单个 user_email 参数。

参数

类型

描述

user_email

str

用户的邮箱地址(例如 sarah.chen@sapphirewellness.com)

get_user_alerts

从 User Profile API 获取该用户的健康警报。每条警报包含:

  • severity — 警报的紧急级别(例如 critical、warning)

  • category — 触发警报的指标类别

  • alertMessage — 警报的人类可读描述

  • metricName / metricType — 触发阈值的具体指标

get_user_commendations

返回的个性化推荐服务按相关度评分排序。每条推荐包含:

  • relevanceScore — 服务与用户健康画像匹配程度的整数评分

  • partnerService — 服务名称、类别、类型和描述

  • generatedAt — 生成推荐的时间戳

get_user_subscriptions

获取用户当前的活跃服务订阅,并为每条订阅补充来自 Partner Service API 的完整服务详情。包含:

  • partnerServiceId — 注册服务的标识符

  • isActive — 订阅当前是否处于活动状态

  • associationContext — 合同结束日期及其他上下文元数据

  • service_details — 完整服务规格、价格、可用性和合同信息

检查工具

使用 MCP Inspector 浏览工具 schema 并发送测试调用:

npx @modelcontextprotocol/inspector http://localhost:8001/sse

连接到 Claude Desktop

在 claude_desktop_config.json 中添加:

{
  "mcpServers": {
    "sapphire-user": {
      "url": "http://localhost:8001/sse"
    }
  }
}

然后向 Claude 提问:“<sup... training...> 是否有健康警报?” 它将使用所提供的邮箱调用 get_user_alerts。

扩展

添加新工具:

  1. 创建 sapphire_user/models/<name>.py —— 定义 Pydantic response model

  2. 创建 sapphire_user/tools/<name>.py —— 定义 @mcp.tool() 并调用相应的 API

  3. 在 server.py 中注册

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