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

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "page": { "description": "Page number", "minimum": 1, "type": "number" }, "password": { "description": "WordPress application password", "type": "string" }, "perPage": { "description": "Number of comments per page", "maximum": 100, "minimum": 1, "type": "number" }, "postId": { "description": "Filter comments by post ID", "type": "number" }, "siteUrl": { "description": "WordPress site URL", "format": "uri", "type": "string" }, "username": { "description": "WordPress username", "type": "string" } }, "required": [ "siteUrl", "username", "password" ], "type": "object" }

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; } }

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