get-categories
Retrieve all post categories from the hafiz.blog WordPress site to organize content and improve navigation.
Instructions
Get all categories available on hafiz.blog (WordPress.com)
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-categories"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:219-241 (handler)The handler function for the 'get-categories' tool. It fetches categories from the WordPress.com API endpoint, handles empty results, formats the category list with name and slug, and returns formatted text content.
async () => { const categoriesUrl = `${WP_COM_API_BASE}/categories?per_page=50&_fields=id,name,slug`; const categories = await fetchJson<WPCategory[]>(categoriesUrl); if (!categories || categories.length === 0) { return { content: [{ type: "text", text: "No categories found" }], }; } const formattedCategories = categories.map((category) => `Category: ${category.name} (Slug: ${category.slug})` ); return { content: [ { type: "text", text: `Categories on hafiz.blog:\n\n${formattedCategories.join("\n")}`, }, ], }; } - src/index.ts:209-213 (schema)TypeScript interface defining the WordPress category structure used for typing the API response in the get-categories handler.
interface WPCategory { id: number; name: string; slug: string; } - src/index.ts:215-242 (registration)Registration of the 'get-categories' tool using McpServer.tool method, with tool name, description, empty input schema (no parameters), and inline handler function.
server.tool( "get-categories", "Get all categories available on hafiz.blog (WordPress.com)", {}, async () => { const categoriesUrl = `${WP_COM_API_BASE}/categories?per_page=50&_fields=id,name,slug`; const categories = await fetchJson<WPCategory[]>(categoriesUrl); if (!categories || categories.length === 0) { return { content: [{ type: "text", text: "No categories found" }], }; } const formattedCategories = categories.map((category) => `Category: ${category.name} (Slug: ${category.slug})` ); return { content: [ { type: "text", text: `Categories on hafiz.blog:\n\n${formattedCategories.join("\n")}`, }, ], }; } );