Skip to main content
Glama

get-comments

Retrieve and manage comments from any WordPress site by specifying site URL, username, and password. Filter by post ID, limit results per page, and paginate through comments efficiently.

Instructions

Get a list of comments from a WordPress site

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageNoPage number
passwordYesWordPress application password
perPageNoNumber of comments per page
postIdNoFilter comments by post ID
siteUrlYesWordPress site URL
usernameYesWordPress username

Implementation Reference

  • The async handler function for the 'get-comments' tool. It constructs API parameters, calls makeWPRequest to fetch comments from the WP REST API /wp-json/wp/v2/comments endpoint, formats the response, and returns a structured text content response.
    async ({ siteUrl, username, password, postId, perPage = 10, page = 1 }) => {
      try {
        const params: Record<string, any> = { per_page: perPage, page };
        if (postId !== undefined) params.post = postId;
        
        const comments = await makeWPRequest<WPComment[]>({
          siteUrl,
          endpoint: "comments",
          auth: { username, password },
          params
        });
        
        const formattedComments = Array.isArray(comments) ? comments.map(comment => ({
          id: comment.id,
          author_name: comment.author_name || "Anonymous",
          content: comment.content?.rendered || "No content",
          post: comment.post || "Unknown post",
          date: comment.date || "No date"
        })) : [];
        
        const commentsText = formattedComments.length > 0
          ? formattedComments.map(comment => 
              `ID: ${comment.id}\nAuthor: ${comment.author_name}\nDate: ${comment.date}\nContent: ${comment.content}\n---`
            ).join("\n")
          : "No comments found";
        
        return {
          content: [
            {
              type: "text",
              text: `Comments from ${siteUrl}${postId ? ` for post #${postId}` : ''}:\n\n${commentsText}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error retrieving comments: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • Zod input schema defining parameters for the get-comments tool: required siteUrl, username, password; optional postId, perPage (1-100), page.
      siteUrl: z.string().url().describe("WordPress site URL"),
      username: z.string().describe("WordPress username"),
      password: z.string().describe("WordPress application password"),
      postId: z.number().optional().describe("Filter comments by post ID"),
      perPage: z.number().min(1).max(100).optional().describe("Number of comments per page"),
      page: z.number().min(1).optional().describe("Page number"),
    },
  • src/index.ts:1007-1063 (registration)
    Registration of the 'get-comments' tool on the McpServer instance using server.tool(name, description, inputSchema, handlerFn).
    server.tool(
      "get-comments",
      "Get a list of comments from a WordPress site",
      {
        siteUrl: z.string().url().describe("WordPress site URL"),
        username: z.string().describe("WordPress username"),
        password: z.string().describe("WordPress application password"),
        postId: z.number().optional().describe("Filter comments by post ID"),
        perPage: z.number().min(1).max(100).optional().describe("Number of comments per page"),
        page: z.number().min(1).optional().describe("Page number"),
      },
      async ({ siteUrl, username, password, postId, perPage = 10, page = 1 }) => {
        try {
          const params: Record<string, any> = { per_page: perPage, page };
          if (postId !== undefined) params.post = postId;
          
          const comments = await makeWPRequest<WPComment[]>({
            siteUrl,
            endpoint: "comments",
            auth: { username, password },
            params
          });
          
          const formattedComments = Array.isArray(comments) ? comments.map(comment => ({
            id: comment.id,
            author_name: comment.author_name || "Anonymous",
            content: comment.content?.rendered || "No content",
            post: comment.post || "Unknown post",
            date: comment.date || "No date"
          })) : [];
          
          const commentsText = formattedComments.length > 0
            ? formattedComments.map(comment => 
                `ID: ${comment.id}\nAuthor: ${comment.author_name}\nDate: ${comment.date}\nContent: ${comment.content}\n---`
              ).join("\n")
            : "No comments found";
          
          return {
            content: [
              {
                type: "text",
                text: `Comments from ${siteUrl}${postId ? ` for post #${postId}` : ''}:\n\n${commentsText}`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error retrieving comments: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • TypeScript interface WPComment used to type the API response data in the handler.
    interface WPComment {
      id: number;
      author_name?: string;
      content?: {
        rendered: string;
      };
      post?: number;
      date?: string;
    }
  • Shared helper function makeWPRequest used by get-comments (and other tools) to make authenticated 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;
      }
    }
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 but only states the basic action. It doesn't cover critical aspects like authentication requirements (implied by parameters but not described), pagination behavior, rate limits, error conditions, or output format. For a tool with 6 parameters and no annotation coverage, this is a significant gap in transparency.

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, making it easy to parse quickly. Every part of the sentence contributes to understanding the core functionality.

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?

Given the complexity (6 parameters, no annotations, no output schema), the description is insufficiently complete. It doesn't explain authentication needs, pagination behavior, filtering options, or return values, leaving the agent with gaps in understanding how to use the tool effectively. For a data retrieval tool with multiple parameters, 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 fully documents all 6 parameters. The description adds no additional meaning beyond implying filtering by post (via 'postId') and pagination (via 'page' and 'perPage'), but these are already clear in the schema. This meets the baseline of 3 for high schema coverage without extra value.

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 verb ('Get') and resource ('list of comments from a WordPress site'), making the purpose unambiguous. However, it doesn't differentiate from sibling tools like 'get-post' or 'get-user' beyond the resource type, lacking specificity about scope or filtering capabilities that might distinguish it.

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. It doesn't mention siblings like 'get-post' (which might include comments) or 'create-comment', nor does it specify prerequisites like authentication or filtering options. This leaves the agent with minimal context for tool selection.

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