Create Category
createCategoryCreate a new category for organizing memos in the local database. Provide a unique category name to structure your memo collection.
Instructions
Create a new category
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes |
Implementation Reference
- src/repository/categories.ts:5-20 (handler)The core handler/logic for createCategory. Creates a new category with an auto-generated ID and timestamps, stores it in the database, and returns it.
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 } - src/schemas/categories.ts:12-16 (schema)Zod schema and TypeScript type for validating the createCategory input. Defines the expected shape: name (string, min length 1).
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, including its description, input schema (from CreateCategorySchema.shape), output schema, and the handler callback that invokes the repository function.
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/schemas/categories.ts:3-8 (schema)The CategorySchema used as the output schema for createCategory, defining the full category shape including id, name, createdAt, updatedAt.
export const CategorySchema = z.object({ createdAt: z.string().datetime(), id: z.string(), name: z.string().min(1), updatedAt: z.string().datetime(), })