get-areas
Retrieve all areas from Things 3 to organize projects and tasks, with an option to include nested items for comprehensive project management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| include_items | No | Include projects and tasks within areas |
Implementation Reference
- src/index.ts:868-880 (handler)Tool registration for "get-areas" and the handler function logic.
server.tool( "get-areas", { include_items: z.boolean().optional().describe("Include projects and tasks within areas"), }, async ({ include_items }) => { const data = await withDatabase((db) => { const tasks = getAllTasks(db); return getAreas(db, tasks, include_items ?? false); }); return buildTextResponse(`Found ${data.length} areas`, { areas: data }); } ); - src/index.ts:483-538 (helper)Helper function `getAreas` which executes the actual database logic to fetch and format areas.
function getAreas(db: DatabaseSync, tasks: TaskRecord[], includeItems = false): AreaRecord[] { const rows = db .prepare( ` SELECT AREA.uuid, AREA.title FROM TMArea AS AREA ORDER BY AREA."index" ` ) .all() as Array<{ uuid: string; title: string }>; const areaTags = db .prepare( ` SELECT AREA_TAG.areas AS area_id, TAG.title AS tag_title FROM TMAreaTag AS AREA_TAG LEFT JOIN TMTag AS TAG ON TAG.uuid = AREA_TAG.tags ORDER BY TAG."index" ` ) .all() as Array<{ area_id: string; tag_title: string | null }>; const tagsByArea = new Map<string, string[]>(); for (const row of areaTags) { if (!row.tag_title) continue; const current = tagsByArea.get(row.area_id) ?? []; current.push(row.tag_title); tagsByArea.set(row.area_id, current); } return rows.map((row) => { const area: AreaRecord = { id: row.uuid, title: row.title, tags: tagsByArea.get(row.uuid) ?? [], }; if (includeItems) { area.projects = tasks.filter( (task) => task.type === "project" && task.areaId === row.uuid && !task.trashed ); area.todos = tasks.filter( (task) => task.type === "to-do" && task.areaId === row.uuid && !task.trashed && !task.projectId ); } return area; }); }