@automattic/mcp-wordpress-remote 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # MCP WordPress Remote
2
+
3
+ The mcp-wordpress-remote package acts as a bridge between local Model Context Protocol (MCP) clients and remote WordPress MCP servers. By leveraging npx, you can execute this package without a global installation, simplifying the setup process.
4
+
5
+ ## WordPress MCP plugin
6
+
7
+ You have to install the [wordpress-mcp](https://github.com/Automattic/wordpress-mcp) plugin on your WordPress website.
8
+
9
+ ## Why
10
+
11
+ 1. Most of the clients does not suport SSE or Streamable communications protocols.
12
+ 2. Improved eficiency. This proxy will not keep an open connection to your website, and it will only make simple REST API requests to your website when needed.
13
+ 3. Oauth2.1 is not yet available on wordpress out of the box.
14
+ 4. Security trough WordPress API passwords and WooCommerce REST API cosumer key and secret
15
+ 5. Easy to use. See installation instructions below.
16
+
17
+ ## Usage
18
+
19
+ ### Environment Variables
20
+
21
+ The following environment variables are required:
22
+
23
+ - `WP_API_URL`: The URL of your WordPress site (e.g., `https://example.com`)
24
+ - `WP_API_USERNAME`: Your WordPress username
25
+ - `WP_API_PASSWORD`: Your WordPress API password
26
+ - `WOO_CUSTOMER_KEY`: Your Woocommerce customer key (optional, if you intend to use WooCommerce MCP assets)
27
+ - `WOO_CUSTOMER_SECRET`: Your WooCommerce customer secret (optional, if you intend to use WooCommerce MCP assets)
28
+ - `LOG_FILE`: Optional full path to a log file
29
+
30
+ ### Configuration in MCP Clients
31
+
32
+ #### Claude Desktop
33
+
34
+ In order to add an MCP server to Claude Desktop you need to edit the configuration file located at:
35
+
36
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
37
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
38
+
39
+ Example configuration:
40
+
41
+ ```json
42
+ {
43
+ "mcpServers": {
44
+ "wordpress-mcp": {
45
+ "command": "npx",
46
+ "args": ["@Automattic/mcp-wordpress-remote"],
47
+ "env": {
48
+ "WP_API_URL": "https://your-wordpress-site.com",
49
+ "WP_API_USERNAME": "your-username",
50
+ "WP_API_PASSWORD": "your-password",
51
+ "WOO_CUSTOMER_KEY": "your-woo-customer-key",
52
+ "WOO_CUSTOMER_SECRET": "your-woo-customer-secret",
53
+ "LOG_FILE": "optional full path to the log file"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ https://woocommerce.com/document/woocommerce-rest-api/
61
+
62
+ #### Cursor
63
+
64
+ The configuration file is located at `~/.cursor/mcp.json`.
65
+
66
+ Example configuration:
67
+
68
+ ```json
69
+ {
70
+ "mcpServers": {
71
+ "wordpress-mcp": {
72
+ "command": "npx",
73
+ "args": ["@Automattic/mcp-wordpress-remote"],
74
+ "env": {
75
+ "WP_API_URL": "https://your-wordpress-site.com",
76
+ "WP_API_USERNAME": "your-username",
77
+ "WP_API_PASSWORD": "your-password",
78
+ "WOO_CUSTOMER_KEY": "your-woo-customer-key",
79
+ "WOO_CUSTOMER_SECRET": "your-woo-customer-secret",
80
+ "LOG_FILE": "optional full path to the log file"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## @todo
88
+
89
+ As of now, this package is in its early development stages. Any suggestions, bugreports, PR's are welcome.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/proxy.js ADDED
@@ -0,0 +1,274 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/proxy.ts
4
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
5
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+
7
+ // src/lib/utils.ts
8
+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
9
+ import * as fs from "node:fs";
10
+ import * as path from "node:path";
11
+ var LOG_DIR = process.env.LOG_DIR || path.join(process.cwd(), "logs");
12
+ var LOG_FILE = process.env.LOG_FILE || path.join(LOG_DIR, "mcp-proxy.log");
13
+ if (process.env.LOG_FILE || process.env.LOG_DIR) {
14
+ const logDir = path.dirname(LOG_FILE);
15
+ if (!fs.existsSync(logDir)) {
16
+ fs.mkdirSync(logDir, { recursive: true });
17
+ }
18
+ }
19
+ function log(message, ...args) {
20
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
21
+ const formattedArgs = args.length > 0 ? args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : arg).join(" ") : "";
22
+ const logMessage = `${timestamp}: ${message}${formattedArgs ? " " + formattedArgs : ""}
23
+ `;
24
+ if (process.env.LOG_FILE || process.env.LOG_DIR) {
25
+ fs.appendFileSync(LOG_FILE, logMessage);
26
+ }
27
+ }
28
+
29
+ // src/lib/wordpress-api.ts
30
+ function validateEnvironment() {
31
+ const requiredEnvVars = ["WP_API_URL", "WP_API_USERNAME", "WP_API_PASSWORD"];
32
+ const missingVars = requiredEnvVars.filter((varName) => !process.env[varName]);
33
+ if (missingVars.length > 0) {
34
+ throw new Error(
35
+ `Missing required environment variables: ${missingVars.join(
36
+ ", "
37
+ )}. Please set these variables before starting the server.`
38
+ );
39
+ }
40
+ }
41
+ async function wpRequest(params = { method: "init" }) {
42
+ validateEnvironment();
43
+ const endpoint = "wp/v2/wpmcp";
44
+ const method = "POST";
45
+ const baseUrl = process.env.WP_API_URL;
46
+ log(`Request method: ${params.method || "init"}`);
47
+ log(`Request args: ${JSON.stringify(params.args || {})}`);
48
+ let username;
49
+ let password;
50
+ if (params.method === "tools/call" && params.args && params.args.tool && params.args.tool.startsWith("wc_reports_")) {
51
+ username = process.env.WOO_CUSTOMER_KEY;
52
+ password = process.env.WOO_CUSTOMER_SECRET;
53
+ log(`Using WooCommerce credentials for tool: ${params.args.tool}`);
54
+ if (!username || !password) {
55
+ throw new Error(
56
+ "Missing WooCommerce credentials. Please set WOO_CUSTOMER_KEY and WOO_CUSTOMER_SECRET environment variables."
57
+ );
58
+ }
59
+ } else {
60
+ username = process.env.WP_API_USERNAME;
61
+ password = process.env.WP_API_PASSWORD;
62
+ log(`Using WordPress credentials for method: ${params.method || "init"}`);
63
+ }
64
+ log(`Username length: ${username ? username.length : 0}`);
65
+ log(`Password length: ${password ? password.length : 0}`);
66
+ log(`Environment: ${process.env.NODE_ENV || "development"}`);
67
+ log(`API URL: ${baseUrl}`);
68
+ const auth = Buffer.from(`${username}:${password}`).toString("base64");
69
+ log(`Auth header length: ${auth.length}`);
70
+ const url = new URL(`/wp-json/${endpoint}`, baseUrl).toString();
71
+ log(`Requesting URL: ${url}`);
72
+ const headers = {
73
+ Authorization: `Basic ${auth}`,
74
+ "Content-Type": "application/json"
75
+ };
76
+ const fetchOptions = {
77
+ method,
78
+ headers,
79
+ body: JSON.stringify(params)
80
+ };
81
+ try {
82
+ log(`Sending request to WordPress API...`);
83
+ const response = await fetch(url, fetchOptions);
84
+ log(`Response status: ${response.status}`);
85
+ if (!response.ok) {
86
+ const errorText = await response.text();
87
+ log(`Error response: ${errorText}`);
88
+ throw new Error(`WordPress API error (${response.status}): ${errorText}`);
89
+ }
90
+ const responseData = await response.json();
91
+ log(`Response received successfully`);
92
+ return responseData;
93
+ } catch (error) {
94
+ log(`Error in wpRequest: ${error instanceof Error ? error.message : String(error)}`);
95
+ throw error;
96
+ }
97
+ }
98
+
99
+ // src/proxy.ts
100
+ import {
101
+ CallToolRequestSchema,
102
+ ListResourcesRequestSchema,
103
+ ListToolsRequestSchema,
104
+ ListPromptsRequestSchema,
105
+ GetPromptRequestSchema,
106
+ ListResourceTemplatesRequestSchema,
107
+ ReadResourceRequestSchema,
108
+ SubscribeRequestSchema,
109
+ UnsubscribeRequestSchema,
110
+ SetLevelRequestSchema,
111
+ CompleteRequestSchema,
112
+ ListRootsRequestSchema
113
+ } from "@modelcontextprotocol/sdk/types.js";
114
+ async function WordPressProxy() {
115
+ const init = await wpRequest({ method: "init" });
116
+ const server = new Server(
117
+ {
118
+ name: init.serverInfo.name,
119
+ version: init.serverInfo.version
120
+ },
121
+ {
122
+ capabilities: init.capabilities
123
+ // Type assertion to fix linter error
124
+ }
125
+ );
126
+ const withLogging = (schema, handler) => async (request) => {
127
+ log(`Received ${schema} request:`, JSON.stringify(request));
128
+ const response = await handler(request);
129
+ log(`${schema} response:`, JSON.stringify(response));
130
+ return response;
131
+ };
132
+ server.setRequestHandler(
133
+ ListToolsRequestSchema,
134
+ withLogging("ListTools", async (request) => {
135
+ log("Processing ListToolsRequest");
136
+ const response = await wpRequest({
137
+ method: "tools/list",
138
+ cursor: request.params?.cursor
139
+ });
140
+ return response;
141
+ })
142
+ );
143
+ server.setRequestHandler(
144
+ CallToolRequestSchema,
145
+ withLogging("CallTool", async (request) => {
146
+ log("Processing CallToolRequest");
147
+ const response = await wpRequest({
148
+ method: "tools/call",
149
+ name: request.params.name,
150
+ arguments: request.params.arguments
151
+ });
152
+ return response;
153
+ })
154
+ );
155
+ server.setRequestHandler(
156
+ ListResourcesRequestSchema,
157
+ withLogging("ListResources", async (request) => {
158
+ log("Processing ListResourcesRequest");
159
+ const response = await wpRequest({
160
+ method: "resources/list",
161
+ cursor: request.params?.cursor
162
+ });
163
+ return response;
164
+ })
165
+ );
166
+ server.setRequestHandler(
167
+ ListResourceTemplatesRequestSchema,
168
+ withLogging("ListResourceTemplates", async (request) => {
169
+ log("Processing ListResourceTemplatesRequest");
170
+ const response = await wpRequest({
171
+ method: "resources/templates/list",
172
+ cursor: request.params?.cursor
173
+ });
174
+ return response;
175
+ })
176
+ );
177
+ server.setRequestHandler(
178
+ ReadResourceRequestSchema,
179
+ withLogging("ReadResource", async (request) => {
180
+ log("Processing ReadResourceRequest");
181
+ const response = await wpRequest({
182
+ method: "resources/read",
183
+ uri: request.params.uri
184
+ });
185
+ return response;
186
+ })
187
+ );
188
+ server.setRequestHandler(
189
+ SubscribeRequestSchema,
190
+ withLogging("Subscribe", async (request) => {
191
+ log("Processing SubscribeRequest");
192
+ const response = await wpRequest({
193
+ method: "resources/subscribe",
194
+ uri: request.params.uri
195
+ });
196
+ return response;
197
+ })
198
+ );
199
+ server.setRequestHandler(
200
+ UnsubscribeRequestSchema,
201
+ withLogging("Unsubscribe", async (request) => {
202
+ log("Processing UnsubscribeRequest");
203
+ const response = await wpRequest({
204
+ method: "resources/unsubscribe",
205
+ uri: request.params.uri
206
+ });
207
+ return response;
208
+ })
209
+ );
210
+ server.setRequestHandler(
211
+ ListPromptsRequestSchema,
212
+ withLogging("ListPrompts", async (request) => {
213
+ log("Processing ListPromptsRequest");
214
+ const response = await wpRequest({
215
+ method: "prompts/list",
216
+ cursor: request.params?.cursor
217
+ });
218
+ return response;
219
+ })
220
+ );
221
+ server.setRequestHandler(
222
+ GetPromptRequestSchema,
223
+ withLogging("GetPrompt", async (request) => {
224
+ log("Processing GetPromptRequest");
225
+ const response = await wpRequest({
226
+ method: "prompts/get",
227
+ name: request.params.name,
228
+ arguments: request.params.arguments
229
+ });
230
+ return response;
231
+ })
232
+ );
233
+ server.setRequestHandler(
234
+ SetLevelRequestSchema,
235
+ withLogging("SetLevel", async (request) => {
236
+ log("Processing SetLevelRequest");
237
+ const response = await wpRequest({
238
+ method: "logging/setLevel",
239
+ level: request.params.level
240
+ });
241
+ return response;
242
+ })
243
+ );
244
+ server.setRequestHandler(
245
+ CompleteRequestSchema,
246
+ withLogging("Complete", async (request) => {
247
+ log("Processing CompleteRequest");
248
+ const response = await wpRequest({
249
+ method: "completion/complete",
250
+ ref: request.params.ref,
251
+ argument: request.params.argument
252
+ });
253
+ return response;
254
+ })
255
+ );
256
+ server.setRequestHandler(
257
+ ListRootsRequestSchema,
258
+ withLogging("ListRoots", async (request) => {
259
+ log("Processing ListRootsRequest");
260
+ const response = await wpRequest({
261
+ method: "roots/list"
262
+ });
263
+ return response;
264
+ })
265
+ );
266
+ const transport = new StdioServerTransport();
267
+ server.connect(transport).then(() => {
268
+ log("MCP server connected to transport successfully");
269
+ }).catch((error) => {
270
+ log(`Error starting MCP server:`, error);
271
+ process.exit(1);
272
+ });
273
+ }
274
+ WordPressProxy();
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@automattic/mcp-wordpress-remote",
3
+ "version": "0.1.6",
4
+ "description": "MCP WordPress Remote proxy server",
5
+ "keywords": [
6
+ "mcp",
7
+ "wordpress",
8
+ "remote",
9
+ "proxy"
10
+ ],
11
+ "author": "Automattic Inc.",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Automattic/mcp-wordpress-remote.git"
15
+ },
16
+ "type": "module",
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "main": "dist/proxy.js",
23
+ "bin": {
24
+ "@automattic/mcp-wordpress-remote": "dist/proxy.js"
25
+ },
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "build:watch": "tsup --watch",
29
+ "check": "prettier --check . && tsc",
30
+ "start": "node dist/proxy.js",
31
+ "dev": "NODE_ENV=development node dist/proxy.js",
32
+ "test": "jest",
33
+ "test:watch": "jest --watch"
34
+ },
35
+ "dependencies": {
36
+ "@modelcontextprotocol/sdk": "^1.8.0",
37
+ "express": "^4.18.2",
38
+ "open": "^10.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/express": "^4.17.21",
42
+ "@types/jest": "^29.5.12",
43
+ "@types/node": "^20.11.19",
44
+ "jest": "^29.7.0",
45
+ "prettier": "^3.2.5",
46
+ "ts-jest": "^29.1.2",
47
+ "tsup": "^8.0.2",
48
+ "typescript": "^5.3.3"
49
+ },
50
+ "tsup": {
51
+ "entry": [
52
+ "src/proxy.ts"
53
+ ],
54
+ "format": [
55
+ "esm"
56
+ ],
57
+ "dts": true,
58
+ "clean": true,
59
+ "outDir": "dist"
60
+ },
61
+ "jest": {
62
+ "preset": "ts-jest",
63
+ "testEnvironment": "node",
64
+ "testMatch": [
65
+ "**/__tests__/**/*.ts",
66
+ "**/?(*.)+(spec|test).ts"
67
+ ],
68
+ "moduleFileExtensions": [
69
+ "ts",
70
+ "js",
71
+ "json",
72
+ "node"
73
+ ]
74
+ }
75
+ }