Skip to main content
Glama

create-category

Efficiently add a new category to your WordPress site by specifying name, description, slug, and optional parent ID. Authenticates securely to streamline content organization.

Instructions

Create a new WordPress category

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNoHTML description of the term
metaNoMeta fields
nameYesHTML title for the term
parentNoThe parent term ID
passwordYesWordPress application password
siteUrlYesWordPress site URL
slugNoAn alphanumeric identifier for the term unique to its type
usernameYesWordPress username

Implementation Reference

  • Handler function that constructs category data and sends POST request to WordPress /wp-json/wp/v2/categories endpoint via makeWPRequest to create new category, returns success/error message.
    async ({ siteUrl, username, password, name, description, slug, parent, meta, }) => { try { const categoryData: Record<string, any> = { name }; if (description) categoryData.description = description; if (slug) categoryData.slug = slug; if (parent) categoryData.parent = parent; if (meta) categoryData.meta = meta; const category = await makeWPRequest<WPCategory>({ siteUrl, endpoint: "categories", method: "POST", auth: { username, password }, data: categoryData }); return { content: [ { type: "text", text: `Successfully created category:\nID: ${category.id}\nName: ${name}\nSlug: ${category.slug || "No slug"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error creating category: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
  • Zod input schema defining parameters for create-category tool: required siteUrl, username, password, name; optional description, slug, parent, meta.
    { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), name: z.string().describe("HTML title for the term"), description: z.string().optional().describe("HTML description of the term"), slug: z.string().optional().describe("An alphanumeric identifier for the term unique to its type"), parent: z.number().optional().describe("The parent term ID"), meta: z.record(z.any()).optional().describe("Meta fields"), },
  • src/index.ts:1924-1982 (registration)
    Tool registration via server.tool('create-category') call, including name, description, input schema, and handler function.
    server.tool( "create-category", "Create a new WordPress category", { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), name: z.string().describe("HTML title for the term"), description: z.string().optional().describe("HTML description of the term"), slug: z.string().optional().describe("An alphanumeric identifier for the term unique to its type"), parent: z.number().optional().describe("The parent term ID"), meta: z.record(z.any()).optional().describe("Meta fields"), }, async ({ siteUrl, username, password, name, description, slug, parent, meta, }) => { try { const categoryData: Record<string, any> = { name }; if (description) categoryData.description = description; if (slug) categoryData.slug = slug; if (parent) categoryData.parent = parent; if (meta) categoryData.meta = meta; const category = await makeWPRequest<WPCategory>({ siteUrl, endpoint: "categories", method: "POST", auth: { username, password }, data: categoryData }); return { content: [ { type: "text", text: `Successfully created category:\nID: ${category.id}\nName: ${name}\nSlug: ${category.slug || "No slug"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error creating category: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • Shared helper function makeWPRequest used by create-category (and other tools) to make authenticated HTTP requests to WordPress REST API endpoints.
    async function makeWPRequest<T>({ siteUrl, endpoint, method = 'GET', auth, data = null, params = null }: { siteUrl: string; endpoint: string; method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; auth: { username: string; password: string }; data?: any; params?: any; }): Promise<T> { const authString = Buffer.from(`${auth.username}:${auth.password}`).toString('base64'); try { const response = await axios({ method, url: `${siteUrl}/wp-json/wp/v2/${endpoint}`, headers: { 'Authorization': `Basic ${authString}`, 'Content-Type': 'application/json', }, data: data, params: params }); return response.data as T; } catch (error) { if (axios.isAxiosError(error) && error.response) { throw new Error(`WordPress API error: ${error.response.data?.message || error.message}`); } throw error; } }
  • TypeScript interface WPCategory used for typing the response from WordPress categories API in create-category tool.
    interface WPCategory { id: number; name?: string; slug?: string; description?: string; parent?: number; count?: number; meta?: Record<string, any>; }

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/prathammanocha/wordpress-mcp-server'

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