> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pulseguard.nl/llms.txt
> Use this file to discover all available pages before exploring further.

# Model Context Protocol (MCP)

> Gebruik PulseGuard via MCP in AI assistants zoals ChatGPT.

# Model Context Protocol (MCP)

PulseGuard ondersteunt het Model Context Protocol (MCP), waardoor je PulseGuard kunt gebruiken in AI assistants zoals ChatGPT. Hiermee kun je je monitoring data direct opvragen via natuurlijke taal.

## Overzicht

Het MCP server van PulseGuard stelt je in staat om:

* Dashboard statistieken te bekijken
* Domeinen en uptime te monitoren
* Incidenten bij te houden
* Device status te controleren
* Netwerk scans uit te voeren (DNS, poorten)

## Setup in ChatGPT

### 1. Custom Action Aanmaken

1. Ga naar **ChatGPT Settings** → **Actions** → **Create new action**

2. **Server Details invullen:**
   ```
   Server URL: https://api.ipulse.one/mcp
   Authentication: Bearer token (optioneel)
   ```

3. **Schema importeren** of gebruik de beschikbare tools

4. **Verbinding testen:**
   Vraag ChatGPT: "Laat me mijn PulseGuard dashboard zien"

## Beschikbare Tools

### 1. Dashboard Statistieken Opvragen

**Tool Naam:** `get_dashboard_stats`

Haalt uitgebreide monitoring statistieken op.

**Parameters:**

* `organizationId` (optioneel): Filter statistieken per organisatie

**Response:**

```json theme={null}
{
  "domains": { "total": 10, "up": 8, "down": 2, "uptime": 95 },
  "devices": { "total": 5, "online": 4, "offline": 1 },
  "services": { "total": 15, "up": 14, "down": 1 },
  "incidents": { "active": 3, "critical": 1 }
}
```

### 2. Incidenten Lijst

**Tool Naam:** `list_incidents`

Haal een lijst van incidenten op met filtering.

**Parameters:**

* `status` (optioneel): Filter op status (open, investigating, resolved, etc.)
* `severity` (optioneel): Filter op severity (low, medium, high, critical)
* `organizationId` (optioneel): Filter per organisatie
* `limit` (optioneel, standaard: 20): Aantal resultaten

**Response:**

```json theme={null}
{
  "incidents": [...],
  "total": 50,
  "summary": {
    "open": 10,
    "critical": 2
  }
}
```

### 3. Domeinen Status

**Tool Naam:** `get_domains_status`

Haal monitoring status voor alle domeinen op.

**Parameters:**

* `organizationId` (optioneel): Filter per organisatie

**Response:**

```json theme={null}
{
  "summary": {
    "total": 10,
    "up": 8,
    "down": 2,
    "avgResponseTime": 150,
    "uptime": 95.5
  },
  "domains": [...]
}
```

### 4. DNS Records Scannen

**Tool Naam:** `scan_dns`

Scan DNS records voor een domein.

**Parameters:**

* `domain` (vereist): Domeinnaam om te scannen

**Response:**

```json theme={null}
{
  "domain": "example.com",
  "records": [...],
  "total": 15
}
```

### 5. Poorten Scannen

**Tool Naam:** `scan_ports`

Scan veelgebruikte poorten op een host.

**Parameters:**

* `host` (vereist): Hostname of IP adres
* `ports` (optioneel): Komma-gescheiden poorten of range

**Response:**

```json theme={null}
{
  "host": "example.com",
  "openPorts": [...],
  "totalScanned": 15
}
```

### 6. Devices Status

**Tool Naam:** `get_devices_status`

Haal status en metrics voor gemonitorde devices op.

**Parameters:**

* `organizationId` (vereist): Organisatie ID

**Response:**

```json theme={null}
{
  "devices": [...],
  "total": 5,
  "online": 4,
  "offline": 1
}
```

## UI Componenten

Het MCP server bevat kant-en-klare UI componenten die renderen in ChatGPT:

### Dashboard Widget

* Toont real-time monitoring statistieken
* Geeft aantal domeinen, devices, services en incidenten weer
* Kleur-gecodeerde status indicatoren

### Incidenten Widget

* Lijst incidenten met severity en status
* Kleur-gecodeerd per severity niveau
* Toont aanmaaktijd en metadata

### Domeinen Widget

* Samenvattingsstatistieken (uptime, response time)
* Lijst van gemonitorde domeinen met status
* Visuele status indicatoren

## Voorbeeld Prompts

* "Laat me mijn monitoring dashboard zien"
* "Geef alle kritieke incidenten"
* "Wat is de status van mijn domeinen?"
* "Scan DNS records voor example.com"
* "Controleer poort 443 op example.com"
* "Laat offline devices zien"

## Authenticatie

Het MCP server ondersteunt Clerk authenticatie:

```bash theme={null}
POST /mcp
Authorization: Bearer <clerk-jwt-token>
```

User context wordt geëxtraheerd uit de JWT en gebruikt om resultaten te filteren.

## Development

### Lokaal Testen

1. Start de backend:

```bash theme={null}
cd apps/backend
bun run start:dev
```

2. Test met curl:

```bash theme={null}
curl -X POST http://localhost:3001/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list",
    "params": {}
  }'
```

3. Gebruik MCP Inspector:

```bash theme={null}
npx @modelcontextprotocol/inspector http://localhost:3001/mcp
```

## Troubleshooting

### Veelvoorkomende Problemen

1. **CORS Errors:**
   * Zorg ervoor dat CORS is ingeschakeld in NestJS main.ts
   * Controleer of toegestane origins ChatGPT domeinen bevatten

2. **Authenticatie Fouten:**
   * Controleer of Clerk JWT geldig is
   * Controleer authorization header formaat

3. **Tool Niet Gevonden:**
   * Controleer of tool is geregistreerd in mcp.service.ts
   * Controleer of tool naam exact overeenkomt

### Debug Mode

Schakel debug logging in:

```typescript theme={null}
// In mcp.controller.ts
this.logger.debug(`MCP Request: ${JSON.stringify(body)}`);
```

## Meer Informatie

* [MCP Specificatie](https://modelcontextprotocol.io)
* [ChatGPT Apps SDK](https://platform.openai.com/docs/chatgpt/apps-sdk)
* [PulseGuard Docs](https://docs.ipulse.one)
