@automattic/mcp-wordpress-remote 0.2.17 → 0.2.18

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/dist/lib.d.ts CHANGED
@@ -12,7 +12,7 @@ interface WordPressResponse {
12
12
  [key: string]: any;
13
13
  }
14
14
 
15
- declare const MCP_WORDPRESS_REMOTE_VERSION = "0.2.17";
15
+ declare const MCP_WORDPRESS_REMOTE_VERSION = "0.2.18";
16
16
  /**
17
17
  * Centralized configuration for MCP WordPress Remote
18
18
  * All default values are defined here and can be overridden via environment variables
package/dist/lib.js CHANGED
@@ -28867,7 +28867,7 @@ async function selectCallbackPort(serverUrl, specifiedPort, _unused) {
28867
28867
  }
28868
28868
 
28869
28869
  // src/lib/config.ts
28870
- var MCP_WORDPRESS_REMOTE_VERSION = "0.2.17";
28870
+ var MCP_WORDPRESS_REMOTE_VERSION = "0.2.18";
28871
28871
  var CONFIG = {
28872
28872
  // API Configuration
28873
28873
  WP_API_URL: process.env.WP_API_URL || "https://example.com",
@@ -29093,7 +29093,9 @@ function log(message, level = 2 /* INFO */, category = "GENERAL", ...args) {
29093
29093
  const formattedArgs = args.length > 0 ? args.map((arg) => typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg).join(" ") : "";
29094
29094
  const logMessage = `${timestamp} [${levelName}] [${category}] ${message}${formattedArgs ? "\n" + formattedArgs : ""}
29095
29095
  `;
29096
- process.stderr.write(logMessage);
29096
+ if (process.env.LOG_TO_STDERR === "true") {
29097
+ process.stderr.write(logMessage);
29098
+ }
29097
29099
  if (process.env.LOG_FILE) {
29098
29100
  fs2.appendFileSync(process.env.LOG_FILE, logMessage);
29099
29101
  }
package/dist/proxy.js CHANGED
@@ -36036,7 +36036,7 @@ async function selectCallbackPort(serverUrl, specifiedPort, _unused) {
36036
36036
  }
36037
36037
 
36038
36038
  // src/lib/config.ts
36039
- var MCP_WORDPRESS_REMOTE_VERSION = "0.2.17";
36039
+ var MCP_WORDPRESS_REMOTE_VERSION = "0.2.18";
36040
36040
  var CONFIG = {
36041
36041
  // API Configuration
36042
36042
  WP_API_URL: process.env.WP_API_URL || "https://example.com",
@@ -36218,7 +36218,9 @@ function log(message, level = 2 /* INFO */, category = "GENERAL", ...args) {
36218
36218
  const formattedArgs = args.length > 0 ? args.map((arg) => typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg).join(" ") : "";
36219
36219
  const logMessage = `${timestamp} [${levelName}] [${category}] ${message}${formattedArgs ? "\n" + formattedArgs : ""}
36220
36220
  `;
36221
- process.stderr.write(logMessage);
36221
+ if (process.env.LOG_TO_STDERR === "true") {
36222
+ process.stderr.write(logMessage);
36223
+ }
36222
36224
  if (process.env.LOG_FILE) {
36223
36225
  fs2.appendFileSync(process.env.LOG_FILE, logMessage);
36224
36226
  }
@@ -38578,28 +38580,83 @@ function createSessionContext() {
38578
38580
  }
38579
38581
 
38580
38582
  // src/lib/transport-detection.ts
38581
- async function detectTransportType(context) {
38582
- logger.info("Initializing connection to WordPress API with transport detection...", "PROXY");
38583
+ async function detectTransportType(context, initParams) {
38584
+ logger.info("\u{1F50D} Starting transport detection and WordPress API initialization...", "TRANSPORT_DETECT");
38583
38585
  let init;
38584
38586
  let transportType = null;
38587
+ const enhancedParams = initParams ? { ...initParams } : {};
38588
+ if (enhancedParams.clientInfo) {
38589
+ if (typeof enhancedParams.clientInfo === "object" && enhancedParams.clientInfo !== null && !Array.isArray(enhancedParams.clientInfo)) {
38590
+ const originalClient = enhancedParams.clientInfo?.name || "unknown";
38591
+ const newClientInfo = { ...enhancedParams.clientInfo };
38592
+ if (newClientInfo.proxied && typeof newClientInfo.proxied === "object") {
38593
+ newClientInfo.proxied = {
38594
+ ...newClientInfo.proxied,
38595
+ name: "@automattic/mcp-wordpress-remote",
38596
+ version: MCP_WORDPRESS_REMOTE_VERSION
38597
+ };
38598
+ } else {
38599
+ newClientInfo.proxied = {
38600
+ name: "@automattic/mcp-wordpress-remote",
38601
+ version: MCP_WORDPRESS_REMOTE_VERSION
38602
+ };
38603
+ }
38604
+ enhancedParams.clientInfo = newClientInfo;
38605
+ logger.info("\u{1F4CB} Added proxy information to clientInfo", "TRANSPORT_DETECT", {
38606
+ originalClient,
38607
+ proxyName: "@automattic/mcp-wordpress-remote",
38608
+ proxyVersion: MCP_WORDPRESS_REMOTE_VERSION
38609
+ });
38610
+ } else {
38611
+ logger.warn("clientInfo is present but not a valid object, skipping enhancement", "TRANSPORT_DETECT", {
38612
+ clientInfoType: typeof enhancedParams.clientInfo,
38613
+ isArray: Array.isArray(enhancedParams.clientInfo),
38614
+ isNull: enhancedParams.clientInfo === null
38615
+ });
38616
+ }
38617
+ } else {
38618
+ logger.debug("No clientInfo provided in initialize parameters", "TRANSPORT_DETECT");
38619
+ }
38585
38620
  try {
38586
- logger.info("Attempting JSON-RPC transport...", "PROXY");
38587
- const initMessage = addSessionInfo({ method: "initialize" }, {}, context);
38621
+ logger.info("\u{1F4E1} Attempting JSON-RPC transport...", "TRANSPORT_DETECT");
38622
+ const wpRequestParams = {
38623
+ method: "initialize",
38624
+ ...enhancedParams
38625
+ };
38626
+ const initMessage = addSessionInfo(wpRequestParams, {}, context);
38627
+ logger.info("Sending initialization message via JSON-RPC:", "TRANSPORT_DETECT", {
38628
+ method: initMessage.method,
38629
+ id: initMessage.id,
38630
+ jsonrpc: initMessage.jsonrpc,
38631
+ hasParams: !!initMessage.params && Object.keys(initMessage.params).length > 1
38632
+ // More than just _proxy_request_id
38633
+ });
38634
+ logger.debug("Complete JSON-RPC init message:", "TRANSPORT_DETECT", initMessage);
38588
38635
  const initResponse = await wpRequest(initMessage, true);
38589
38636
  init = initResponse;
38590
38637
  transportType = "jsonrpc";
38591
- logger.info("\u2705 JSON-RPC transport detected and working", "PROXY");
38638
+ logger.info("\u2705 JSON-RPC transport detected and working", "TRANSPORT_DETECT");
38639
+ logger.debug("JSON-RPC initialization response:", "TRANSPORT_DETECT", init);
38592
38640
  } catch (error) {
38593
- logger.warn("JSON-RPC transport failed, trying simple transport...", "PROXY");
38594
- logger.debug("JSON-RPC error:", "PROXY", error);
38641
+ logger.warn("\u26A0\uFE0F JSON-RPC transport failed, trying simple transport...", "TRANSPORT_DETECT");
38642
+ logger.debug("JSON-RPC error details:", "TRANSPORT_DETECT", error);
38595
38643
  try {
38596
- const simpleInitRequest = { method: "initialize" };
38597
- const initResponse = await wpRequest(simpleInitRequest, false);
38644
+ const simpleRequestParams = {
38645
+ method: "initialize",
38646
+ ...enhancedParams
38647
+ };
38648
+ logger.info("Sending initialization message via Simple transport:", "TRANSPORT_DETECT", {
38649
+ method: simpleRequestParams.method,
38650
+ hasParams: Object.keys(simpleRequestParams).length > 1
38651
+ });
38652
+ logger.debug("Complete Simple init message:", "TRANSPORT_DETECT", simpleRequestParams);
38653
+ const initResponse = await wpRequest(simpleRequestParams, false);
38598
38654
  init = initResponse;
38599
38655
  transportType = "simple";
38600
- logger.info("\u2705 Simple transport detected and working", "PROXY");
38656
+ logger.info("\u2705 Simple transport detected and working", "TRANSPORT_DETECT");
38657
+ logger.debug("Simple initialization response:", "TRANSPORT_DETECT", init);
38601
38658
  } catch (simpleError) {
38602
- logger.error("Both JSON-RPC and simple transports failed", "PROXY", simpleError);
38659
+ logger.error("\u274C Both JSON-RPC and simple transports failed", "TRANSPORT_DETECT", simpleError);
38603
38660
  throw new Error("Unable to establish connection with either transport type");
38604
38661
  }
38605
38662
  }
@@ -38621,36 +38678,54 @@ async function detectTransportType(context) {
38621
38678
 
38622
38679
  // src/lib/error-utils.ts
38623
38680
  function mapHttpStatusToMcpCode(statusCode) {
38624
- const MCP_ERROR_CODES = {
38681
+ const JSONRPC_ERROR_CODES = {
38625
38682
  PARSE_ERROR: -32700,
38626
38683
  INVALID_REQUEST: -32600,
38627
38684
  METHOD_NOT_FOUND: -32601,
38628
38685
  INVALID_PARAMS: -32602,
38629
- INTERNAL_ERROR: -32603,
38630
- UNAUTHORIZED: -32010,
38631
- PERMISSION_DENIED: -32008
38686
+ INTERNAL_ERROR: -32603
38687
+ };
38688
+ const MCP_ERROR_CODES = {
38689
+ SERVER_ERROR: -32e3,
38690
+ // Generic server error
38691
+ TIMEOUT_ERROR: -32001,
38692
+ // Request timeout
38693
+ RESOURCE_NOT_FOUND: -32002,
38694
+ // Resource not found
38695
+ TOOL_NOT_FOUND: -32003,
38696
+ // Tool not found
38697
+ PROMPT_NOT_FOUND: -32004,
38698
+ // Prompt not found
38699
+ PERMISSION_DENIED: -32008,
38700
+ // Access denied/forbidden
38701
+ UNAUTHORIZED: -32010
38702
+ // Authentication required
38632
38703
  };
38633
38704
  switch (statusCode) {
38634
38705
  case 400:
38635
- return MCP_ERROR_CODES.INVALID_REQUEST;
38706
+ return JSONRPC_ERROR_CODES.INVALID_REQUEST;
38636
38707
  case 401:
38637
38708
  return MCP_ERROR_CODES.UNAUTHORIZED;
38638
38709
  case 403:
38639
38710
  return MCP_ERROR_CODES.PERMISSION_DENIED;
38640
38711
  case 404:
38641
- return MCP_ERROR_CODES.METHOD_NOT_FOUND;
38712
+ return JSONRPC_ERROR_CODES.METHOD_NOT_FOUND;
38713
+ case 408:
38714
+ return MCP_ERROR_CODES.TIMEOUT_ERROR;
38715
+ case 413:
38716
+ // Payload Too Large
38642
38717
  case 422:
38643
- return MCP_ERROR_CODES.INVALID_PARAMS;
38718
+ return JSONRPC_ERROR_CODES.INVALID_PARAMS;
38644
38719
  case 500:
38645
- // Internal Server Error
38720
+ return JSONRPC_ERROR_CODES.INTERNAL_ERROR;
38646
38721
  case 502:
38647
38722
  // Bad Gateway
38648
38723
  case 503:
38649
- // Service Unavailable
38724
+ return MCP_ERROR_CODES.SERVER_ERROR;
38650
38725
  case 504:
38651
- // Gateway Timeout
38726
+ return MCP_ERROR_CODES.TIMEOUT_ERROR;
38652
38727
  default:
38653
- return MCP_ERROR_CODES.INTERNAL_ERROR;
38728
+ return JSONRPC_ERROR_CODES.INTERNAL_ERROR;
38654
38729
  }
38655
38730
  }
38656
38731
  function convertAPIErrorToMcpError(error) {
@@ -38680,17 +38755,38 @@ function createRequestHandler(config, context) {
38680
38755
  function createWrappedHandler(config, context) {
38681
38756
  const handler = createRequestHandler(config, context);
38682
38757
  return async (request) => {
38683
- logger.debug(`Received ${config.name} request`, "MCP", request);
38758
+ logger.info(`\u{1F4E9} Client Message: ${config.name}`, "CLIENT");
38759
+ logger.info(`Request ID: ${request.id || "none"} | Method: ${config.method}`, "CLIENT");
38760
+ if (request.params && Object.keys(request.params).length > 0) {
38761
+ logger.info(`Request parameters:`, "CLIENT", {
38762
+ paramCount: Object.keys(request.params).length,
38763
+ paramKeys: Object.keys(request.params)
38764
+ });
38765
+ logger.debug(`Full request parameters:`, "CLIENT", request.params);
38766
+ } else {
38767
+ logger.info(`No request parameters`, "CLIENT");
38768
+ }
38684
38769
  logger.debug(
38685
- `Adding session info - Session ID: ${context.sessionId}, MCP Request ID: ${request.id}`,
38686
- "SESSION"
38770
+ `Session context - ID: ${context.sessionId || "none"}, Transport: ${context.transportType || "detecting"}, Counter: ${context.requestIdCounter}`,
38771
+ "CLIENT"
38687
38772
  );
38773
+ logger.debug(`Complete client request object:`, "CLIENT", request);
38774
+ const startTime = Date.now();
38688
38775
  try {
38689
38776
  const response = await handler(request);
38690
- logger.debug(`${config.name} response sent`, "MCP");
38777
+ const duration = Date.now() - startTime;
38778
+ logger.info(`\u2705 Client Response: ${config.name} completed in ${duration}ms`, "CLIENT");
38779
+ logger.debug(`Response sent to client:`, "CLIENT", {
38780
+ hasResponse: !!response,
38781
+ responseKeys: response && typeof response === "object" ? Object.keys(response) : "primitive"
38782
+ });
38691
38783
  return response;
38692
38784
  } catch (error) {
38693
- logger.error(`Error handling ${config.name} request`, "MCP", error);
38785
+ const duration = Date.now() - startTime;
38786
+ logger.error(`\u274C Client Error: ${config.name} failed after ${duration}ms`, "CLIENT", {
38787
+ error: error instanceof Error ? error.message : String(error),
38788
+ requestId: request.id
38789
+ });
38694
38790
  if (isAPIError(error) && context.transportType === "simple") {
38695
38791
  logger.debug(`Converting APIError to MCP error format for ${config.name} (simple transport)`, "MCP", {
38696
38792
  statusCode: error.statusCode,
@@ -38815,17 +38911,57 @@ async function WordPressProxy() {
38815
38911
  logger.warn("Error cleaning up expired tokens", "PROXY", error);
38816
38912
  }
38817
38913
  const sessionContext = createSessionContext();
38818
- const { initResult } = await detectTransportType(sessionContext);
38819
38914
  const server = new Server(
38820
38915
  {
38821
- name: initResult.serverInfo.name,
38822
- version: initResult.serverInfo.version
38916
+ name: "WordPress MCP Remote Proxy",
38917
+ version: "0.2.17"
38823
38918
  },
38824
38919
  {
38825
- capabilities: initResult.capabilities
38826
- // Type assertion to fix linter error
38920
+ capabilities: {
38921
+ tools: {},
38922
+ resources: {},
38923
+ prompts: {},
38924
+ logging: {},
38925
+ completions: {}
38926
+ }
38827
38927
  }
38828
38928
  );
38929
+ server.setRequestHandler(InitializeRequestSchema, async (request) => {
38930
+ logger.info("\u{1F4E9} Client Initialize Request received", "INIT");
38931
+ logger.debug("Initialize request details:", "INIT", request);
38932
+ try {
38933
+ logger.info("\u{1F504} Initializing WordPress connection with client parameters", "INIT");
38934
+ const { initResult } = await detectTransportType(sessionContext, request.params);
38935
+ const wordpressInitResponse = {
38936
+ protocolVersion: initResult.protocolVersion || "2025-06-18",
38937
+ serverInfo: initResult.serverInfo,
38938
+ capabilities: initResult.capabilities,
38939
+ instructions: initResult.instructions || "MCP WordPress Remote Proxy Server"
38940
+ };
38941
+ logger.info("\u2705 Returning WordPress server initialize response", "INIT");
38942
+ logger.debug("Initialize response:", "INIT", wordpressInitResponse);
38943
+ return wordpressInitResponse;
38944
+ } catch (error) {
38945
+ logger.error("\u274C Failed to initialize WordPress connection with client parameters", "INIT", error);
38946
+ const fallbackResponse = {
38947
+ protocolVersion: "2025-06-18",
38948
+ serverInfo: {
38949
+ name: "WordPress MCP Remote Proxy",
38950
+ version: "0.2.17"
38951
+ },
38952
+ capabilities: {
38953
+ tools: {},
38954
+ resources: {},
38955
+ prompts: {},
38956
+ logging: {},
38957
+ completions: {}
38958
+ },
38959
+ instructions: "MCP WordPress Remote Proxy Server (Connection Failed)"
38960
+ };
38961
+ logger.warn("\u26A0\uFE0F Using fallback initialize response", "INIT");
38962
+ return fallbackResponse;
38963
+ }
38964
+ });
38829
38965
  server.setRequestHandler(ListToolsRequestSchema, createWrappedHandler(HANDLER_CONFIGS.listTools, sessionContext));
38830
38966
  server.setRequestHandler(CallToolRequestSchema, createWrappedHandler(HANDLER_CONFIGS.callTool, sessionContext));
38831
38967
  server.setRequestHandler(ListResourcesRequestSchema, createWrappedHandler(HANDLER_CONFIGS.listResources, sessionContext));
@@ -38839,6 +38975,25 @@ async function WordPressProxy() {
38839
38975
  server.setRequestHandler(CompleteRequestSchema, createWrappedHandler(HANDLER_CONFIGS.complete, sessionContext));
38840
38976
  server.setRequestHandler(ListRootsRequestSchema, createWrappedHandler(HANDLER_CONFIGS.listRoots, sessionContext));
38841
38977
  const transport = new StdioServerTransport();
38978
+ transport.onmessage = (message) => {
38979
+ const msg = message;
38980
+ const method = typeof msg?.method === "string" ? msg.method : "unknown";
38981
+ const id = msg?.id ?? "none";
38982
+ const hasParams = Boolean(msg?.params && typeof msg.params === "object" && Object.keys(msg.params).length);
38983
+ logger.info("\u{1F4E5} Raw client message received", "TRANSPORT", {
38984
+ method,
38985
+ id,
38986
+ hasParams,
38987
+ messageType: method === "unknown" ? "response/notification" : "request"
38988
+ });
38989
+ logger.debug("Complete raw message:", "TRANSPORT", message);
38990
+ };
38991
+ transport.onerror = (error) => {
38992
+ logger.error("\u274C Transport error:", "TRANSPORT", error);
38993
+ };
38994
+ transport.onclose = () => {
38995
+ logger.info("\u{1F50C} Transport connection closed", "TRANSPORT");
38996
+ };
38842
38997
  server.connect(transport).then(() => {
38843
38998
  logger.info("MCP server connected to transport successfully", "PROXY");
38844
38999
  }).catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/mcp-wordpress-remote",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "MCP WordPress Remote proxy server",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"