Skip to main content
Glama
hafizrahman

Weather & WordPress MCP Server

by hafizrahman

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)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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")}`, }, ], }; }
  • 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")}`, }, ], }; } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hafizrahman/wp-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server