@automattic/mcp-wordpress-remote 0.2.1 → 0.2.3

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 (3) hide show
  1. package/README.md +465 -23
  2. package/dist/proxy.js +2024 -94
  3. package/package.json +55 -5
package/README.md CHANGED
@@ -1,40 +1,482 @@
1
1
  # MCP WordPress Remote
2
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.
3
+ **A Model Context Protocol (MCP) server for seamless WordPress integration**
4
4
 
5
- ## Requirements
5
+ Connect AI assistants like Claude Desktop to your WordPress sites with multiple authentication methods including OAuth 2.0, JWT tokens, and application passwords.
6
+
7
+ ## Features
8
+
9
+ - **MCP Authorization Specification Compliant** - Implements MCP Authorization specification 2025-06-18
10
+ - **OAuth 2.1 with PKCE** - Secure authorization code flow with PKCE (RFC 7636)
11
+ - **Resource Indicators** - RFC 8707 compliance for token audience binding
12
+ - **Dynamic Client Registration** - RFC 7591 support for automatic client registration
13
+ - **Protected Resource Metadata Discovery** - RFC 9728 for automatic endpoint discovery
14
+ - **Multiple Authentication Methods** - OAuth 2.1, JWT tokens, and WordPress application passwords
15
+ - **Persistent Token Storage** - OAuth tokens stored securely with automatic validation
16
+ - **Multi-instance Coordination** - Lockfiles prevent authentication conflicts
17
+ - **Automatic Token Management** - Handles validation, refresh, and cleanup
18
+ - **Enhanced Error Handling** - Detailed error messages with proper categorization
19
+ - **Comprehensive Logging** - Structured logging with categories and levels
20
+ - **Complete MCP Support** - Tools, resources, prompts, and more
21
+
22
+ ## Quick Start
23
+
24
+ ### Installation
25
+
26
+ ```bash
27
+ npm install @automattic/mcp-wordpress-remote
28
+ ```
29
+
30
+ ### Configuration
31
+
32
+ Add to your MCP client configuration (e.g., Claude Desktop's `claude_desktop_config.json`):
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "wordpress": {
38
+ "command": "npx",
39
+ "args": ["-y", "@automattic/mcp-wordpress-remote"],
40
+ "env": {
41
+ "WP_API_URL": "https://your-wordpress-site.com"
42
+ }
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ ### First Run
49
+
50
+ 1. **Start your MCP client** (Claude Desktop, etc.)
51
+ 2. **Choose authentication method** based on your preference:
52
+ - **OAuth 2.0** (default): Browser opens automatically for authorization
53
+ - **JWT Token**: Set `JWT_TOKEN` environment variable
54
+ - **Application Password**: Set `WP_API_USERNAME` and `WP_API_PASSWORD`
55
+ 3. **Start using WordPress features** in your AI assistant
56
+
57
+ ## WordPress MCP Plugin
58
+
59
+ You need to install the [wordpress-mcp](https://github.com/Automattic/wordpress-mcp) plugin on your WordPress website and enable MCP Functionality in Settings > MCP Settings.
60
+
61
+ ## Authentication Methods
62
+
63
+ ### 1. OAuth 2.1 (Recommended - MCP Compliant)
64
+
65
+ OAuth 2.1 provides the most secure and user-friendly experience with full MCP Authorization specification compliance for **self-hosted WordPress sites**.
66
+
67
+ #### **For Self-Hosted WordPress Sites:**
68
+
69
+ ```json
70
+ {
71
+ "mcpServers": {
72
+ "wordpress": {
73
+ "command": "npx",
74
+ "args": ["-y", "@automattic/mcp-wordpress-remote"],
75
+ "env": {
76
+ "WP_API_URL": "https://your-wordpress-site.com",
77
+ "OAUTH_ENABLED": "true",
78
+ "OAUTH_FLOW_TYPE": "authorization_code",
79
+ "OAUTH_USE_PKCE": "true"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ #### **For WordPress.com Sites (Automatic Compatibility):**
87
+
88
+ ```json
89
+ {
90
+ "mcpServers": {
91
+ "wordpress": {
92
+ "command": "npx",
93
+ "args": ["-y", "@automattic/mcp-wordpress-remote"],
94
+ "env": {
95
+ "WP_API_URL": "https://yoursite.wordpress.com"
96
+ }
97
+ }
98
+ }
99
+ }
100
+ ```
101
+
102
+ _The system automatically detects WordPress.com sites and uses compatible OAuth2 endpoints._
103
+
104
+ **MCP Authorization Specification Features:**
105
+
106
+ - **OAuth 2.1 authorization code flow** with PKCE (RFC 7636)
107
+ - **Resource Indicators** (RFC 8707) for token audience binding
108
+ - **Dynamic Client Registration** (RFC 7591) when supported
109
+ - **Protected Resource Metadata Discovery** (RFC 9728)
110
+ - **Authorization Server Metadata Discovery** (RFC 8414)
111
+
112
+ **Benefits:**
113
+
114
+ - Full compliance with MCP Authorization specification 2025-06-18
115
+ - Enhanced security with PKCE protection
116
+ - One-time browser authorization
117
+ - Tokens stored securely with automatic validation
118
+ - Automatic endpoint discovery
119
+ - No need to manage passwords
120
+ - Automatic expiration handling
121
+
122
+ ### 2. JWT Token Authentication
123
+
124
+ For server-to-server authentication or when OAuth is not available.
6
125
 
7
- - Node.js version 22 or higher
126
+ ```json
127
+ {
128
+ "mcpServers": {
129
+ "wordpress": {
130
+ "command": "npx",
131
+ "args": ["-y", "@automattic/mcp-wordpress-remote"],
132
+ "env": {
133
+ "WP_API_URL": "https://your-wordpress-site.com",
134
+ "JWT_TOKEN": "your-jwt-token-here"
135
+ }
136
+ }
137
+ }
138
+ }
139
+ ```
8
140
 
9
- ## WordPress MCP plugin
141
+ ### 3. WordPress Application Passwords (Legacy)
10
142
 
11
- You have to install the [wordpress-mcp](https://github.com/Automattic/wordpress-mcp) plugin on your WordPress website, and enable MCP Functionality on Settings > MCP Settings.
143
+ Uses WordPress username and application password for basic authentication.
12
144
 
13
- ## Why
145
+ ```json
146
+ {
147
+ "mcpServers": {
148
+ "wordpress": {
149
+ "command": "npx",
150
+ "args": ["-y", "@automattic/mcp-wordpress-remote"],
151
+ "env": {
152
+ "WP_API_URL": "https://your-wordpress-site.com",
153
+ "WP_API_USERNAME": "your-username",
154
+ "WP_API_PASSWORD": "your-application-password",
155
+ "OAUTH_ENABLED": "false"
156
+ }
157
+ }
158
+ }
159
+ }
160
+ ```
14
161
 
15
- 1. Most of the clients does not suport SSE or Streamable communications protocols.
16
- 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.
17
- 3. Oauth2.1 is not yet available on wordpress out of the box.
18
- 4. Security trough WordPress API passwords and WooCommerce REST API cosumer key and secret
19
- 5. Easy to use. See installation instructions below.
162
+ To create an application password:
20
163
 
21
- ## Usage
164
+ 1. Go to your WordPress admin dashboard
165
+ 2. Navigate to Users > Profile
166
+ 3. Scroll down to "Application Passwords"
167
+ 4. Create a new application password for MCP access
168
+
169
+ ## Advanced Configuration
170
+
171
+ ### Custom OAuth Settings
172
+
173
+ ```json
174
+ {
175
+ "mcpServers": {
176
+ "wordpress": {
177
+ "command": "npx",
178
+ "args": ["-y", "@automattic/mcp-wordpress-remote"],
179
+ "env": {
180
+ "WP_API_URL": "https://your-wordpress-site.com",
181
+ "OAUTH_CALLBACK_PORT": "8080",
182
+ "OAUTH_HOST": "127.0.0.1",
183
+ "WP_OAUTH_CLIENT_ID": "your-custom-client-id"
184
+ }
185
+ }
186
+ }
187
+ }
188
+ ```
189
+
190
+ ### WooCommerce Integration
191
+
192
+ For WooCommerce-specific tools and reports:
193
+
194
+ ```json
195
+ {
196
+ "mcpServers": {
197
+ "wordpress": {
198
+ "command": "npx",
199
+ "args": ["-y", "@automattic/mcp-wordpress-remote"],
200
+ "env": {
201
+ "WP_API_URL": "https://your-wordpress-site.com",
202
+ "WOO_CUSTOMER_KEY": "ck_your-consumer-key",
203
+ "WOO_CUSTOMER_SECRET": "cs_your-consumer-secret"
204
+ }
205
+ }
206
+ }
207
+ }
208
+ ```
22
209
 
23
210
  ### Environment Variables
24
211
 
25
- The following environment variables are required:
212
+ | Variable | Description | Default | Required |
213
+ | ---------------------------- | ---------------------------------- | -------------------- | -------- |
214
+ | `WP_API_URL` | WordPress site URL | - | ✅ |
215
+ | `OAUTH_ENABLED` | Enable OAuth authentication | `true` | - |
216
+ | `OAUTH_CALLBACK_PORT` | OAuth callback port | `3000` | - |
217
+ | `OAUTH_HOST` | OAuth callback hostname | `127.0.0.1` | - |
218
+ | `WP_OAUTH_CLIENT_ID` | Custom OAuth client ID | - | - |
219
+ | **MCP OAuth 2.1 Settings** | | | |
220
+ | `OAUTH_FLOW_TYPE` | OAuth flow type | `authorization_code` | - |
221
+ | `OAUTH_USE_PKCE` | Use PKCE (required for OAuth 2.1) | `true` | - |
222
+ | `OAUTH_DYNAMIC_REGISTRATION` | Enable dynamic client registration | `true` | - |
223
+ | `OAUTH_RESOURCE_INDICATOR` | Use resource indicators (RFC 8707) | `true` | - |
224
+ | **Configuration** | | | |
225
+ | `WP_MCP_CONFIG_DIR` | Config directory override | `~/.mcp-auth` | - |
226
+ | `LOG_FILE` | Log file path | - | - |
227
+ | `LOG_LEVEL` | Log level (0-3) | `2` | - |
228
+ | **Legacy Authentication** | | | |
229
+ | `JWT_TOKEN` | JWT token for authentication | - | - |
230
+ | `WP_API_USERNAME` | WordPress username (legacy) | - | - |
231
+ | `WP_API_PASSWORD` | WordPress app password (legacy) | - | - |
232
+ | `WOO_CUSTOMER_KEY` | WooCommerce consumer key | - | - |
233
+ | `WOO_CUSTOMER_SECRET` | WooCommerce consumer secret | - | - |
234
+
235
+ ### WordPress.com Compatibility
236
+
237
+ The package automatically detects WordPress.com sites and uses the appropriate OAuth2 flow for full compatibility with the [WordPress.com OAuth2 API](https://developer.wordpress.com/docs/oauth2/).
238
+
239
+ #### **Automatic Detection**
240
+
241
+ WordPress.com sites (\*.wordpress.com) are automatically detected and configured with:
242
+
243
+ - **Standard OAuth2 implicit flow** (as per WordPress.com documentation)
244
+ - **WordPress.com OAuth endpoints**: `public-api.wordpress.com/oauth2/*`
245
+ - **Bearer token authentication** format
246
+ - **No PKCE requirement** (WordPress.com compatible)
247
+
248
+ #### **Manual WordPress.com Configuration**
249
+
250
+ For explicit WordPress.com mode:
251
+
252
+ ```json
253
+ {
254
+ "env": {
255
+ "WP_API_URL": "https://yoursite.wordpress.com",
256
+ "OAUTH_FLOW_TYPE": "implicit",
257
+ "OAUTH_USE_PKCE": "false",
258
+ "OAUTH_RESOURCE_INDICATOR": "false"
259
+ }
260
+ }
261
+ ```
262
+
263
+ ### Disable OAuth
264
+
265
+ To use only JWT or Basic Auth:
266
+
267
+ ```json
268
+ {
269
+ "env": {
270
+ "OAUTH_ENABLED": "false",
271
+ "JWT_TOKEN": "your-jwt-token"
272
+ }
273
+ }
274
+ ```
275
+
276
+ ## Development Mode
277
+
278
+ For development and testing, you can use the local repository:
279
+
280
+ ### Setup
281
+
282
+ 1. **Clone the repository:**
283
+
284
+ ```bash
285
+ git clone https://github.com/Automattic/mcp-wordpress-remote.git
286
+ cd mcp-wordpress-remote
287
+ ```
288
+
289
+ 2. **Install dependencies:**
290
+
291
+ ```bash
292
+ npm install
293
+ ```
294
+
295
+ 3. **Build the project:**
296
+ ```bash
297
+ npm run build
298
+ ```
299
+
300
+ ### Configuration
301
+
302
+ Configure your MCP client to use the local version:
303
+
304
+ ```json
305
+ {
306
+ "mcpServers": {
307
+ "wordpress": {
308
+ "command": "node",
309
+ "args": ["/path/to/your/mcp-wordpress-remote/dist/proxy.js"],
310
+ "env": {
311
+ "WP_API_URL": "https://your-wordpress-site.com"
312
+ }
313
+ }
314
+ }
315
+ }
316
+ ```
317
+
318
+ ### Development Workflow
319
+
320
+ - **Watch mode:** `npm run build:watch` - Automatically rebuilds on file changes
321
+ - **Testing:** `npm test` - Run the test suite
322
+ - **Type checking:** `npm run check` - Run TypeScript and Prettier checks
323
+
324
+ ## Token Management
325
+
326
+ ### OAuth Token Storage
327
+
328
+ Tokens are automatically stored in:
329
+
330
+ ```
331
+ ~/.mcp-auth/wordpress-remote-{version}/
332
+ ```
333
+
334
+ ### Manual Management
335
+
336
+ ```bash
337
+ # View stored tokens
338
+ ls -la ~/.mcp-auth/wordpress-remote-*/
339
+
340
+ # Clear all tokens (forces re-authentication)
341
+ rm -rf ~/.mcp-auth/wordpress-remote-*/
342
+
343
+ # Clear tokens for specific version
344
+ rm -rf ~/.mcp-auth/wordpress-remote-0.2.1/
345
+ ```
346
+
347
+ ### Token Security
348
+
349
+ - **Secure file permissions** (600) on all token files
350
+ - **Automatic token validation** before each request
351
+ - **Expired token cleanup** during startup
352
+ - **Version isolation** - each version stores tokens separately
353
+
354
+ ## Multi-Instance Support
355
+
356
+ The proxy automatically coordinates between multiple instances:
357
+
358
+ - **Lockfiles** prevent simultaneous OAuth flows
359
+ - **Process coordination** ensures only one authentication at a time
360
+ - **Graceful waiting** when another instance is authenticating
361
+ - **Automatic cleanup** of stale locks
362
+
363
+ If you see "waiting for other instance" messages, this is normal behavior.
364
+
365
+ ## Troubleshooting
366
+
367
+ ### Authentication Issues
368
+
369
+ **OAuth browser doesn't open:**
370
+
371
+ - Check if port 3000 is available
372
+ - Try a different port with `OAUTH_CALLBACK_PORT`
373
+ - Manually open the URL shown in logs
374
+
375
+ **OAuth authorization fails:**
376
+
377
+ - Verify WordPress site has MCP plugin installed and enabled
378
+ - Check WordPress admin user permissions
379
+ - Try clearing tokens and re-authenticating
380
+
381
+ **JWT authentication fails:**
382
+
383
+ - Verify JWT token is valid and not expired
384
+ - Check token format and encoding
385
+ - Ensure WordPress site supports JWT authentication
386
+
387
+ **Basic Auth fails:**
388
+
389
+ - Verify username and application password
390
+ - Check application password is active
391
+ - Ensure user has sufficient permissions
392
+
393
+ ### Connection Issues
394
+
395
+ **API endpoint not found:**
396
+
397
+ - Verify WordPress MCP plugin is installed and activated
398
+ - Check plugin is enabled in WordPress admin
399
+ - Confirm `WP_API_URL` is correct
400
+
401
+ **Permission denied:**
402
+
403
+ - Check user permissions in WordPress
404
+ - Verify authentication credentials
405
+ - Review WordPress user roles
406
+
407
+ ### Port Conflicts
408
+
409
+ If port 3000 is already in use:
410
+
411
+ ```json
412
+ {
413
+ "env": {
414
+ "OAUTH_CALLBACK_PORT": "8080"
415
+ }
416
+ }
417
+ ```
418
+
419
+ ### Multi-instance Messages
420
+
421
+ "Waiting for other instance" messages are normal when multiple MCP clients start simultaneously. The system coordinates authentication to prevent conflicts.
422
+
423
+ ### Log Analysis
424
+
425
+ Enable detailed logging:
426
+
427
+ ```json
428
+ {
429
+ "env": {
430
+ "LOG_LEVEL": "3",
431
+ "LOG_FILE": "/path/to/logfile.log"
432
+ }
433
+ }
434
+ ```
435
+
436
+ Log levels:
437
+
438
+ - `0` - Errors only
439
+ - `1` - Warnings and errors
440
+ - `2` - Info, warnings, and errors (default)
441
+ - `3` - Debug, info, warnings, and errors
442
+
443
+ ## Security Features
444
+
445
+ - **Secure OAuth flow** with state parameters and PKCE
446
+ - **Token encryption** with secure file permissions
447
+ - **Automatic validation** before each API request
448
+ - **Expired token cleanup** and refresh handling
449
+ - **Multi-instance coordination** prevents authentication conflicts
450
+
451
+ ## Why Use MCP WordPress Remote?
452
+
453
+ 1. **Multiple Authentication Methods** - Choose what works best for your setup
454
+ 2. **Enhanced Security** - OAuth 2.0 with persistent token storage
455
+ 3. **Better User Experience** - One-time setup with automatic token management
456
+ 4. **Multi-Instance Support** - Works reliably with multiple MCP clients
457
+ 5. **Comprehensive Logging** - Detailed logs for troubleshooting
458
+ 6. **Easy Setup** - No global installation required with npx
459
+
460
+ ## Requirements
461
+
462
+ - **Node.js 22+** (required for fetch API support)
463
+ - **WordPress site** with [wordpress-mcp](https://github.com/Automattic/wordpress-mcp) plugin
464
+ - **WordPress user account** with appropriate permissions
465
+
466
+ ## License
467
+
468
+ GPL v2 or later
469
+
470
+ ## Contributing
26
471
 
27
- - `WP_API_URL`: The URL of your WordPress site (e.g., `https://example.com`)
28
- - `WP_API_USERNAME`: Your WordPress username
29
- - `WP_API_PASSWORD`: Your WordPress [application password](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/#Getting-Credentials)
30
- - `WOO_CUSTOMER_KEY`: Your Woocommerce customer key (optional, if you intend to use WooCommerce MCP assets)
31
- - `WOO_CUSTOMER_SECRET`: Your WooCommerce customer secret (optional, if you intend to use WooCommerce MCP assets)
32
- - `LOG_FILE`: Optional full path to a log file
472
+ Contributions welcome! This project is maintained by Automattic Inc.
33
473
 
34
- ### Configuration in MCP Clients
474
+ ## Support
35
475
 
36
- Please check [WordPress-mcp](https://github.com/Automattic/wordpress-mcp?tab=readme-ov-file#mcp-client-configuration) plugin git repository for configuration details
476
+ - **Issues:** [GitHub Issues](https://github.com/Automattic/mcp-wordpress-remote/issues)
477
+ - **Documentation:** Check the troubleshooting section above
478
+ - **WordPress MCP Plugin:** [Plugin Repository](https://github.com/Automattic/wordpress-mcp)
37
479
 
38
- ## @todo
480
+ ---
39
481
 
40
- As of now, this package is in its early development stages. Any suggestions, bugreports, PR's are welcome.
482
+ **Need help?** Check the [troubleshooting section](#troubleshooting) or open an issue.