pathways-mcp-server

pathways-mcp-server

Exposes health segmentation data from the Pathways platform, enabling natural language queries about population segments, metrics, and geographic distributions across countries like Senegal and Kenya.

Category
访问服务器

README

Pathways MCP Server

A Model Context Protocol (MCP) server that exposes the Pathways health segmentation platform as structured tools. Pathways provides woman-centered data and insights to help global health organizations design targeted interventions.

What it does

This server connects to the Pathways Strapi CMS API and provides tools that let Claude (or any MCP client) explore population segmentation data:

Tool Description
list_segmentations Discover available country studies (Senegal, Kenya, Nigeria, etc.)
get_segmentation Full details and segments for a specific study
list_segments Filter segments by vulnerability level or stratum (urban/rural)
get_segment_profile Comprehensive "who are these women?" view with metrics by theme/domain
get_segment_metrics Quantitative indicators for a segment, filterable by health theme
search_variables Search indicators by name, theme, domain, or data type
list_themes_and_domains Reference list of health themes and vulnerability domains
list_regions Sub-national regions for a country
get_geographic_distribution Geographic distribution of segments across regions

Example query this enables: "What is the best way to reach out to women in R4 in Tambacounda to improve family planning outcomes?"

Prerequisites

  • Python 3.10+
  • A Pathways API token (read-only Bearer token for the Strapi CMS)

Installation

cd pathways-mcp-server
python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Configuration

Copy the example env file and add your token:

cp .env.example .env
# Edit .env and set PATHWAYS_API_TOKEN
Variable Default Description
PATHWAYS_API_TOKEN (required) Strapi read-only API token
PATHWAYS_API_URL https://api.staging.withpathways.org Strapi API base URL

Running standalone

PATHWAYS_API_TOKEN=<your-token> python -m pathways_mcp.server

The server communicates over stdio using the MCP protocol. To test interactively, use the MCP Inspector:

npx @modelcontextprotocol/inspector

Using with Claude

Claude Desktop

Add this to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "pathways": {
      "command": "<path-to-repo>/pathways-mcp-server/.venv/bin/python",
      "args": ["-m", "pathways_mcp.server"],
      "cwd": "<path-to-repo>/pathways-mcp-server",
      "env": {
        "PATHWAYS_API_TOKEN": "<your-token>",
        "PATHWAYS_API_URL": "https://api.staging.withpathways.org"
      }
    }
  }
}

Project structure

pathways-mcp-server/
├── pyproject.toml
├── requirements.txt
├── .env.example
├── .gitignore
├── README.md
└── src/
    └── pathways_mcp/
        ├── __init__.py
        ├── __main__.py         # python -m entry point
        ├── server.py           # FastMCP server + tool registration
        ├── api.py              # Strapi API client (httpx, auth, pagination)
        └── tools/
            ├── __init__.py
            ├── segmentations.py
            ├── segments.py
            ├── metrics.py
            ├── variables.py
            ├── reference.py
            └── geography.py

The Pathways Data Model

Understanding this hierarchy is key to understanding all the tools.

Geography (e.g., Senegal)
  └── Segmentation (e.g., SEN_2019DHS8_v1 — "Senegal 2019 DHS study")
        ├── Segments (e.g., R1, R2, R3, R4, U1, U2... — distinct groups of women)
        │     └── Metrics (a segment × variable pair = one data point)
        │
        └── Variables (the indicators measured, e.g., "Modern contraceptive use")
              ├── linked to Themes   → describe Health Outcomes
              └── linked to Domains  → describe Vulnerability Factors

Themes  = categories of Health Outcomes  (e.g., Maternal Health, Nutrition)
Domains = categories of Vulnerability Factors (e.g., Household Economics, Social Support)

Regions = sub-national administrative areas within a Geography
Geographic Distributions = what % of each region's population belongs to each segment

The API Client (api.py)

This is the most important infrastructure file. It handles all HTTP communication.

The StrapiClient class

When instantiated, it reads two environment variables — both are now required:

  • PATHWAYS_API_TOKEN — the Bearer token (raises an error immediately if missing)
  • PATHWAYS_API_URL — the base URL (raises an error immediately if missing; there is no default fallback)
self._headers = {"Authorization": f"Bearer {token}"}

Every request includes this header, which Strapi uses to verify access.

fetch_collection — one page of results

This is the main method. It:

  1. Builds the query string parameters (filters, pagination, populate, fields)
  2. Makes an async HTTP GET request using httpx
  3. Returns the parsed JSON
async with httpx.AsyncClient(...) as client:
    resp = await client.get(url, params=params)
    resp.raise_for_status()
    return resp.json()

resp.raise_for_status() checks the HTTP status code. If the server returned a 4xx or 5xx error, it raises a Python exception immediately rather than silently returning broken data. Before calling that, the code also checks for specific codes to give actionable error messages:

if resp.status_code == 403:
    raise RuntimeError("Access denied... Check your PATHWAYS_API_TOKEN.")
if resp.status_code == 404:
    raise RuntimeError(f"Endpoint '{endpoint}' not found on the Strapi API.")

A 403 means the token is wrong or expired. A 404 means the endpoint path itself doesn't exist — usually a typo in the collection name.

fetch_all — auto-pagination

Some tools need all records, not just a page. fetch_all calls fetch_collection in a loop, advancing the page number on each iteration:

while True:
    result = await self.fetch_collection(..., page=page, ...)
    data = result.get("data", [])
    all_data.extend(data)

    page_count = result["meta"]["pagination"]["pageCount"]

    if page >= page_count or len(all_data) >= max_records:
        break
    page += 1

Strapi tells you how many pages exist in the meta.pagination.pageCount field. The loop stops when you've fetched the last page, or when you've hit max_records (a safety cap to prevent fetching thousands of records if the data grows unexpectedly).

This is used by get_segment_profile for both its metrics fetch and variables fetch — both can be very large datasets.

The populate parameter — what Strapi relations are

In relational databases, a foreign key is when one table stores only the ID of a record from another table — not the full data. For example, a metrics record stores a variable_id: 42 rather than copying all the variable's fields.

Strapi works the same way. By default, when you fetch a metric, you get:

{ "id": 1, "percentage": 0.34, "variable": null }

To get the actual variable data embedded in the response, you pass populate:

populate=["variable", "categorical_level"]

Strapi then does a database JOIN behind the scenes and returns:

{
  "id": 1,
  "percentage": 0.34,
  "variable": { "code": "fp.mod.use", "name_en": "Modern FP use", ... },
  "categorical_level": { "name_en": "Yes", ... }
}

Without populate, the tool code would have to make a separate API call for every variable — which would be hundreds of extra requests. Populate fetches them all in one go.

The singleton pattern

_client: StrapiClient | None = None

def get_client() -> StrapiClient:
    global _client
    if _client is None:
        _client = StrapiClient()
    return _client

The client is created once and reused across all tool calls. This avoids re-reading environment variables and re-allocating memory on every request.

RESPONSE_CHAR_LIMIT

Set to 25,000 characters. All tool responses are truncated to this length before being returned to Claude:

return json.dumps(output, indent=2)[:RESPONSE_CHAR_LIMIT]

This is a practical guard: MCP responses that are too large can cause problems for the AI client or hit context limits.


推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选