Skip to main content
Glama

create-comment

Add comments to WordPress posts by specifying site URL, credentials, post ID, and content. Use this tool to automate comment creation with REST APIs for efficient site management.

Instructions

Create a new comment on a WordPress post

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
author_emailNoComment author email (for users who can't set this)
author_nameNoComment author name (for users who can't set this)
contentYesComment content
passwordYesWordPress application password
postIdYesID of the post to comment on
siteUrlYesWordPress site URL
usernameYesWordPress username

Implementation Reference

  • The main handler function that executes the tool logic: constructs comment data and makes a POST request to the WordPress /comments endpoint using the makeWPRequest helper.
    async ({ siteUrl, username, password, postId, content, author_name, author_email }) => {
      try {
        const commentData: Record<string, any> = {
          post: postId,
          content
        };
        
        if (author_name) commentData.author_name = author_name;
        if (author_email) commentData.author_email = author_email;
        
        const comment = await makeWPRequest<WPComment>({
          siteUrl,
          endpoint: "comments",
          method: "POST",
          auth: { username, password },
          data: commentData
        });
        
        return {
          content: [
            {
              type: "text",
              text: `Successfully created comment with ID: ${comment.id} on post #${postId}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error creating comment: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • Zod input schema defining parameters for the create-comment tool: siteUrl, username, password, postId, content, optional author_name and author_email.
    {
      siteUrl: z.string().url().describe("WordPress site URL"),
      username: z.string().describe("WordPress username"),
      password: z.string().describe("WordPress application password"),
      postId: z.number().describe("ID of the post to comment on"),
      content: z.string().describe("Comment content"),
      author_name: z.string().optional().describe("Comment author name (for users who can't set this)"),
      author_email: z.string().email().optional().describe("Comment author email (for users who can't set this)"),
    },
  • src/index.ts:1065-1114 (registration)
    Registration of the 'create-comment' tool using server.tool(), including name, description, input schema, and handler reference.
    server.tool(
      "create-comment",
      "Create a new comment on a WordPress post",
      {
        siteUrl: z.string().url().describe("WordPress site URL"),
        username: z.string().describe("WordPress username"),
        password: z.string().describe("WordPress application password"),
        postId: z.number().describe("ID of the post to comment on"),
        content: z.string().describe("Comment content"),
        author_name: z.string().optional().describe("Comment author name (for users who can't set this)"),
        author_email: z.string().email().optional().describe("Comment author email (for users who can't set this)"),
      },
      async ({ siteUrl, username, password, postId, content, author_name, author_email }) => {
        try {
          const commentData: Record<string, any> = {
            post: postId,
            content
          };
          
          if (author_name) commentData.author_name = author_name;
          if (author_email) commentData.author_email = author_email;
          
          const comment = await makeWPRequest<WPComment>({
            siteUrl,
            endpoint: "comments",
            method: "POST",
            auth: { username, password },
            data: commentData
          });
          
          return {
            content: [
              {
                type: "text",
                text: `Successfully created comment with ID: ${comment.id} on post #${postId}`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error creating comment: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • TypeScript interface defining the structure of a WordPress comment object, used in the makeWPRequest response typing.
    interface WPComment {
      id: number;
      author_name?: string;
      content?: {
        rendered: string;
      };
      post?: number;
      date?: string;
    }
  • Shared utility function for making authenticated HTTP requests to the WordPress REST API using axios, used by the create-comment handler.
    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 the full burden of behavioral disclosure. It states 'Create a new comment' which implies a write/mutation operation, but fails to mention authentication requirements (implied by parameters), potential side effects, error conditions, or response format. This leaves significant gaps for a tool that modifies data.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with zero wasted content.

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 no annotations and no output schema, the description is insufficient. It doesn't explain authentication requirements, error handling, what the response contains, or how it differs from sibling tools. Given the complexity of a 7-parameter write operation, more contextual information 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%, providing clear documentation for all 7 parameters. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline of 3 where the schema does the heavy lifting without compensating for gaps.

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 a new comment') and target resource ('on a WordPress post'), which is specific and unambiguous. However, it doesn't differentiate from sibling tools like 'create-post' or 'create-category' beyond the resource type, missing explicit sibling comparison.

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 'get-comments' or 'update-post'. It lacks context about prerequisites (e.g., authentication needs) or exclusions, offering only a basic statement of purpose without usage context.

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