MCP client: bridge external MCP servers as built-in tools (closes #38) - #51
Merged
Conversation
6 tasks
Adds a wp-admin → openclaWP → MCP Clients page that lets admins register external MCP servers and have their advertised tools surface in the local ability registry under the `mcp/<server>/<tool>` prefix, so agents can call them just like any other ability. v1 ships: * `OpenclaWP_Mcp_Client_Store` — CPT-backed store for server configs (transport, command/args/env or url/headers, per-tool allowlist + disabled list, cached tool metadata, last-error). * `OpenclaWP_Mcp_Client_Transport` — thin MCP 2025-06-18 JSON-RPC client. Implements initialize + tools/list + tools/call over stdio (`proc_open`) and over Streamable HTTP (`wp_remote_post`). * `OpenclaWP_Mcp_Client_Bridge` — registers each enabled server's non-disabled, allowlisted tools as WP abilities under `mcp/<slug>/…` and proxies execution back through the transport. Errors surface as WP_Errors so the loop's tool mediator can degrade gracefully. * `OpenclaWP_Mcp_Clients_Admin` — list / add / edit / re-test / per-tool enable-disable / delete. Three one-click recipes: Fetch (works out of the box), Context7 (needs CONTEXT7_API_KEY), GitHub MCP (needs GITHUB_PERSONAL_ACCESS_TOKEN). * Unit tests assert that bridged tools show up under the `mcp/` prefix, that disabled/allowlist filtering works, and that unsafe tool names are sanitised in the ability path while preserving the original server-native name for tools/call round-trip. Deferred to follow-ups: * HTTP transport is wired but unproven against a real server. * Catalog-mode integration with #1 (tool-discovery meta-tools). * OAuth flow for MCP servers that require it (current http path supports static bearer headers via the config UI). Closes #38
lezama
force-pushed
the
ship/issue-38-mcp-client-bridge
branch
from
May 18, 2026 10:48
f77aad2 to
358d764
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #38
Summary
Adds a wp-admin → openclaWP → MCP Clients page that lets admins register external MCP servers and have their advertised tools surface in the local ability registry under
mcp/<server>/<tool>, so agents can call them just like any other ability.What ships
OpenclaWP_Mcp_Client_Store— CPT-backed store for server configs (transport, command/args/env or url/headers, per-tool allowlist + disabled list, cached tool metadata, last-error).OpenclaWP_Mcp_Client_Transport— thin MCP 2025-06-18 JSON-RPC client. Implementsinitialize+tools/list+tools/callover stdio (proc_open) and over Streamable HTTP (wp_remote_post).OpenclaWP_Mcp_Client_Bridge— registers each enabled server's non-disabled, allowlisted tools as WP abilities undermcp/<slug>/…and proxies execution back through the transport. Errors surface asWP_Errors so the loop's tool-call mediator can degrade gracefully ("the X tool is unavailable…").OpenclaWP_Mcp_Clients_Admin— list / add / edit / re-test / per-tool enable-disable / delete. Three one-click recipes:npx -y @modelcontextprotocol/server-fetch, works out of the box.npx -y @upstash/context7-mcp, needsCONTEXT7_API_KEY.npx -y @modelcontextprotocol/server-github, needsGITHUB_PERSONAL_ACCESS_TOKEN.No new PHP or JS dependencies. The transport uses PHP's built-in
proc_openand WordPress'swp_remote_post.Test plan
vendor/bin/phpunit --testsuite unit— 41 tests, 88 assertions, all green (9 new tests undertests/unit/McpClientBridgeTest.php).php tests/smoke.php— exits 0 (full smoke needs a real WP viastudio wp eval-file).npm run lint— clean.npm run build— webpack compiled successfully.fetchtool advertised, attachmcp/fetch/fetchto an agent'sdefault_config['tools'], ask the agent "fetch https://example.com" — agent receives the markdown.What's deferred
openclawp-mcp-clientscategory so a future catalog layer can filter them as a group.Hard rules
vendor/automattic/agents-api/..mcp.jsonat the repo root — the admin page is the canonical surface.composer.jsonunchanged.package.jsonunchanged (lockfile has onlypeer-flag reclassifications fromnpm install).