getCategory
Retrieve a specific category using its unique ID from the memo-mcp server, ensuring accurate and targeted data retrieval for memo management.
Instructions
Get a single category by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the category |
Implementation Reference
- src/server/tools.ts:203-216 (handler)The handler function that implements the core logic of the 'getCategory' MCP tool: fetches the category by ID from the repository, handles missing category with error response, and returns formatted content with structured data.async ({ id }) => { const category = await getCategory(id) if (!category) { return { content: [{ text: "Category not found", type: "text" }], isError: true, } } return { content: [{ text: JSON.stringify(category), type: "text" }], structuredContent: { category }, } },
- src/server/tools.ts:193-218 (registration)Registers the 'getCategory' tool on the MCP server, defining its name, description, input schema (id: string), output schema referencing CategorySchema, title, and references the handler function.server.registerTool( "getCategory", { description: "Get a single category by ID", inputSchema: { id: z.string().describe("The ID of the category"), }, outputSchema: { category: CategorySchema }, title: "Get Category", }, async ({ id }) => { const category = await getCategory(id) if (!category) { return { content: [{ text: "Category not found", type: "text" }], isError: true, } } return { content: [{ text: JSON.stringify(category), type: "text" }], structuredContent: { category }, } }, )
- src/schemas/categories.ts:3-8 (schema)Zod schema defining the structure of a Category object, used in the output schema of the getCategory tool.export const CategorySchema = z.object({ createdAt: z.string().datetime(), id: z.string(), name: z.string().min(1), updatedAt: z.string().datetime(), })
- src/repository/categories.ts:27-32 (helper)Repository helper function that reads the database and finds/retrieves a category by its ID.export const getCategory = async ( id: string, ): Promise<Category | undefined> => { await db.read() return db.data.categories.find((c) => c.id === id) }