Metadata-Version: 2.4
Name: mac-diagnostics-mcp
Version: 0.5.0
Summary: FastMCP server exposing macOS diagnostic scripts as MCP tools
Author: Thomas Juul Dyhr
License-Expression: MIT
Project-URL: Repository, https://github.com/docdyhr/mac-diagnostics
Project-URL: Changelog, https://github.com/docdyhr/mac-diagnostics/blob/main/CHANGELOG.md
Keywords: macos,mcp,diagnostics,fastmcp
Classifier: Environment :: MacOS X
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastmcp>=2.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Dynamic: license-file

# mac-diagnostics

![CI](https://github.com/docdyhr/mac-diagnostics/actions/workflows/ci.yml/badge.svg)

Small macOS diagnostic shell scripts — sleep/wake, crashes, battery, disk,
network, security, backups, storage, and Wi-Fi — plus an MCP server that
exposes them to AI agents (Claude Desktop, Claude Code, Cursor, VS Code, and
others).

## Scripts

All scripts live in `mac_diagnostics_mcp/scripts/` and run standalone — no
Python required:

- `mac-sleep-investigate.sh` — investigate sleep blockers, wake reasons, dark wakes, login/logout events, and likely always-awake processes.
- `mac-startup-items.sh` — inventory launch agents, launch daemons, login items, and common startup services.
- `mac-crashes.sh` — crash and hang trend analysis (per-app repeat offenders, kernel panics, JetsamEvent OOM kills, Microstackshots hang reports across modern .ips/.diag and legacy .crash formats), plus crash-related unified log entries and watchdog kills.
- `mac-battery.sh` — inspect battery health, cycle count, charging state, thermal state, and recent charging events.
- `mac-cpu-memory.sh` — inspect CPU usage, memory pressure, swap usage, thermal throttling, and related log events.
- `mac-disk-health.sh` — inspect free space, disk details, SMART status, storage profiler data, large home directories, and Time Machine state.
- `mac-network.sh` — inspect network services, interfaces, routes, DNS, connectivity, Wi-Fi state, established connections, listening ports, and HTTP latency.
- `mac-quick-health.sh` — fast overview across CPU, memory, disk, network, sleep blockers, battery, crashes, startup items, and thermal state.
- `mac-security.sh` — baseline security audit: FileVault, SIP, Gatekeeper, XProtect, application firewall, sharing services via listening ports, account hygiene, and a code-signing spot-check of third-party persistence items.
- `mac-backup.sh` — Time Machine health: destination configured, last-backup age, running state, local snapshot usage.
- `mac-storage.sh` — storage breakdown: overall usage, purgeable space, and the size of the usual heavyweight directories (Xcode DerivedData, simulators, Docker, caches, iOS backups, Downloads).
- `mac-wifi.sh` — Wi-Fi link quality: power, association, RSSI, noise, SNR, channel, and transmit rate.
- `mac-software-update.sh` — software-update status: pending macOS updates, automatic-update settings, XProtect definition age, and last successful update check.

**Developer environment tooling:**

- `mac-mcp-servers.sh` — audit MCP server configs across AI clients: deep audit of Claude Desktop (type classification, path health checks, env var key names with values redacted) plus detection of Claude Code, Cursor, VS Code, and Windsurf configs.
- `mac-node-packages.sh` — audit Node.js and Bun ecosystem: detect all Node installations, list npm global packages per prefix, show Bun tools in `~/.bun/bin`, and report available updates.
- `mac-node-update.sh` — show or apply updates for global npm and Bun packages; with `--include-mcp-venvs` also audits/upgrades pip packages in Python venv MCP servers.

### Machine-readable findings

Every report ends with a `Machine-readable findings` section of one-line
findings:

```
FINDING:WARN:disk: boot volume / is 92% full
FINDING:CRIT:network: no outbound connectivity (ping 1.1.1.1 failed) [suggest: investigate_network]
```

Severity is `INFO` / `WARN` / `CRIT`. The MCP server lifts these into
structured tool output, so an agent can react to them deterministically
instead of parsing the prose report. A finding may end with an
**escalation hint** — `[suggest: tool(args)]` — which the server exposes as
a structured `suggestion` field naming the recommended follow-up tool.

### Conditional-depth checks

The expensive unified-log (`log show`) checks in `mac-sleep-investigate.sh`,
`mac-crashes.sh`, and `mac-cpu-memory.sh` run only when a cheap trigger
fires (active sleep blocker, crash reports on disk, memory pressure,
throttling) or `--deep` is passed. Skipped checks are listed as
`SKIPPED: <check> (no trigger; use --deep to force)` in the report — a
clean machine's crash report takes well under a second. The MCP tools
expose this as `deep: false` by default.

## MCP server

### Install

From a clone (development):

```bash
python -m pip install -e .
mac-diagnostics-mcp        # runs the server on stdio
```

Or with zero install, straight from PyPI (once published):

```bash
uvx mac-diagnostics-mcp
```

### Configure your client

**Claude Desktop** — `~/Library/Application Support/Claude/claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "mac-diagnostics": {
      "command": "uvx",
      "args": ["mac-diagnostics-mcp"]
    }
  }
}
```

**Claude Code** — `~/.claude.json` (same `mcpServers` shape), or:

```bash
claude mcp add mac-diagnostics -- uvx mac-diagnostics-mcp
```

**Cursor** — `~/.cursor/mcp.json` (same `mcpServers` shape as Claude Desktop).

**VS Code** — `~/Library/Application Support/Code/User/mcp.json` (same shape).

For a development checkout, point the client at the console script inside the
venv instead:

```json
{
  "mcpServers": {
    "mac-diagnostics": {
      "command": "/path/to/mac-diagnostics/.venv/bin/mac-diagnostics-mcp"
    }
  }
}
```

### Tools

The server exposes 17 tools. Each returns a structured result:
`status` (`ok` / `info` / `warn` / `crit`), a machine-readable `findings`
list, and the full prose `report`. Check `findings` first; read the report
only for detail.

Every read-only tool also accepts `compare_last: true`, which diffs the
findings against the previous run with the same parameters and adds a
`delta` key (`new` / `resolved` / `changed` / `status_change`). Run history
lives in `~/.local/state/mac-diagnostics/`; see
[docs/baselines-design.md](docs/baselines-design.md).

| Tool | Description | Mutates? |
|---|---|---|
| `triage` | Map a symptom in plain language to an ordered tool plan | no |
| `quick_health_check` | Fast 30-second overview | no |
| `investigate_sleep` | Sleep blockers, wake reasons | no |
| `investigate_cpu_memory` | CPU usage, memory pressure | no |
| `investigate_disk` | SMART status, free space | no |
| `investigate_network` | Connectivity, DNS, routing | no |
| `investigate_crashes` | App crash/hang trends, panics, OOM kills | no |
| `investigate_battery` | Battery health, cycle count | no |
| `investigate_startup_items` | Launch agents and daemons, with code-signing assessment | no |
| `security_audit` | FileVault, SIP, firewall, sharing, persistence spot-check | no |
| `backup_audit` | Time Machine destination, last-backup age, snapshots | no |
| `storage_breakdown` | What is consuming the boot volume | no |
| `wifi_quality` | Wi-Fi RSSI, noise, SNR, channel, Tx rate | no |
| `check_software_updates` | Pending macOS updates, auto-update settings, XProtect age | no |
| `list_mcp_servers` | Audit MCP configs across AI clients | no |
| `inspect_node_packages` | Node/Bun ecosystem audit and update report | no |
| `update_node_packages` | Apply npm/bun updates (dry-run by default) | **only with `apply=true`** |

All read-only tools carry `readOnlyHint` annotations so clients can
auto-approve them safely.

### Mutation guard

`update_node_packages(apply=true)` modifies the system (`brew upgrade`,
`npm update -g`, `pip install --upgrade`). It is refused unless the server
was started with:

```json
{
  "mcpServers": {
    "mac-diagnostics": {
      "command": "uvx",
      "args": ["mac-diagnostics-mcp"],
      "env": { "MAC_DIAG_ALLOW_MUTATIONS": "1" }
    }
  }
}
```

Without it, the tool returns a structured refusal — a prompt-injected or
over-eager agent cannot run upgrades.

## Example prompts

With the MCP server configured, ask your agent:

**System overview**
- "Run a quick health check on my Mac."

**Sleep & wake**
- "Investigate why my Mac isn't sleeping."
- "Check for sleep issues from the last 48 hours." *(uses `since` param)*

**CPU & memory**
- "Diagnose high CPU and memory pressure."
- "Check CPU and memory from the last 2 hours." *(uses `since` param)*

**Disk**
- "Check my disk health and free space."
- "Show verbose disk info including all partitions." *(uses `verbose` param)*

**Network**
- "Test my network connectivity and DNS."

**Crashes**
- "Show recent app crashes and panics."
- "List crashes from the last 48 hours." *(uses `since` param)*

**Battery** *(MacBook only)*
- "Check my battery health and cycle count."

**Startup items**
- "List everything that launches at startup."

**Security**
- "Run a security audit of this Mac."
- "Are any of my startup items unsigned?"

**Backups**
- "When did my last Time Machine backup finish?"

**Storage**
- "My disk is full — what is taking up the space?"

**Wi-Fi**
- "Is my Wi-Fi signal any good?"

**Software updates**
- "Are my macOS updates up to date?"

**Symptoms → plan**
- "My battery drains overnight — what should we check?" *(uses `triage`)*

**Change since last time**
- "Run the health check and tell me what changed since last week." *(uses `compare_last`)*

**Workflow prompts** — the server also ships guided multi-tool workflows:
`diagnose_slow_mac`, `investigate_sleep_issues`, `weekly_maintenance`,
`security_review`, and `pre_travel_check`.

**MCP server audit**
- "Audit my MCP server configuration across all AI clients."

**Node / Bun packages**
- "Audit my MCP server configuration across all AI clients."

**Node / Bun packages**
- "Audit my Node.js and Bun global packages."
- "Check for npm and Bun package updates (dry-run)."
- "Apply npm and Bun updates, including Python MCP venvs." *(uses `apply` + `include_mcp_venvs` params; requires the mutation guard)*

## Usage (standalone scripts)

Run a script directly:

```bash
./mac_diagnostics_mcp/scripts/mac-sleep-investigate.sh --since 24h
./mac_diagnostics_mcp/scripts/mac-quick-health.sh
./mac_diagnostics_mcp/scripts/mac-startup-items.sh
./mac_diagnostics_mcp/scripts/mac-crashes.sh --since 48h
./mac_diagnostics_mcp/scripts/mac-battery.sh
./mac_diagnostics_mcp/scripts/mac-cpu-memory.sh --since 2h
./mac_diagnostics_mcp/scripts/mac-disk-health.sh
./mac_diagnostics_mcp/scripts/mac-network.sh
./mac_diagnostics_mcp/scripts/mac-security.sh
./mac_diagnostics_mcp/scripts/mac-backup.sh
./mac_diagnostics_mcp/scripts/mac-storage.sh
./mac_diagnostics_mcp/scripts/mac-wifi.sh
./mac_diagnostics_mcp/scripts/mac-software-update.sh

# Developer environment tools
./mac_diagnostics_mcp/scripts/mac-mcp-servers.sh --stdout
./mac_diagnostics_mcp/scripts/mac-node-packages.sh --stdout
./mac_diagnostics_mcp/scripts/mac-node-update.sh --stdout                        # dry-run
./mac_diagnostics_mcp/scripts/mac-node-update.sh --stdout --apply                # apply updates
./mac_diagnostics_mcp/scripts/mac-node-update.sh --stdout --apply --include-mcp-venvs
```

By default, each script writes a timestamped report folder on your Desktop.
With `--stdout` (the mode the MCP server uses), the report goes to a temp dir
instead — agents calling tools repeatedly will not clutter your Desktop.

Use `--out` to choose a report folder explicitly:

```bash
./mac_diagnostics_mcp/scripts/mac-sleep-investigate.sh --since 24h --out ~/Desktop/sleep-report
```

## Requirements

- macOS
- Bash
- GNU `timeout` available as `timeout` in `PATH` (for example via Homebrew `coreutils`)
- Standard macOS tools used by the scripts, such as `pmset`, `log`, `launchctl`, `system_profiler`, `ioreg`, and `osascript`
- Python ≥ 3.11 and `fastmcp` for the MCP server only

Some commands may require additional macOS permissions or may return partial output depending on privacy settings and whether they are run with elevated privileges.

## Development checks

```bash
bash -n mac_diagnostics_mcp/scripts/*.sh
shellcheck --shell=bash mac_diagnostics_mcp/scripts/*.sh
ruff check mac_diagnostics_mcp/ tests/
pytest
```

## Privacy note

Generated reports can include hostnames, usernames, process names, launch agents, installed services, device/power state, and excerpts from macOS logs. Review report output before sharing it outside your machine.
