updateCategory
Modify a category by updating its name or other properties in the memo-mcp MCP server, ensuring accurate organization of recorded memos.
Instructions
Update a category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the category | |
| name | No |
Implementation Reference
- src/repository/categories.ts:34-58 (handler)Core handler function that updates a category by ID, optionally updating the name, and persists changes to the database.export const updateCategory = async ( id: string, { name }: UpdateCategory, ): Promise<Category | undefined> => { await db.read() const index = db.data.categories.findIndex((c) => c.id === id) if (index === -1) { return undefined } const existingCategory = db.data.categories[index] if (!existingCategory) { return undefined } const newCategory: Category = { ...existingCategory, ...(name ? { name } : {}), updatedAt: new Date().toISOString(), } db.data.categories[index] = newCategory await db.write() return newCategory }
- src/schemas/categories.ts:18-22 (schema)Zod schema and inferred TypeScript type for the UpdateCategory input parameters.export const UpdateCategorySchema = z.object({ name: z.string().min(1).optional(), }) export type UpdateCategory = z.infer<typeof UpdateCategorySchema>
- src/server/tools.ts:219-244 (registration)Registers the 'updateCategory' tool with the MCP server, defining input/output schemas and providing a handler that wraps the repository function, handles not-found cases, and formats the MCP response.server.registerTool( "updateCategory", { description: "Update a category", inputSchema: { id: z.string().describe("The ID of the category"), ...UpdateCategorySchema.shape, }, outputSchema: { category: CategorySchema }, title: "Update Category", }, async ({ id, ...category }) => { const updatedCategory = await updateCategory(id, category) if (!updatedCategory) { return { content: [{ text: "Category not found", type: "text" }], isError: true, } } return { content: [{ text: JSON.stringify(updatedCategory), type: "text" }], structuredContent: { category: updatedCategory }, } }, )