@automattic/mcp-wordpress-remote 0.1.18 → 0.2.0

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.
Files changed (2) hide show
  1. package/dist/proxy.js +61 -28
  2. package/package.json +2 -2
package/dist/proxy.js CHANGED
@@ -20,6 +20,7 @@ function log(message, ...args) {
20
20
  const formattedArgs = args.length > 0 ? args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : arg).join(" ") : "";
21
21
  const logMessage = `${timestamp}: ${message}${formattedArgs ? " " + formattedArgs : ""}
22
22
  `;
23
+ console.error(logMessage.trim());
23
24
  if (LOG_FILE) {
24
25
  fs.appendFileSync(LOG_FILE, logMessage);
25
26
  }
@@ -27,14 +28,26 @@ function log(message, ...args) {
27
28
 
28
29
  // src/lib/wordpress-api.ts
29
30
  function validateEnvironment() {
30
- const requiredEnvVars = ["WP_API_URL", "WP_API_USERNAME", "WP_API_PASSWORD"];
31
- const missingVars = requiredEnvVars.filter((varName) => !process.env[varName]);
32
- if (missingVars.length > 0) {
33
- throw new Error(
34
- `Missing required environment variables: ${missingVars.join(
35
- ", "
36
- )}. Please set these variables before starting the server.`
37
- );
31
+ if (process.env.JWT_TOKEN) {
32
+ const requiredEnvVars = ["WP_API_URL"];
33
+ const missingVars = requiredEnvVars.filter((varName) => !process.env[varName]);
34
+ if (missingVars.length > 0) {
35
+ throw new Error(
36
+ `Missing required environment variables: ${missingVars.join(
37
+ ", "
38
+ )}. Please set these variables before starting the server.`
39
+ );
40
+ }
41
+ } else {
42
+ const requiredEnvVars = ["WP_API_URL", "WP_API_USERNAME", "WP_API_PASSWORD"];
43
+ const missingVars = requiredEnvVars.filter((varName) => !process.env[varName]);
44
+ if (missingVars.length > 0) {
45
+ throw new Error(
46
+ `Missing required environment variables: ${missingVars.join(
47
+ ", "
48
+ )}. Please set JWT_TOKEN or provide ${missingVars.join(", ")}.`
49
+ );
50
+ }
38
51
  }
39
52
  }
40
53
  function removeTrailingSlash(url) {
@@ -47,32 +60,40 @@ async function wpRequest(params = { method: "init" }) {
47
60
  const baseUrl = removeTrailingSlash(process.env.WP_API_URL);
48
61
  log(`Request method: ${params.method || "init"}`);
49
62
  log(`Request args: ${JSON.stringify(params.args || {})}`);
50
- let username;
51
- let password;
52
- if (params.method === "tools/call" && params.args && params.args.tool && params.args.tool.startsWith("wc_reports_")) {
53
- username = process.env.WOO_CUSTOMER_KEY;
54
- password = process.env.WOO_CUSTOMER_SECRET;
55
- log(`Using WooCommerce credentials for tool: ${params.args.tool}`);
56
- if (!username || !password) {
57
- throw new Error(
58
- "Missing WooCommerce credentials. Please set WOO_CUSTOMER_KEY and WOO_CUSTOMER_SECRET environment variables."
59
- );
60
- }
63
+ let authHeader;
64
+ if (process.env.JWT_TOKEN) {
65
+ authHeader = `Bearer ${process.env.JWT_TOKEN}`;
66
+ log(`Using JWT token authentication`);
67
+ log(`Token length: ${process.env.JWT_TOKEN.length}`);
61
68
  } else {
62
- username = process.env.WP_API_USERNAME;
63
- password = process.env.WP_API_PASSWORD;
64
- log(`Using WordPress credentials for method: ${params.method || "init"}`);
69
+ let username;
70
+ let password;
71
+ if (params.method === "tools/call" && params.args && params.args.tool && params.args.tool.startsWith("wc_reports_")) {
72
+ username = process.env.WOO_CUSTOMER_KEY;
73
+ password = process.env.WOO_CUSTOMER_SECRET;
74
+ log(`Using WooCommerce credentials for tool: ${params.args.tool}`);
75
+ if (!username || !password) {
76
+ throw new Error(
77
+ "Missing WooCommerce credentials. Please set WOO_CUSTOMER_KEY and WOO_CUSTOMER_SECRET environment variables."
78
+ );
79
+ }
80
+ } else {
81
+ username = process.env.WP_API_USERNAME;
82
+ password = process.env.WP_API_PASSWORD;
83
+ log(`Using WordPress credentials for method: ${params.method || "init"}`);
84
+ }
85
+ log(`Username length: ${username ? username.length : 0}`);
86
+ log(`Password length: ${password ? password.length : 0}`);
87
+ const auth = Buffer.from(`${username}:${password}`).toString("base64");
88
+ authHeader = `Basic ${auth}`;
89
+ log(`Auth header length: ${auth.length}`);
65
90
  }
66
- log(`Username length: ${username ? username.length : 0}`);
67
- log(`Password length: ${password ? password.length : 0}`);
68
91
  log(`Environment: ${process.env.NODE_ENV || "development"}`);
69
92
  log(`API URL: ${baseUrl}`);
70
- const auth = Buffer.from(`${username}:${password}`).toString("base64");
71
- log(`Auth header length: ${auth.length}`);
72
93
  const url = new URL(`/?rest_route=${endpoint}`, baseUrl).toString();
73
94
  log(`Requesting URL: ${url}`);
74
95
  const headers = {
75
- Authorization: `Basic ${auth}`,
96
+ Authorization: authHeader,
76
97
  "Content-Type": "application/json"
77
98
  };
78
99
  const fetchOptions = {
@@ -128,7 +149,7 @@ if (typeof globalThis.fetch !== "function") {
128
149
  process.exit(1);
129
150
  }
130
151
  async function WordPressProxy() {
131
- const init = await wpRequest({ method: "init" });
152
+ const init = await wpRequest({ method: "initialize" });
132
153
  const server = new Server(
133
154
  {
134
155
  name: init.serverInfo.name,
@@ -149,6 +170,7 @@ async function WordPressProxy() {
149
170
  ListToolsRequestSchema,
150
171
  withLogging("ListTools", async (request) => {
151
172
  log("Processing ListToolsRequest");
173
+ log(JSON.stringify(request));
152
174
  const response = await wpRequest({
153
175
  method: "tools/list",
154
176
  cursor: request.params?.cursor
@@ -160,6 +182,7 @@ async function WordPressProxy() {
160
182
  CallToolRequestSchema,
161
183
  withLogging("CallTool", async (request) => {
162
184
  log("Processing CallToolRequest");
185
+ log(JSON.stringify(request));
163
186
  const response = await wpRequest({
164
187
  method: "tools/call",
165
188
  name: request.params.name,
@@ -172,6 +195,7 @@ async function WordPressProxy() {
172
195
  ListResourcesRequestSchema,
173
196
  withLogging("ListResources", async (request) => {
174
197
  log("Processing ListResourcesRequest");
198
+ log(JSON.stringify(request));
175
199
  const response = await wpRequest({
176
200
  method: "resources/list",
177
201
  cursor: request.params?.cursor
@@ -183,6 +207,7 @@ async function WordPressProxy() {
183
207
  ListResourceTemplatesRequestSchema,
184
208
  withLogging("ListResourceTemplates", async (request) => {
185
209
  log("Processing ListResourceTemplatesRequest");
210
+ log(JSON.stringify(request));
186
211
  const response = await wpRequest({
187
212
  method: "resources/templates/list",
188
213
  cursor: request.params?.cursor
@@ -194,6 +219,7 @@ async function WordPressProxy() {
194
219
  ReadResourceRequestSchema,
195
220
  withLogging("ReadResource", async (request) => {
196
221
  log("Processing ReadResourceRequest");
222
+ log(JSON.stringify(request));
197
223
  const response = await wpRequest({
198
224
  method: "resources/read",
199
225
  uri: request.params.uri
@@ -205,6 +231,7 @@ async function WordPressProxy() {
205
231
  SubscribeRequestSchema,
206
232
  withLogging("Subscribe", async (request) => {
207
233
  log("Processing SubscribeRequest");
234
+ log(JSON.stringify(request));
208
235
  const response = await wpRequest({
209
236
  method: "resources/subscribe",
210
237
  uri: request.params.uri
@@ -216,6 +243,7 @@ async function WordPressProxy() {
216
243
  UnsubscribeRequestSchema,
217
244
  withLogging("Unsubscribe", async (request) => {
218
245
  log("Processing UnsubscribeRequest");
246
+ log(JSON.stringify(request));
219
247
  const response = await wpRequest({
220
248
  method: "resources/unsubscribe",
221
249
  uri: request.params.uri
@@ -227,6 +255,7 @@ async function WordPressProxy() {
227
255
  ListPromptsRequestSchema,
228
256
  withLogging("ListPrompts", async (request) => {
229
257
  log("Processing ListPromptsRequest");
258
+ log(JSON.stringify(request));
230
259
  const response = await wpRequest({
231
260
  method: "prompts/list",
232
261
  cursor: request.params?.cursor
@@ -238,6 +267,7 @@ async function WordPressProxy() {
238
267
  GetPromptRequestSchema,
239
268
  withLogging("GetPrompt", async (request) => {
240
269
  log("Processing GetPromptRequest");
270
+ log(JSON.stringify(request));
241
271
  const response = await wpRequest({
242
272
  method: "prompts/get",
243
273
  name: request.params.name,
@@ -250,6 +280,7 @@ async function WordPressProxy() {
250
280
  SetLevelRequestSchema,
251
281
  withLogging("SetLevel", async (request) => {
252
282
  log("Processing SetLevelRequest");
283
+ log(JSON.stringify(request));
253
284
  const response = await wpRequest({
254
285
  method: "logging/setLevel",
255
286
  level: request.params.level
@@ -261,6 +292,7 @@ async function WordPressProxy() {
261
292
  CompleteRequestSchema,
262
293
  withLogging("Complete", async (request) => {
263
294
  log("Processing CompleteRequest");
295
+ log(JSON.stringify(request));
264
296
  const response = await wpRequest({
265
297
  method: "completion/complete",
266
298
  ref: request.params.ref,
@@ -273,6 +305,7 @@ async function WordPressProxy() {
273
305
  ListRootsRequestSchema,
274
306
  withLogging("ListRoots", async (request) => {
275
307
  log("Processing ListRootsRequest");
308
+ log(JSON.stringify(request));
276
309
  const response = await wpRequest({
277
310
  method: "roots/list"
278
311
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/mcp-wordpress-remote",
3
- "version": "0.1.18",
3
+ "version": "0.2.0",
4
4
  "description": "MCP WordPress Remote proxy server",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -75,4 +75,4 @@
75
75
  "node"
76
76
  ]
77
77
  }
78
- }
78
+ }