createCategory
Organize memos by creating new categories to group related information for easier retrieval and management.
Instructions
Create a new category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Implementation Reference
- src/server/tools.ts:167-173 (handler)MCP tool handler function for 'createCategory' that calls the repository function and formats the MCP response.async (category) => { const newCategory = await createCategory(category) return { content: [{ text: JSON.stringify(newCategory), type: "text" }], structuredContent: { category: newCategory }, } },
- src/schemas/categories.ts:12-16 (schema)Zod schema defining the input structure for the createCategory tool.export const CreateCategorySchema = z.object({ name: z.string().min(1), }) export type CreateCategory = z.infer<typeof CreateCategorySchema>
- src/server/tools.ts:159-174 (registration)Registration of the 'createCategory' tool with the MCP server, specifying schema, description, and handler.server.registerTool( "createCategory", { description: "Create a new category", inputSchema: CreateCategorySchema.shape, outputSchema: { category: CategorySchema }, title: "Create Category", }, async (category) => { const newCategory = await createCategory(category) return { content: [{ text: JSON.stringify(newCategory), type: "text" }], structuredContent: { category: newCategory }, } }, )
- src/repository/categories.ts:5-20 (helper)Repository function that performs the actual category creation logic using the database.export const createCategory = async ( category: CreateCategory, ): Promise<Category> => { const now = new Date().toISOString() const newCategory: Category = { ...category, createdAt: now, id: nanoid(), updatedAt: now, } db.data.categories.push(newCategory) await db.write() return newCategory }