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>;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a creation operation but doesn't mention authentication requirements (implied by parameters), potential side effects, error conditions, or what happens on success. For a mutation tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that efficiently communicates the core purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse while conveying essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 8 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain authentication needs, return values, error handling, or how it differs from sibling tools. Given the complexity and lack of structured data, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 8 parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, maintaining the baseline score of 3 for adequate but not enhanced parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Create') and resource ('a new WordPress category'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling tools like 'update-category' or 'list-categories' beyond the basic verb, missing explicit distinction that would warrant a score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'update-category' or 'list-categories', nor does it mention prerequisites or contextual constraints. It simply states what the tool does without indicating appropriate usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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