Skip to content

feat: plugin, comment, and user tools accept site_id (multi-site) - #39

Open
kleintech wants to merge 1 commit into
InstaWP:mainfrom
kleintech:feat/site-id-plugins-comments-users
Open

kleintech wants to merge 1 commit into
InstaWP:mainfrom
kleintech:feat/site-id-plugins-comments-users

Conversation

@kleintech

Copy link
Copy Markdown
Contributor

Bug

The plugin, comment, and user tools are the only WordPress-hitting tools without a site_id parameter. Worse than a rejection: the MCP SDK builds its validator from each tool's inputSchema.properties as a plain (non-strict) z.object, so a supplied site_id is silently stripped before the handler runs — the call goes to the default site with a clean success and no signal that the wrong site answered. In a multi-site configuration there is no way to inspect or moderate a secondary site's plugins, comments, or users.

The README's multi-site section already promises: "all tools accept an optional site_id parameter to target specific sites."

Fix

All fifteen schemas (list/get/activate/deactivate/create_plugin, the five comment tools, the five user tools) declare the same optional site_id the other tool groups use, and each handler threads it through as makeWordPressRequest's { siteId } option — excluding it from the query/body, since these handlers pass params straight through as the payload and site_id would otherwise leak into the REST request.

With site_id omitted, every handler's payload is unchanged — verified by capturing all fifteen call shapes on both revisions and diffing (identical methods, endpoints, data values, and key order). The tool-overview line in the README now names all six groups; after this, the only tools without site_id are the two wordpress.org-repository lookups and list_sites, none of which target a site.

Tests

tests/tools/site-id-routing.test.ts, 31 tests through the mocked transport. Each handler uses a per-handler site id (cross-wired or hardcoded routing can't pass), and each is exercised both with site_id (siteId lands in options, payload deep-equals the exact pre-change payload, no site_id key in it) and without (siteId undefined, same payload — guards every existing caller). A schema-shape test pins that all fifteen tools declare site_id, since a property missing from inputSchema.properties is stripped by the SDK before the handler ever sees it.

Full suite 66 passed / 2 skipped, green under --sequence.shuffle, tsc clean.

Suggested CHANGELOG entry (release-time backfill, per repo convention):

Added

  • site_id on all plugin, comment, and user tools. These fifteen were the only WordPress-hitting tools without it; in multi-site configs a supplied site_id was silently stripped and the default site answered.

🤖 Generated with Claude Code

https://claude.ai/code/session_012xFYsxskaCvMkg5mDw2iVH

…n target any site

The plugin, comment, and user tools were the only WordPress-hitting
tools without a site_id parameter. The MCP SDK builds its validator from
each tool's inputSchema.properties as a plain (non-strict) z.object, so
a supplied site_id was SILENTLY STRIPPED before the handler ran and the
call went to the default site with no error — in a multi-site
configuration there was no way to inspect or moderate a secondary site's
plugins, comments, or users, and no signal that the wrong site had
answered. The README's multi-site section already promises "all tools
accept an optional site_id parameter".

Each of the fifteen schemas now declares the same optional site_id used
by the other tool groups, and each handler threads it through as the
request's { siteId } option, excluding it from the query/body sent to
WordPress (handlers passed `params` straight through as the payload, so
site_id would otherwise have leaked into the REST request). With site_id
omitted, every handler's payload is byte-identical to before — verified
by capturing all fifteen call shapes on both revisions and diffing.
README's tool-overview line now names all six groups.

Tests cover all fifteen handlers through the mocked transport, each with
a per-handler site id (so cross-wired or hardcoded routing cannot pass),
asserting: siteId lands in the request options; the payload deep-equals
the exact pre-change payload both with and without site_id; site_id
never appears in the payload; and every tool's input schema declares
site_id (a property missing from the schema is stripped by the SDK
before the handler sees it).

Co-Authored-By: Claude <noreply@anthropic.com>
@kleintech

Copy link
Copy Markdown
Contributor Author

Adversarial review record (one independent reviewer; findings verified, then fixed before this PR was opened):

Found and fixed: the first version of the test file injected the same site id everywhere and never exercised the no-site_id path, so three mutants survived (dropping the activate body, dropping create_user's fields, hardcoding the routed site id). Rewritten with per-handler site ids and exact expected-payload assertions with and without site_id; all three mutants now fail 2 tests each. Also corrected a factual error: .strict() on these schemas never reaches MCP validation (the SDK wraps inputSchema.properties in a plain z.object — verified by parsing unknown keys through all 15 tools), so the pre-change behavior was silent stripping, not rejection; commit message, tests, and this PR describe it accordingly.

Clean, confirmed: payloads byte-identical to main for all fifteen handlers with site_id omitted (captured and diffed on both revisions, including key order — site_id declared first in each schema keeps the rest-spread order stable); .strict() counts undisturbed; unknown site_id surfaces siteManager's "Site 'X' not found" through each handler's catch; 41/44 tools now declare site_id, the three without being the two wordpress.org lookups and list_sites.

Noted, pre-existing, untouched: zodToJsonSchema imported unused in plugins.ts/users.ts; DELETE payloads ride the request body rather than query params (affects force); site aliases aren't resolved by siteManager.getSite() despite the README documenting them — consistent with every existing site_id tool.

@kilo-code-bot

kilo-code-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

Kilo Code Review could not run — your account is out of credits.

Add credits or switch to a free model to enable reviews on this change.

kleintech added a commit to kleintech/mcp-wp that referenced this pull request Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant