Metadata-Version: 2.4
Name: mac-diagnostics-mcp
Version: 0.6.1
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)
[![PyPI](https://img.shields.io/pypi/v/mac-diagnostics-mcp)](https://pypi.org/project/mac-diagnostics-mcp/)

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

## Quickstart

```bash
uvx mac-diagnostics-mcp   # runs the MCP server on stdio, zero install
```

Point your client at it — Claude Desktop
(`~/Library/Application Support/Claude/claude_desktop_config.json`):

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

- **Claude Code**: `claude mcp add mac-diagnostics -- uvx mac-diagnostics-mcp`
- **Cursor**: same `mcpServers` JSON in `~/.cursor/mcp.json`
- **VS Code**: same JSON in `~/Library/Application Support/Code/User/mcp.json`

Then ask your agent: *"Run a quick health check on my Mac."*

## Scripts

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

- `mac-quick-health.sh` — fast overview: CPU, memory, disk, network, sleep blockers, battery, crashes, startup items, thermal state.
- `mac-sleep-investigate.sh` — sleep blockers, wake reasons, dark wakes, always-awake processes.
- `mac-cpu-memory.sh` — CPU usage, memory pressure, swap, thermal throttling.
- `mac-disk-health.sh` — free space, SMART status, large home directories, Time Machine state.
- `mac-network.sh` — interfaces, routes, DNS, connectivity, listening ports, HTTP latency.
- `mac-crashes.sh` — crash/hang trends: repeat offenders, panics, OOM kills, hang reports (.ips/.diag and legacy .crash).
- `mac-battery.sh` — battery health, cycle count, charging state and history.
- `mac-startup-items.sh` — launch agents/daemons, login items, startup services.
- `mac-security.sh` — FileVault, SIP, Gatekeeper, XProtect, firewall, sharing services, account hygiene, persistence spot-check.
- `mac-backup.sh` — Time Machine destination, last-backup age, snapshot usage.
- `mac-storage.sh` — what fills the disk: purgeable space, heavyweight directories (Xcode, simulators, Docker, caches, iOS backups).
- `mac-wifi.sh` — Wi-Fi RSSI, noise, SNR, channel, transmit rate.
- `mac-software-update.sh` — pending macOS updates, auto-update settings, XProtect age.

Developer environment:

- `mac-mcp-servers.sh` — audit MCP server configs across AI clients (types, path health; env values redacted).
- `mac-node-packages.sh` — Node.js/Bun installations, global packages, available updates.
- `mac-node-update.sh` — apply npm/Bun updates (`--include-mcp-venvs` for Python MCP venvs).

### Machine-readable findings

Every report ends with one-line findings an agent can parse
deterministically:

```
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`. An optional `[suggest: tool(args)]`
escalation hint names the recommended follow-up tool.

### Conditional-depth checks

Expensive `log show` checks run only when a cheap trigger fires (active
sleep blocker, crash reports on disk, memory pressure) or `--deep` is
passed. Skips are listed as `SKIPPED: ...` lines — a clean machine's
crash report takes well under a second.

## Tools

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

Every read-only tool accepts `compare_last: true` — diffs findings
against the previous run 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, DNS-tamper checks | no |
| `check_network_addons` | Third-party tools (Little Snitch, KnockKnock, …): presence, state, conflicts | 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`) and is refused unless the
server was started with `MAC_DIAG_ALLOW_MUTATIONS=1`:

```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.

### Workflow prompts

Guided multi-tool workflows shipped with the server: `diagnose_slow_mac`,
`investigate_sleep_issues`, `weekly_maintenance`, `security_review`, and
`pre_travel_check`.

## Example prompts

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

**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`)*

**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 & storage**
- "Check my disk health and free space."
- "Show verbose disk info including all partitions." *(uses `verbose` param)*
- "My disk is full — what is taking up the space?"

**Network & Wi-Fi**
- "Test my network connectivity and DNS."
- "Is my Wi-Fi signal any good?"

**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?"

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

**MCP server audit**
- "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)

```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) it goes to a temp
dir instead. Use `--out PATH` to choose explicitly.

## Development

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

For development, point your client at the venv console script:
`"/path/to/mac-diagnostics/.venv/bin/mac-diagnostics-mcp"`.

Checks:

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

Releases are tagged (`vX.Y.Z`) and published via GitHub release — the
`publish.yml` workflow uploads to PyPI automatically (OIDC trusted
publishing, no tokens).

## Requirements

- macOS and Bash
- GNU `timeout` in `PATH` (e.g. Homebrew `coreutils`)
- Standard macOS tools: `pmset`, `log`, `launchctl`, `system_profiler`, `ioreg`, `osascript`
- Python ≥ 3.11 and `fastmcp` — MCP server only

Some commands return partial output depending on macOS privacy settings.

## Privacy note

Reports can include hostnames, usernames, process names, installed
services, and log excerpts. Review report output before sharing it
outside your machine.

## License

MIT
