# Using LastPing from an AI agent

LastPing is a **dead-man's-switch monitor**: something checks in on a schedule, and if the check-in doesn't arrive, LastPing opens an incident and alerts a human. That makes it the natural way for an autonomous agent to prove it's still alive and doing its job — and to get someone notified when it isn't (crash, hang, infinite loop, or a scheduled run that silently stops firing).

LastPing is the first monitor your agent can set up itself. An autonomous agent is the new cron job — and the same failure class (silent absence of a signal that should have arrived) applies to both.

## Via MCP (recommended)

Install the `lastping-mcp` server — a single Go binary, no npm, no runtime dependencies.

### Build

```bash
# requires Go 1.22+
git clone https://github.com/tp322d/lastping-app
cd lastping-app
go build -o lastping-mcp ./cmd/lastping-mcp
```

### Configure (Claude Desktop / Claude Code / Cursor)

Add to `claude_desktop_config.json` (Claude Desktop) or `.mcp.json` (project-level):

```json
{
  "mcpServers": {
    "lastping": {
      "command": "/absolute/path/to/lastping-mcp",
      "env": { "LASTPING_API_KEY": "lp_your_key_here" }
    }
  }
}
```

Get an API key at: https://app.lastping.dev — Settings → API Keys.

### Self-instrumentation in one conversation

1. **`create_monitor`** — create a heartbeat (expected every N seconds, or on a cron) for the task you run. Pass a stable `slug` so re-running is idempotent (upsert, not duplicate).
2. **`get_ping_instructions`** — returns the ping URL plus ready-to-run `curl_success` / `curl_start` / `curl_fail` snippets for that monitor.
3. **Wire the pings into your work** — run the **success** ping when the task finishes, the **fail** ping if it errors, and (for long or possibly-hung work) the **start** ping at launch.

If the run goes silent, LastPing opens an incident and alerts you — without the agent having to notice it died.

### MCP tool reference

**Monitors:** `create_monitor` (upsert by slug) · `list_monitors` · `get_monitor` · `update_monitor` · `delete_monitor` · `pause_monitor` · `resume_monitor` · `snooze_monitor`

**Incidents:** `list_incidents` · `get_incident` (includes failure detail — the "why")

**Destinations:** `list_destinations` · `create_destination` · `test_destination`

**Routing:** `set_route` — route a monitor's `down` / `recovery` / `fail` alerts to one or more destinations (replaces the set; empty clears it)

**Self-instrumentation:** `get_ping_instructions` — returns the ping URL plus `curl_success` / `curl_start` / `curl_fail` for any monitor. This is the key tool for one-conversation self-instrumentation.

## Via the REST API directly

Everything the MCP server does maps to `POST`/`GET`/`PATCH` `/api/v1/...` with `Authorization: Bearer <api-key>`.

- Reference: https://app.lastping.dev/docs/api/
- llms.txt: https://lastping.dev/llms.txt

Auth: `Authorization: Bearer lp_your_key_here` on every request.

Monitor creation is **idempotent by slug** — safe to retry from an agent. Passing the same `slug` updates the existing monitor rather than creating a duplicate.

## Ping conventions

- `GET https://ping.lastping.dev/<monitor-uuid>` — success / "I'm alive"
- `.../start` — a run began (enables overrun + never-finished detection)
- `.../fail` — the run failed (POST the error/log body as `text/plain`, up to 64 KB — stored as failure detail on the incident)
- `.../<exit-code>` — report a shell exit code (0 = success, non-zero = fail)
- `...?rid=<run-id>` — pair a start with its later success/fail and record run duration

## What LastPing detects for agents

- **Silent death** — the agent process exits without pinging. No signal in the expected window → incident.
- **Hung runs** — start ping sent, no success/fail within the grace window → incident.
- **Explicit failures** — agent POSTs to `/fail` with the error body → incident opens immediately with failure detail attached.
- **Scheduled runs that stop** — no run signal in the expected cron window → incident.
- **Recovery** — next successful ping closes the incident and sends a recovery notice automatically.

## Pricing

LastPing is free for individuals — no monitor cap, no feature gate. A paid team tier may be introduced later for teams running fleets of agents.

## More

- Web: https://lastping.dev/agents/
- API docs: https://app.lastping.dev/docs/api/
- GitHub: https://github.com/tp322d/lastping-app
- Contact: hello@lastping.dev
