# NHANES (design-correct survey analysis)

Connects assistants directly to CDC NHANES files with built-in survey weights and design variance. Designed for analyses requiring Taylor linearization and NCHS standards.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 2
- Author: Black-Swan-Causal-Labs
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/Black-Swan-Causal-Labs/nhanes-mcp
- Updated: 2026-10-05
- HTML: https://affpapa.org/en/nevibecode/mcp/nhanes-design-correct-survey-analysis

## What it does

Standard language models often compute simple averages on NHANES files, yielding flawed numbers. This MCP server enforces valid survey methodology by default. It downloads public files from CDC servers, merges records on `SEQN`, and selects the appropriate sample weight in `WT_ANALYSIS`. Subsetting via the `domain` parameter keeps the full sample design intact, so Taylor linearization variance calculations stay sound.

The server provides 17 tools across the research workflow. They help explore CDC codebooks, recode missing values with `set_missing`, and collapse repeated rows via `flag_from_long_table`. For survival analysis, it supports design-based Cox models linked to mortality records. Supported cycles range from 1999–2000 through 2021–2023.

Running the server requires `uv` on your system. Black Swan Causal Labs is not affiliated with CDC, and researchers must comply with the public NCHS data use agreement.

## Requirements
- Needs: Python and uv (commands run via uvx)
- Environment variables: `NHANES_MCP_CACHE`, `NHANES_MCP_DATA_DIR` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add --env NHANES_MCP_CACHE=<NHANES_MCP_CACHE> --env NHANES_MCP_DATA_DIR=<NHANES_MCP_DATA_DIR> --transport stdio nhanes-design-correct-survey-analysis -- uvx nhanes-mcp
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from nhanes-mcp <command>

### Codex

**Platform CLI**
```bash
codex mcp add nhanes-design-correct-survey-analysis --env NHANES_MCP_CACHE=<NHANES_MCP_CACHE> --env NHANES_MCP_DATA_DIR=<NHANES_MCP_DATA_DIR> -- uvx nhanes-mcp
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from nhanes-mcp <command>

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "nhanes-design-correct-survey-analysis": {
            "command": "uvx",
            "args": [
                "nhanes-mcp"
            ],
            "env": {
                "NHANES_MCP_CACHE": "<NHANES_MCP_CACHE>",
                "NHANES_MCP_DATA_DIR": "<NHANES_MCP_DATA_DIR>"
            }
        }
    }
}
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from nhanes-mcp <command>

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "nhanes-design-correct-survey-analysis": {
            "type": "stdio",
            "command": "uvx",
            "args": [
                "nhanes-mcp"
            ],
            "env": {
                "NHANES_MCP_CACHE": "<NHANES_MCP_CACHE>",
                "NHANES_MCP_DATA_DIR": "<NHANES_MCP_DATA_DIR>"
            }
        }
    }
}
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from nhanes-mcp <command>

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e NHANES_MCP_CACHE=<NHANES_MCP_CACHE> -e NHANES_MCP_DATA_DIR=<NHANES_MCP_DATA_DIR> nhanes-design-correct-survey-analysis uvx nhanes-mcp
```
Replace <…> with your own values. uvx runs the command named after the package; if the README names another one, use uvx --from nhanes-mcp <command>

## When to use it
- Merge multi-cycle NHANES survey files using individual `SEQN` identifiers
- Assign correct probability weights automatically for exam or dietary data
- Calculate Korn-Graubard confidence intervals with official NCHS reliability flags
- Fit design-adjusted Cox survival models with Linked Mortality File follow-up

## Example prompts
- Search NHANES codebooks for blood pressure variables from 2017 to 2020 and compute weighted prevalence.
- Pool 2015-2018 cycles, apply domain filtering for diabetes, and calculate mean fasting glucose.
- Run a design-based Cox model linking body mass index with mortality follow-up.

## Similar
- [Zotero MCP](https://affpapa.org/en/nevibecode/mcp/zotero-mcp.md) — MCP server · ★ 5585
- [arxiv-mcp-server](https://affpapa.org/en/nevibecode/mcp/arxiv-mcp-server.md) — MCP server · ★ 3235
- [PaperBanana](https://affpapa.org/en/nevibecode/mcp/paperbanana.md) — MCP server · ★ 2418
- [MATLAB MCP Server](https://affpapa.org/en/nevibecode/mcp/matlab-mcp-server.md) — MCP server · ★ 1723
- [Hex Research](https://affpapa.org/en/nevibecode/mcp/hex-research.md) — MCP server · ★ 584
- [DocsAgent — Zotero, Obsidian & Apple Notes MCP Server](https://affpapa.org/en/nevibecode/mcp/docsagent-zotero-obsidian-apple-notes-mcp-server.md) — MCP server · ★ 578

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
