complered tools 2 and guide

This commit is contained in:
southseact-3d
2026-02-08 20:15:38 +00:00
parent bd6817f697
commit b95efaebea
5 changed files with 1599 additions and 84 deletions

View File

@@ -0,0 +1,106 @@
# WP-CLI Testing MCP Server
This MCP server provides tools for testing WordPress plugins on an external WordPress multisite installation via WP-CLI over SSH.
## Tools Provided
### 1. test_plugin_external_wp
Runs automated CLI tests on an external WordPress installation with full isolation via multisite subsites.
**Features:**
- Automatic subsite provisioning (`wp site create`)
- Plugin upload and activation
- Dependency installation (WooCommerce, ACF, etc.)
- WP-CLI based test execution
- Automatic cleanup after delay
**Example:**
```json
{
"plugin_path": "/workspace/my-plugin",
"plugin_slug": "my-plugin",
"test_mode": "cli",
"required_plugins": [
{"plugin_slug": "woocommerce", "activate": true}
],
"test_scenarios": [
{
"name": "Plugin activates",
"type": "custom",
"wp_cli_command": "plugin activate my-plugin",
"assertions": {"wp_cli_success": true}
}
]
}
```
### 2. external_wp_testing_config
Returns the resolved configuration and validates required environment variables.
**Example:**
```json
{}
```
**Returns:**
```json
{
"ok": true,
"missing": [],
"config": {
"wpHost": "wp-test.example.com",
"wpSshUser": "wordpress",
"enableMultisite": true,
...
}
}
```
## How It's Loaded
This server is **NOT** loaded automatically. It's injected dynamically by the chat server only when:
1. The Builder "External WP CLI testing" toggle is enabled
2. The chat server sets `OPENCODE_EXTRA_MCP_SERVERS` environment variable
3. OpenCode reads that variable and adds this MCP server to its configuration
## Configuration
All configuration is via environment variables (see EXTERNAL_WP_CLI_TESTING_SETUP.md):
- `TEST_WP_HOST` - WordPress server hostname
- `TEST_WP_SSH_USER` - SSH username
- `TEST_WP_SSH_KEY` - Path to SSH private key
- `TEST_WP_PATH` - WordPress installation path
- `TEST_WP_BASE_URL` - Base URL of site
- `TEST_WP_MULTISITE` - Enable multisite (default: true)
- etc.
## Architecture
```
OpenCode (when toggle enabled)
↓ loads MCP server via OPENCODE_EXTRA_MCP_SERVERS
wp-cli-testing MCP Server
↓ imports ../../../chat/external-wp-testing.js
External WP Testing Module
↓ SSH connection
WordPress Multisite Test Server
↓ creates subsite
Isolated Test Environment
```
## Dependencies
This MCP server relies on:
- `@modelcontextprotocol/sdk` (provided by OpenCode)
- `zod` (provided by OpenCode)
- `../../../chat/external-wp-testing.js` (CommonJS module)
## Notes
- Only `test_mode: "cli"` is implemented (visual mode not yet supported)
- Requires WordPress multisite configured on external server
- All plugin operations happen on isolated subsites
- Automatic cleanup scheduled after test completion

View File

@@ -153,19 +153,26 @@ server.setRequestHandler(CallToolRequestSchema, async (req) => {
const args = (req.params.arguments ?? {})
// Lazy-load to avoid paying cost unless tool is actually invoked.
// Note: external-wp-testing.js is CommonJS; import default gives module.exports.
const externalTesting = await import("../../../chat/external-wp-testing.js")
const mod = externalTesting.default ?? externalTesting
const createExternalWpTester = mod?.createExternalWpTester
const getExternalTestingConfig = mod?.getExternalTestingConfig
// Note: external-wp-testing.js is CommonJS; when imported from ESM,
// exports are on .default for Node.js CommonJS modules
let createExternalWpTester
let getExternalTestingConfig
try {
const externalTesting = await import("../../../chat/external-wp-testing.js")
const mod = externalTesting.default ?? externalTesting
createExternalWpTester = mod?.createExternalWpTester
getExternalTestingConfig = mod?.getExternalTestingConfig
if (typeof createExternalWpTester !== "function" || typeof getExternalTestingConfig !== "function") {
if (typeof createExternalWpTester !== "function" || typeof getExternalTestingConfig !== "function") {
throw new Error("Required exports not found on module")
}
} catch (error) {
return {
content: [
{
type: "text",
text:
"wp-cli-testing MCP server misconfigured: could not load chat/external-wp-testing.js exports.",
text: `wp-cli-testing MCP server error: Failed to load chat/external-wp-testing.js - ${error.message}`,
},
],
isError: true,