Skip to main content
Glama

get-category

Retrieve a specific WordPress category by ID using site URL, username, and application password. Integrates with WordPress MCP Server for secure API-based category management.

Instructions

Get a specific category by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryIdYesID of the category to retrieve
contextNoScope under which the request is madeview
passwordYesWordPress application password
siteUrlYesWordPress site URL
usernameYesWordPress username

Implementation Reference

  • Handler function for the 'get-category' tool. It makes an authenticated GET request to the WordPress REST API endpoint `/wp-json/wp/v2/categories/{categoryId}` and returns formatted category details or an error message.
      async ({ siteUrl, username, password, categoryId, context }) => {
        try {
          const category = await makeWPRequest<WPCategory>({
            siteUrl,
            endpoint: `categories/${categoryId}`,
            auth: { username, password },
            params: { context }
          });
          
          return {
            content: [
              {
                type: "text",
                text: `Category Details:\nID: ${category.id}\nName: ${category.name || "No name"}\nSlug: ${category.slug || "No slug"}\nDescription: ${category.description || "No description"}\nParent ID: ${category.parent || 0}\nPost Count: ${category.count || 0}`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error retrieving category: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • Zod input schema defining parameters for the 'get-category' tool: siteUrl, credentials, categoryId, and optional context.
      siteUrl: z.string().url().describe("WordPress site URL"),
      username: z.string().describe("WordPress username"),
      password: z.string().describe("WordPress application password"),
      categoryId: z.number().describe("ID of the category to retrieve"),
      context: z.enum(["view", "embed", "edit"]).optional().default("view").describe("Scope under which the request is made"),
    },
  • src/index.ts:1884-1886 (registration)
    Registration of the 'get-category' tool on the MCP server instance using server.tool() with name, description, input schema, and handler function.
    "get-category",
    "Get a specific category by ID",
    {
  • TypeScript interface defining the WPCategory type used for typing the API response in the 'get-category' handler.
    interface WPCategory {
      id: number;
      name?: string;
      slug?: string;
      description?: string;
      parent?: number;
      count?: number;
      meta?: Record<string, any>;
    }
  • Shared helper function makeWPRequest used by the 'get-category' handler to perform authenticated requests to the WordPress REST API.
    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;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the basic action without disclosing behavioral traits. It doesn't mention authentication needs (implied by parameters), rate limits, error handling, or what data is returned, leaving significant gaps for a tool with multiple required parameters.

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, efficient sentence that front-loads the core purpose without any wasted words. It's appropriately sized for a simple retrieval tool, making it easy to parse quickly.

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 tool with 5 parameters (4 required), no annotations, and no output schema, the description is inadequate. It doesn't explain authentication requirements, return values, or error conditions, leaving too much undefined for proper agent usage.

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 fully documents all 5 parameters. The description adds no additional meaning beyond implying 'categoryId' is used for retrieval, which is already clear from the schema. Baseline 3 is appropriate as the schema handles parameter documentation.

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 ('Get') and resource ('a specific category by ID'), making the purpose immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'list-categories' or 'get-post' beyond the resource name, missing explicit differentiation.

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?

No guidance is provided on when to use this tool versus alternatives like 'list-categories' for browsing or 'get-post' for other resources. The description lacks context about prerequisites or scenarios where this tool is appropriate.

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