@automattic/mcp-wordpress-remote 0.2.5 → 0.2.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.
Files changed (2) hide show
  1. package/dist/proxy.js +25 -5
  2. package/package.json +1 -1
package/dist/proxy.js CHANGED
@@ -34,6 +34,10 @@ var CONFIG = {
34
34
  // Resource Indicators (RFC 8707)
35
35
  OAUTH_RESOURCE_INDICATOR: process.env.OAUTH_RESOURCE_INDICATOR !== "false",
36
36
  // Resource parameter support
37
+ // OAuth Scopes Configuration
38
+ // OAUTH_SCOPES: Comma-separated list of OAuth scopes (e.g., "read,write" or "global")
39
+ // If empty, uses defaults: "global" for WordPress.com, "read,write" for self-hosted
40
+ OAUTH_SCOPES: process.env.OAUTH_SCOPES || "",
37
41
  // Timeout Configuration (in milliseconds)
38
42
  OAUTH_TIMEOUT: 3e4,
39
43
  // 30 seconds
@@ -52,6 +56,12 @@ var CONFIG = {
52
56
  // Environment
53
57
  NODE_ENV: process.env.NODE_ENV || "development"
54
58
  };
59
+ function parseOAuthScopes(envScopes, defaultScopes) {
60
+ if (!envScopes || envScopes.trim() === "") {
61
+ return defaultScopes;
62
+ }
63
+ return envScopes.split(",").map((scope) => scope.trim()).filter((scope) => scope.length > 0);
64
+ }
55
65
  function isWordPressComSite(url) {
56
66
  try {
57
67
  const siteUrl = new URL(url);
@@ -64,15 +74,18 @@ function isWordPressComSite(url) {
64
74
  }
65
75
  function getRecommendedOAuthConfig(siteUrl) {
66
76
  if (isWordPressComSite(siteUrl)) {
77
+ const defaultScopes = ["global"];
67
78
  return {
68
79
  flowType: "implicit",
69
80
  usePKCE: false,
70
81
  useResourceIndicator: false,
71
82
  authorizationEndpoint: "https://public-api.wordpress.com/oauth2/authorize",
72
83
  tokenEndpoint: "https://public-api.wordpress.com/oauth2/token",
84
+ scopes: parseOAuthScopes(CONFIG.OAUTH_SCOPES, defaultScopes),
73
85
  description: "WordPress.com OAuth2 (compatible mode)"
74
86
  };
75
87
  } else {
88
+ const defaultScopes = ["read", "write"];
76
89
  return {
77
90
  flowType: "authorization_code",
78
91
  usePKCE: true,
@@ -81,6 +94,7 @@ function getRecommendedOAuthConfig(siteUrl) {
81
94
  // Will be discovered
82
95
  tokenEndpoint: void 0,
83
96
  // Will be discovered
97
+ scopes: parseOAuthScopes(CONFIG.OAUTH_SCOPES, defaultScopes),
84
98
  description: "MCP-compliant OAuth 2.1"
85
99
  };
86
100
  }
@@ -889,15 +903,17 @@ var MCPOAuthProvider = class {
889
903
  // Discovered metadata
890
904
  this.authServerMetadata = null;
891
905
  this.resourceMetadata = null;
906
+ const serverUrl = options.serverUrl || CONFIG.WP_API_URL;
907
+ const recommendedConfig = getRecommendedOAuthConfig(serverUrl);
892
908
  this.config = {
893
- serverUrl: options.serverUrl || CONFIG.WP_API_URL,
894
- resource: generateCanonicalResourceURI(options.serverUrl || CONFIG.WP_API_URL),
909
+ serverUrl,
910
+ resource: generateCanonicalResourceURI(serverUrl),
895
911
  responseType: "code",
896
912
  // OAuth 2.1 uses authorization code flow
897
913
  usePKCE: true,
898
914
  // PKCE is required for OAuth 2.1
899
915
  redirectUri: `http://${CONFIG.OAUTH_HOST}:${CONFIG.OAUTH_CALLBACK_PORT}/oauth/callback`,
900
- scopes: options.scopes || ["read", "write"],
916
+ scopes: options.scopes || recommendedConfig.scopes,
901
917
  clientId: options.clientId || CONFIG.WP_OAUTH_CLIENT_ID,
902
918
  callbackPort: CONFIG.OAUTH_CALLBACK_PORT,
903
919
  host: CONFIG.OAUTH_HOST,
@@ -1260,6 +1276,7 @@ import { EventEmitter as EventEmitter2 } from "node:events";
1260
1276
  var WP_PERSISTENT_CONFIG = {
1261
1277
  authorizeEndpoint: "/wp-admin/admin.php?page=mcp-oauth-authorize",
1262
1278
  scopes: ["read", "write"],
1279
+ // Default for self-hosted, will be overridden for WordPress.com
1263
1280
  callbackPort: CONFIG.OAUTH_CALLBACK_PORT,
1264
1281
  host: CONFIG.OAUTH_HOST
1265
1282
  };
@@ -1270,7 +1287,9 @@ var PersistentWPOAuthClientProvider = class {
1270
1287
  const recommendedConfig = getRecommendedOAuthConfig(options.serverUrl || "");
1271
1288
  this.options = {
1272
1289
  ...WP_PERSISTENT_CONFIG,
1273
- ...options
1290
+ ...options,
1291
+ // Use recommended scopes for the site type
1292
+ scopes: options.scopes || recommendedConfig.scopes
1274
1293
  };
1275
1294
  if (isWpCom && recommendedConfig.authorizationEndpoint) {
1276
1295
  this.options.authorizeEndpoint = recommendedConfig.authorizationEndpoint;
@@ -1911,10 +1930,11 @@ async function getOAuthTokens() {
1911
1930
  const shouldUseMCPFlow = !isWPCom && CONFIG.OAUTH_FLOW_TYPE === "authorization_code" && CONFIG.OAUTH_USE_PKCE;
1912
1931
  if (shouldUseMCPFlow) {
1913
1932
  if (!mcpOAuthProvider) {
1933
+ const recommendedConfig2 = getRecommendedOAuthConfig(serverUrl);
1914
1934
  mcpOAuthProvider = new MCPOAuthProvider({
1915
1935
  serverUrl,
1916
1936
  clientId: CONFIG.WP_OAUTH_CLIENT_ID,
1917
- scopes: ["read", "write"]
1937
+ scopes: recommendedConfig2.scopes
1918
1938
  });
1919
1939
  }
1920
1940
  logger.auth("Using MCP-compliant OAuth 2.1 authorization code flow with PKCE");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/mcp-wordpress-remote",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "MCP WordPress Remote proxy server",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"