feat: add MCP tool handlers, definitions, and collection resource

Wrap existing service layer with MCP-compatible tool handlers for items,
categories, threads/candidates, setups, and image fetching. Add collection
summary resource for overview data. All 14 MCP-specific tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 13:35:27 +02:00
parent a10156142f
commit 8919829167
7 changed files with 987 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import type { db as prodDb } from "@/db/index.ts";
import { getAllCategories } from "../../services/category.service.ts";
import { getAllItems } from "../../services/item.service.ts";
import { getAllSetups } from "../../services/setup.service.ts";
import { getAllThreads } from "../../services/thread.service.ts";
import { getGlobalTotals } from "../../services/totals.service.ts";
type Db = typeof prodDb;
export function getCollectionSummary(db: Db) {
const totals = getGlobalTotals(db);
const categories = getAllCategories(db);
const items = getAllItems(db);
const setups = getAllSetups(db);
const activeThreads = getAllThreads(db, false);
// Build items-by-category map
const itemsByCategory: Record<string, number> = {};
for (const item of items) {
const catName = item.categoryName;
itemsByCategory[catName] = (itemsByCategory[catName] ?? 0) + 1;
}
return {
overview: {
totalItems: totals?.itemCount ?? 0,
totalWeightGrams: totals?.totalWeight ?? 0,
totalCostCents: totals?.totalCost ?? 0,
categoryCount: categories.length,
setupCount: setups.length,
activeThreadCount: activeThreads.length,
},
itemsByCategory,
activeThreads: activeThreads.map((t) => ({
id: t.id,
name: t.name,
candidateCount: t.candidateCount,
category: t.categoryName,
})),
};
}