createCategory
Generate and manage new categories for organizing memos in the memo-mcp server. Specify a category name to streamline storage and retrieval.
Instructions
Create a new category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Implementation Reference
- src/server/tools.ts:167-172 (handler)The handler function for the 'createCategory' MCP tool. It invokes the repository function and formats the response with content and structuredContent.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 creating a category (name field).export const CreateCategorySchema = z.object({ name: z.string().min(1), }) export type CreateCategory = z.infer<typeof CreateCategorySchema>
- src/server/tools.ts:159-173 (registration)Registers the 'createCategory' tool with the MCP server, specifying input/output schemas, description, title, and the handler 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/repository/categories.ts:5-20 (helper)Repository helper function that creates a new category object with timestamps and ID, persists it to 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:3-10 (schema)Zod schema defining the full category structure used for output validation.export const CategorySchema = z.object({ createdAt: z.string().datetime(), id: z.string(), name: z.string().min(1), updatedAt: z.string().datetime(), }) export type Category = z.infer<typeof CategorySchema>