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

# Run Log Retention Now

> Manually trigger the daily log-retention cleanup.

Forces the log-retention cleanup to run immediately instead of waiting for the daily cron. Deletes call logs, daily-aggregated analytics rows, and stale MCP sessions older than the thresholds defined in plugin settings.

<Note>
  Useful right after lowering `log_retention_days` or `analytics_retention_days` on a busy site — without this, the freed-up rows would only be reclaimed at the next cron tick. Be aware that on huge tables the delete pass can run for several seconds; the request blocks until the cleanup completes.
</Note>

<Note>
  Permission is gated on the WordPress core capability **`manage_options`** (not the plugin's `getmcp_manage_settings`). This is intentional — the operation can be slow on large tables, so it stays restricted to site administrators.
</Note>

## Body

No body. Send an empty `POST`.

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
       --url https://yoursite.com/wp-json/getmcp/v1/admin/run-retention \
       --header 'Authorization: Bearer gmcp_your_api_key' \
       --header 'content-type: application/json'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://yoursite.com/wp-json/getmcp/v1/admin/run-retention",
      headers={
          "Authorization": "Bearer gmcp_your_api_key",
          "Content-Type": "application/json",
      },
  )
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://yoursite.com/wp-json/getmcp/v1/admin/run-retention",
    {
      method: "POST",
      headers: {
        "Authorization": "Bearer gmcp_your_api_key",
        "Content-Type": "application/json",
      },
    }
  );
  const data = await response.json();
  ```

  ```php PHP theme={null}
  $response = wp_remote_post(
      "https://yoursite.com/wp-json/getmcp/v1/admin/run-retention",
      [
          "headers" => [
              "Authorization" => "Bearer gmcp_your_api_key",
              "Content-Type"  => "application/json",
          ],
      ]
  );
  $data = json_decode( wp_remote_retrieve_body( $response ), true );
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "deleted": {
      "call_logs": 12453,
      "analytics_daily": 18,
      "sessions": 7
    },
    "thresholds": {
      "log_retention_days": 30,
      "analytics_retention_days": 90
    }
  }
  ```

  ```json 403 Forbidden theme={null}
  {
    "code": "rest_forbidden",
    "message": "Permission denied.",
    "data": { "status": 403 }
  }
  ```
</ResponseExample>

## Response Fields

<ResponseField name="deleted" type="object">
  Per-table count of rows removed by this run.
</ResponseField>

<ResponseField name="deleted.call_logs" type="integer">
  Call-log rows deleted (older than `log_retention_days`).
</ResponseField>

<ResponseField name="deleted.analytics_daily" type="integer">
  Aggregated daily-analytics rows deleted (older than `analytics_retention_days`).
</ResponseField>

<ResponseField name="deleted.sessions" type="integer">
  Stale MCP session rows reclaimed.
</ResponseField>

<ResponseField name="thresholds" type="object">
  The retention thresholds in effect at the time of the run, mirroring the matching keys on the [Settings](/api-reference/settings/get) endpoint.
</ResponseField>
