deleteCategory
Remove a specific category from the memo-mcp server by providing its unique ID, ensuring efficient organization and management of memo categories.
Instructions
Delete a category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the category |
Implementation Reference
- src/repository/categories.ts:60-78 (handler)Core function implementing the logic to delete a category by ID from the database and update associated memos by clearing their categoryId.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)Registers the 'deleteCategory' MCP tool with input/output schemas and a thin wrapper handler that calls the core deleteCategory function and formats the MCP response.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)Zod schema defining the Category type, referenced in the outputSchema of the deleteCategory tool.export const CategorySchema = z.object({ createdAt: z.string().datetime(), id: z.string(), name: z.string().min(1), updatedAt: z.string().datetime(), })