Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ Manage multiple WordPress sites from a single MCP server:
- `get_site`: Get details about a specific site configuration
- `test_site`: Test connection to a specific WordPress site

All content and taxonomy tools support an optional `site_id` parameter to target specific sites.
All content, taxonomy, media, plugin, comment, and user tools support an optional `site_id` parameter to target specific sites.

### **Unified Content Management** (9 tools)

Handles ALL content types (posts, pages, custom post types) with a single set of intelligent tools:

- `list_content`: List any content type with filtering and pagination
- `list_content`: List any content type with filtering and pagination. Supports `fields` to select which top-level fields come back (e.g. `["id", "slug", "meta"]`) — see [Selecting fields](#selecting-fields).
- `get_content`: Get specific content by ID and type
- `create_content`: Create new content of any type
- `update_content`: Update existing content of any type, including targeted partial edits
Expand Down Expand Up @@ -266,11 +266,68 @@ with rest_base `documentation-categories`). Tools resolve the identifier via
`/wp/v2/taxonomies` and error on unknown taxonomies instead of guessing.
`assign_terms_to_content` verifies the write against the WordPress response
and reports an error if the terms were not actually saved.
`create_content` and `update_content` verify their `categories`/`tags` writes
the same way, but since the rest of the write (title, content, meta) did
apply, they report a warning alongside the successful result instead of an
error, naming the exact term IDs WordPress silently dropped.

#### Recipe Cards (WP Recipe Maker)

Sites running [WP Recipe Maker](https://wordpress.org/plugins/wp-recipe-maker/) (WPRM) store recipe cards in a separate `wprm_recipe` custom post type referenced by shortcode from the surrounding blog post. The unified content tools handle these recipes directly — no recipe-specific tool family is needed.

### Selecting fields

`list_content` and `get_content` return every field by default, and for post types
that carry long bodies that is almost always more than the caller wants — a
listing of four neighbourhood guides can run to 90KB of rendered HTML. Pass
`fields` to ask WordPress for a subset:

```json
{ "content_type": "post", "per_page": 20, "fields": ["id", "slug", "meta"] }
```

`get_content` takes the same parameter, which matters most on a single long post
where the rendered body is nearly the whole payload:

```json
{ "content_type": "post", "id": 5575, "fields": ["id", "slug", "meta"] }
```

One restriction there: `include_raw_content` reads `content.raw` off the
response, so a selection that doesn't deliver the raw body would return
successfully with no `content_raw` and no explanation. Combining the two is
rejected unless the selection includes `content` or `content.raw` — note that
`content.rendered` does **not** qualify, since it is a sibling subfield and
carries no raw body.

This maps to WordPress's own [`_fields`](https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields)
parameter, so nested paths work too (`title.rendered`), and a requested field an
item doesn't have is simply absent rather than an error.

Two behaviours worth knowing, both verified against a live site:

- **A selection drops `_links`** unless you name it. The HAL `_links` block is a
field like any other, so `["id", "slug"]` returns no links.
- **A selection naming only fields that don't exist returns empty objects**, not
an error and not an empty list — `_fields=typo` on a listing of two posts comes
back as `[{}, {}]`. Read that as "your field names were wrong", not "no posts".

Useful selections:

| Goal | `fields` |
| --- | --- |
| Inspect metadata (SEO keys, custom fields) | `["id", "slug", "meta"]` |
| Build an index or a link list | `["id", "title", "link"]` |
| Check publication state | `["id", "status", "modified"]` |
| Read a body exactly, for editing | `["id", "content"]` with `include_raw_content` |

Omit `fields` to get the full payload, which is the previous behaviour — minus
whatever `MCP_WP_STRIP_FIELDS` removes (`yoast_head` and `yoast_head_json` by
default). Those fields are deleted from every response after WordPress returns
them, so a selection asking only for them would come back as empty objects;
`list_content` errors in that case rather than returning a result that looks
like missing data.

**Reading recipes** — `get_content`, `list_content`, `find_content_by_url`, and `get_content_by_slug` all work with `content_type: "wprm_recipe"`. WPRM exposes the full structured recipe payload as a `recipe` field on the REST response, including ingredients, instructions, times, equipment, nutrition, notes, and rating.

**Writing recipes** — pass the recipe payload via `custom_fields.recipe` on `create_content` or `update_content`. WPRM hooks into the WordPress REST insert action (`rest_insert_wprm_recipe`) and reads `recipe` from the request body root, so any field documented by WPRM's data model is accepted.
Expand Down
19 changes: 13 additions & 6 deletions src/tools/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { z } from 'zod';

// Schema for listing comments
const listCommentsSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
page: z.coerce.number().optional().describe("Page number (default 1)"),
per_page: z.coerce.number().min(1).max(100).optional().describe("Items per page (default 10, max 100)"),
search: z.string().optional().describe("Search term for comment content"),
Expand All @@ -22,11 +23,13 @@ const listCommentsSchema = z.object({

// Schema for getting a single comment
const getCommentSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
id: z.coerce.number().describe("Comment ID")
}).strict();

// Schema for creating a comment
const createCommentSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
post: z.coerce.number().describe("The ID of the post object the comment is for"),
author: z.coerce.number().optional().describe("The ID of the user object, if the author is a registered user"),
author_name: z.string().optional().describe("Display name for the comment author"),
Expand All @@ -39,6 +42,7 @@ const createCommentSchema = z.object({

// Schema for updating a comment
const updateCommentSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
id: z.coerce.number().describe("Comment ID"),
post: z.coerce.number().optional().describe("The ID of the post object the comment is for"),
author: z.coerce.number().optional().describe("The ID of the user object, if the author is a registered user"),
Expand All @@ -52,6 +56,7 @@ const updateCommentSchema = z.object({

// Schema for deleting a comment
const deleteCommentSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
id: z.coerce.number().describe("Comment ID"),
force: z.boolean().optional().describe("Whether to bypass trash and force deletion")
}).strict();
Expand Down Expand Up @@ -96,7 +101,8 @@ export const commentTools: Tool[] = [
export const commentHandlers = {
list_comments: async (params: ListCommentsParams) => {
try {
const response = await makeWordPressRequest('GET', "comments", params);
const { site_id, ...query } = params;
const response = await makeWordPressRequest('GET', "comments", query, { siteId: site_id });
const comments: WPComment[] = response;
return {
toolResult: {
Expand All @@ -116,7 +122,7 @@ export const commentHandlers = {

get_comment: async (params: GetCommentParams) => {
try {
const response = await makeWordPressRequest('GET', `comments/${params.id}`);
const response = await makeWordPressRequest('GET', `comments/${params.id}`, undefined, { siteId: params.site_id });
const comment: WPComment = response;
return {
toolResult: {
Expand All @@ -136,7 +142,8 @@ export const commentHandlers = {

create_comment: async (params: CreateCommentParams) => {
try {
const response = await makeWordPressRequest('POST', "comments", params);
const { site_id, ...body } = params;
const response = await makeWordPressRequest('POST', "comments", body, { siteId: site_id });
const comment: WPComment = response;
return {
toolResult: {
Expand All @@ -156,8 +163,8 @@ export const commentHandlers = {

update_comment: async (params: UpdateCommentParams) => {
try {
const { id, ...updateData } = params;
const response = await makeWordPressRequest('POST', `comments/${id}`, updateData);
const { id, site_id, ...updateData } = params;
const response = await makeWordPressRequest('POST', `comments/${id}`, updateData, { siteId: site_id });
const comment: WPComment = response;
return {
toolResult: {
Expand All @@ -177,7 +184,7 @@ export const commentHandlers = {

delete_comment: async (params: DeleteCommentParams) => {
try {
const response = await makeWordPressRequest('DELETE', `comments/${params.id}`, { force: params.force });
const response = await makeWordPressRequest('DELETE', `comments/${params.id}`, { force: params.force }, { siteId: params.site_id });
const comment: WPComment = response;
return {
toolResult: {
Expand Down
19 changes: 14 additions & 5 deletions src/tools/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
// Make schema empty since the WordPress REST API plugins endpoint doesn't accept parameters
// in the same way as other endpoints
const listPluginsSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
status: z.enum(['active', 'inactive']).optional().default('active').describe("Filter plugins by status (active, inactive)")
}).strict();

const getPluginSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
plugin: z.string().describe("Plugin slug (e.g., 'akismet', 'elementor', 'wordpress-seo')")
}).strict();

const activatePluginSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
plugin: z.string().describe("Plugin slug (e.g., 'akismet', 'elementor', 'wordpress-seo')")
}).strict();

const deactivatePluginSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
plugin: z.string().describe("Plugin slug (e.g., 'akismet', 'elementor', 'wordpress-seo')")
}).strict();

const createPluginSchema = z.object({
site_id: z.string().optional().describe("Site ID (for multi-site setups)"),
slug: z.string({ required_error: "Plugin slug is required" }).describe("WordPress.org plugin directory slug, e.g., 'akismet', 'elementor', 'wordpress-seo'"),
status: z.enum(['inactive', 'active']).optional().default('active').describe("Plugin activation status")
}).strict();
Expand Down Expand Up @@ -70,7 +75,8 @@ export const pluginTools: Tool[] = [
export const pluginHandlers = {
list_plugins: async (params: z.infer<typeof listPluginsSchema>) => {
try {
const response = await makeWordPressRequest("GET", "plugins", params);
const { site_id, ...query } = params;
const response = await makeWordPressRequest("GET", "plugins", query, { siteId: site_id });
return {
toolResult: {
content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
Expand All @@ -88,7 +94,7 @@ export const pluginHandlers = {
},
get_plugin: async (params: z.infer<typeof getPluginSchema>) => {
try {
const response = await makeWordPressRequest("GET", `plugins/${params.plugin}`);
const response = await makeWordPressRequest("GET", `plugins/${params.plugin}`, undefined, { siteId: params.site_id });
return {
toolResult: {
content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
Expand All @@ -106,7 +112,8 @@ export const pluginHandlers = {
},
activate_plugin: async (params: z.infer<typeof activatePluginSchema>) => {
try {
const response = await makeWordPressRequest("POST", `plugins/${params.plugin}/activate`, params);
const { site_id, ...body } = params;
const response = await makeWordPressRequest("POST", `plugins/${params.plugin}/activate`, body, { siteId: site_id });
return {
toolResult: {
content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
Expand All @@ -124,7 +131,8 @@ export const pluginHandlers = {
},
deactivate_plugin: async (params: z.infer<typeof deactivatePluginSchema>) => {
try {
const response = await makeWordPressRequest("POST", `plugins/${params.plugin}/deactivate`, params);
const { site_id, ...body } = params;
const response = await makeWordPressRequest("POST", `plugins/${params.plugin}/deactivate`, body, { siteId: site_id });
return {
toolResult: {
content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
Expand All @@ -142,7 +150,8 @@ export const pluginHandlers = {
},
create_plugin: async (params: z.infer<typeof createPluginSchema>) => {
try {
const response = await makeWordPressRequest("POST", "plugins", params);
const { site_id, ...body } = params;
const response = await makeWordPressRequest("POST", "plugins", body, { siteId: site_id });
return {
toolResult: {
content: [{ type: "text", text: JSON.stringify(response, null, 2) }]
Expand Down
Loading
Loading