MCP
Comments integrates with Craft’s Model Context Protocol (MCP) server so an AI client can work through your moderation queue, read an element’s comments as a thread, and approve, hold, mark as spam or remove comments. For example, you can ask a connected client what’s waiting for review on your latest blog post, approve the genuine comments and mark the rest as spam.
This integration requires Craft 5.12 or later. Comments still works on earlier supported Craft versions, but its MCP tools aren’t available there.
Connecting a Client
Follow Craft’s MCP setup instructions (opens new window) to connect a client through the authenticated HTTP server or the local mcp/serve command. Comments registers its tools automatically, so there’s no separate Comments server to install or enable. These tools aren’t exposed through Craft’s public MCP server.
The client acts as the signed-in user and follows Comments’ user permissions. Reading comments needs View comments, the moderation tools need Moderate comments, and removing or restoring a comment also needs Trash other users’ comments, as it does in the control panel. Nobody can change the status of their own comment. On a multi-site install, the tools only include comments posted on sites the user can edit. An HTTP connection authorised for read-only access can read comments and the moderation queue, and changing a status also requires write access.
Email addresses, IP addresses, user agents and the page a comment was posted from are only included for admins, as in the control panel. That applies wherever Craft’s MCP server returns a comment, including Craft’s own search_query tool, which finds no comments at all for someone who can’t view them.
Moderating Comments
Start with comments_moderation_queue to see what’s waiting, then use comments_set_status to decide it. comments_thread shows a comment in context, with the rest of the discussion on its element.
| Tool | Purpose |
|---|---|
comments_moderation_queue | Lists the comments under Needs review and Reported, oldest first, as the moderation sources in the Comments index do. Reported comments include each open report’s reason and details. Pass queue to choose one queue, elementId for comments on one element, such as an entry, and siteId for one site. limit (up to 50) and offset page through a single queue. |
comments_set_status | Moves up to 50 comments to approved, pending, spam or removed. Pass a reason when removing comments, and a note to keep an internal note for other moderators with each comment that changes. |
comments_thread | Returns the comments on an element as a nested thread, oldest first, with a count of each status. Pass statuses to choose which statuses to include, and limit (up to 200) to cap the number of comments. |
A status change makes the same decision a moderator would make in the control panel. It appears in the comment’s moderation history under the user’s name, sends the same notifications, tells your spam classifier when a comment is marked as spam or not spam, and fires the same events. Moving a pending comment to approved approves it, moving a spam comment to pending is Not spam, and moving an approved comment to pending holds it for review again. Setting a reported comment that’s already approved to approved is Keep, so it stays up and its open reports are dismissed. Removing a reported comment, or marking it as spam, resolves its reports.
Each comment succeeds or fails on its own, and the result says what happened to each one, such as a comment that was already approved or one the user can’t moderate. For example, these arguments to comments_set_status remove two comments as advertising:
{
"commentIds": [412, 415],
"status": "removed",
"reason": "advertising",
"note": "Same link posted on several entries."
}The removal reasons are off-topic, harassment, personal-information, advertising and other, the same reasons offered when removing a comment from its page in the control panel.
Working with Comment Elements
Comments also work with Craft’s elements_* tools, using the type comments. The comment reference handle works too.
| Tool | Purpose |
|---|---|
elements_schema | Describes the supported query criteria and the attributes an update accepts. |
elements_list | Finds comments using criteria such as ownerId (the element they’re on), moderationState, hasOpenReports, userId and parentId. Comments in every status are listed unless you pass status. |
elements_get | Reads an individual comment. |
elements_update | Changes a comment’s status, the same way as comments_set_status. Pass status, and optionally reason and note, in attributes. |
elements_validate | Checks whether a status change can be made, without making it. |
elements_delete | Moves a comment to Craft’s trash, or deletes it permanently with hardDelete. Both need Delete comments. |
elements_restore | Restores a comment from Craft’s trash, which needs Trash other users’ comments. |
Each comment includes its status, its heldReason while it waits for review (such as keyword or first-comment), its number of openReports, its author’s name, its text, the ID of the element it’s on and of the comment it replies to, and its dates. A status of author-removed means its author deleted it.
To take a comment down, set its status to removed rather than deleting it. Removing keeps the comment’s history and can be undone from its page in the control panel. Comments can’t be created, duplicated or edited through MCP, which includes their text, author, element and custom fields.
If you add comments to Craft’s public MCP server, it only returns approved comments’ public details, such as the author’s name and the comment’s text.