# MCP Health Check

Performs a complete MCP health check and updates the cache.

## Workflow

```
1. Test MCP Connectivity  -> Call mcp__smartstack__validate_conventions
2. Get MCP Version        -> smartstack --version (bundled in CLI)
3. List Available Tools   -> Enumerate mcp__smartstack__* tools
4. Update Cache           -> Write .claude/mcp-status.json
```

## Step 1: Test Connectivity

Call MCP with minimal parameters:

```
mcp__smartstack__validate_conventions({
  checks: ["tables"]
})
```

**Expected:** Response without connection error

**On failure:**
```
MCP CONNECTION FAILED
   Error: <error_message>

   Actions:
   1. Verify MCP is configured: claude mcp list
   2. Re-register: claude mcp add smartstack -- npx --package @atlashub/smartstack-cli smartstack-mcp
   3. Restart Claude Code
```

## Step 2: Get Version

```bash
# Read CLI package version (MCP is bundled inside)
npx smartstack --version 2>/dev/null || smartstack --version
```

## Step 3: List Tools

Verify these critical tools are available:

| Tool | Purpose |
|------|---------|
| `validate_conventions` | Convention validation |
| `scaffold_extension` | Code generation |
| `suggest_migration` | Migration naming |
| `check_migrations` | Conflict detection |
| `generate_permissions` | RBAC generation |

## Step 4: Update Cache

Write to `.claude/mcp-status.json`:

```json
{
  "lastCheck": "<ISO_DATE>",
  "mcpVersion": "<VERSION>",
  "bundled": true,
  "status": "ok",
  "toolsAvailable": [
    "validate_conventions",
    "scaffold_extension",
    "suggest_migration",
    "check_migrations",
    "generate_permissions"
  ]
}
```

## Output Formats

**Success:**
```
MCP HEALTH CHECK
  Status      : OK
  Version     : 2.0.0 (bundled)
  Tools       : 19 available
  Cache       : Updated (.claude/mcp-status.json)
  Next check  : in 7 days (auto)
```

**Warning (update available):**
```
MCP HEALTH CHECK
  Status      : UPDATE AVAILABLE
  Current     : 1.38.0
  Latest      : 2.0.0
  Action      : npm update -g @atlashub/smartstack-cli
```

**Error:**
```
MCP HEALTH CHECK
  Status      : ERROR
  Issue       : MCP server not responding

  Troubleshooting:
  1. Check registration: claude mcp list
  2. Re-register: claude mcp add smartstack -- npx --package @atlashub/smartstack-cli smartstack-mcp
  3. Update CLI: npm update -g @atlashub/smartstack-cli
  4. Restart Claude Code
```
