Delete Category
deleteCategoryDelete a category by providing its unique ID to remove it from the memo database.
Instructions
Delete a category
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the category |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes |
Implementation Reference
- src/repository/categories.ts:60-78 (handler)The deleteCategory repository function that performs the actual deletion logic. It reads the database, finds the category by ID, splices it from the array, clears categoryId references on memos, writes back, and returns the deleted category (or undefined if not found).
export const deleteCategory = async ( id: string, ): Promise<Category | undefined> => { await db.read() const index = db.data.categories.findIndex((c) => c.id === id) if (index === -1) { return undefined } const deletedCategory = db.data.categories.splice(index, 1)[0] db.data.memos.forEach((memo) => { if (memo.categoryId === id) { memo.categoryId = undefined } }) await db.write() return deletedCategory } - src/server/tools.ts:246-270 (registration)Tool registration for 'deleteCategory' using server.registerTool. Defines input schema (id string), output schema (CategorySchema), and the handler that calls the deleteCategory repository function with error handling.
server.registerTool( "deleteCategory", { description: "Delete a category", inputSchema: { id: z.string().describe("The ID of the category"), }, outputSchema: { category: CategorySchema }, title: "Delete Category", }, async ({ id }) => { const deletedCategory = await deleteCategory(id) if (!deletedCategory) { return { content: [{ text: "Category not found", type: "text" }], isError: true, } } return { content: [{ text: JSON.stringify(deletedCategory), type: "text" }], structuredContent: { category: deletedCategory }, } }, ) - src/schemas/categories.ts:3-8 (schema)CategorySchema Zod definition used as the output schema for deleteCategory. Defines the shape of a Category object with id, name, createdAt, and updatedAt fields.
export const CategorySchema = z.object({ createdAt: z.string().datetime(), id: z.string(), name: z.string().min(1), updatedAt: z.string().datetime(), })