Skip to content

Tutorial 201: Detect & Clean Up Unused Media

This tutorial shows how to use the Media Cleanup add-on abilities to discover unused, duplicate, or oversized files and bulk-action them safely.

Plugins required: Virtual Media Folders · VMFA AI Ability · vmfa-media-cleanup · WordPress MCP Adapter


An agent or script that:

  1. Checks current cleanup statistics.
  2. Starts a background scan.
  3. Polls until the scan finishes.
  4. Reviews the unused-file results.
  5. Trashes the confirmed unused items.

Before starting a scan, get a quick overview of the last completed scan’s findings:

Terminal window
curl -s -X POST "https://example.com/wp-json/mcp/mcp-adapter-default-server" \
-u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0", "id": 1, "method": "tools/call",
"params": {
"name": "mcp-adapter-execute-ability",
"arguments": { "ability_name": "vmfo-cleanup/get-stats", "parameters": {} }
}
}'

Response:

{
"total_media": 1240,
"unused_count": 87,
"duplicate_count": 34,
"duplicate_groups": 12,
"oversized_count": 5,
"flagged_count": 126
}

If the numbers are stale (or this is the first run), start a fresh scan.


Start a scan limited to unused and duplicate detection:

Terminal window
curl -s -X POST "https://example.com/wp-json/mcp/mcp-adapter-default-server" \
-u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0", "id": 2, "method": "tools/call",
"params": {
"name": "mcp-adapter-execute-ability",
"arguments": {
"ability_name": "vmfo-cleanup/start-scan",
"parameters": { "types": ["unused", "duplicate"] }
}
}
}'

Response:

{ "status": "running", "started_at": "2026-05-02T10:00:00Z" }

Call get-scan-status repeatedly until status is completed (or failed):

Terminal window
curl -s -X POST "https://example.com/wp-json/mcp/mcp-adapter-default-server" \
-u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0", "id": 3, "method": "tools/call",
"params": {
"name": "mcp-adapter-execute-ability",
"arguments": { "ability_name": "vmfo-cleanup/get-scan-status", "parameters": {} }
}
}'

Partial response mid-scan:

{
"status": "running",
"phase": "unused",
"total": 1240,
"processed": 640,
"started_at": "2026-05-02T10:00:00Z",
"completed_at": null
}

Completed response:

{
"status": "completed",
"total": 1240,
"processed": 1240,
"completed_at": "2026-05-02T10:02:10Z"
}

A reasonable polling interval is 5–10 seconds.


Retrieve the first page of unused media items:

Terminal window
curl -s -X POST "https://example.com/wp-json/mcp/mcp-adapter-default-server" \
-u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0", "id": 4, "method": "tools/call",
"params": {
"name": "mcp-adapter-execute-ability",
"arguments": {
"ability_name": "vmfo-cleanup/list-results",
"parameters": { "type": "unused", "per_page": 50, "page": 1 }
}
}
}'

Response:

{
"items": [
{ "id": 1001, "title": "old-banner-2019.png", "url": "...", "type": "unused", "file_size": 204800 },
{ "id": 1002, "title": "draft-hero.jpg", "url": "...", "type": "unused", "file_size": 819200 }
],
"total": 87,
"page": 1,
"per_page": 50,
"total_pages": 2
}

Review the list. Collect the id values for items safe to remove.


Trash is reversible — prefer it over permanent deletion.

Terminal window
curl -s -X POST "https://example.com/wp-json/mcp/mcp-adapter-default-server" \
-u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0", "id": 5, "method": "tools/call",
"params": {
"name": "mcp-adapter-execute-ability",
"arguments": {
"ability_name": "vmfo-cleanup/trash",
"parameters": { "attachment_ids": [1001, 1002] }
}
}
}'

Response:

{ "trashed": 2, "failed": 0 }

If you are certain items are safe to remove permanently, use vmfo-cleanup/delete instead. See media-cleanup.md for details and a warning.


For duplicates, retrieve the list with type: "duplicate", identify the canonical version you want to keep, collect the redundant IDs, and archive or trash them:

Terminal window
# List duplicate results
"parameters": { "type": "duplicate", "per_page": 50 }
# Archive the extras (reversible)
"ability_name": "vmfo-cleanup/archive",
"parameters": { "attachment_ids": [1003, 1004] }

StepAbilityPurpose
1vmfo-cleanup/get-statsOverview of last scan
2vmfo-cleanup/start-scanStart background scan
3vmfo-cleanup/get-scan-statusPoll for completion
4vmfo-cleanup/list-resultsReview flagged items
5vmfo-cleanup/trashSoft-delete unused media
vmfo-cleanup/deleteHard-delete (irreversible)

Previous: Tutorial 101 · Next: Tutorial 301 — Automate Folder Assignment with Rules