Skip to content

Commit 7c8b47d

Browse files
budzanowskiclaude
andcommitted
Add developer documentation for MCP integration
Adds comprehensive developer-facing documentation for WooCommerce MCP (Model Context Protocol) integration following the structure and style of existing WooCommerce feature documentation. Documentation includes: - Overview of MCP integration architecture and components - Available abilities for products and orders management - Authentication and security requirements - Connection instructions for Claude Code and other MCP clients - Extension guidelines for third-party developers - Troubleshooting and debugging information - References to demo plugin and related resources The documentation emphasizes that this is a developer preview feature with implementation details that may change in future releases. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent c216491 commit 7c8b47d

File tree

2 files changed

+287
-0
lines changed

2 files changed

+287
-0
lines changed

docs/features/mcp/README.md

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
---
2+
post_title: Model Context Protocol (MCP) Integration
3+
sidebar_label: MCP Integration
4+
category_slug: mcp
5+
---
6+
7+
# Model Context Protocol (MCP) Integration
8+
9+
## Introduction
10+
11+
WooCommerce includes native support for the Model Context Protocol (MCP), enabling AI assistants and tools to interact directly with WooCommerce stores through a standardized protocol. This integration exposes WooCommerce functionality as discoverable tools that AI clients can use to perform store operations with proper authentication and permissions.
12+
13+
**Developer Preview Notice**: The MCP implementation in WooCommerce is currently in developer preview. Implementation details, APIs, and integration patterns may change in future releases as the feature matures.
14+
15+
## Background
16+
17+
The Model Context Protocol (MCP) is an open standard that enables AI applications to securely connect to external data sources and tools. WooCommerce's MCP integration builds on two core technologies:
18+
19+
- **[WordPress Abilities API](https://github.com/WordPress/abilities-api)** - A standardized system for registering capabilities in WordPress
20+
- **[WooCommerce MCP Adapter](https://github.com/WordPress/mcp-adapter)** - The core MCP protocol implementation
21+
22+
This architecture allows WooCommerce to expose operations as MCP tools through the flexible WordPress Abilities system while maintaining existing security and permission models.
23+
24+
## What's Available
25+
26+
WooCommerce's MCP integration provides AI assistants with structured access to core store operations:
27+
28+
### Product Management
29+
- List products with filtering and pagination
30+
- Retrieve detailed product information
31+
- Create new products
32+
- Update existing products
33+
- Delete products
34+
35+
### Order Management
36+
- List orders with filtering and pagination
37+
- Retrieve detailed order information
38+
- Create new orders
39+
- Update existing orders
40+
41+
All operations respect WooCommerce's existing permission system and are authenticated using WooCommerce REST API keys.
42+
43+
## Architecture
44+
45+
The MCP integration follows this data flow:
46+
47+
```
48+
AI Client (Claude, etc.)
49+
↓ (MCP protocol over HTTPS)
50+
WooCommerce MCP Server
51+
↓ (WordPress Abilities API)
52+
WooCommerce Abilities
53+
```
54+
55+
### Core Components
56+
57+
**MCP Adapter Provider** ([`MCPAdapterProvider.php`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Internal/MCP/MCPAdapterProvider.php))
58+
- Manages MCP server initialization and configuration
59+
- Handles feature flag checking (`mcp_integration`)
60+
- Provides ability filtering and namespace management
61+
62+
**Abilities Registry** ([`AbilitiesRegistry.php`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Internal/Abilities/AbilitiesRegistry.php))
63+
- Centralizes WooCommerce ability registration
64+
- Bridges WordPress Abilities API with WooCommerce operations
65+
- Enables ability discovery for the MCP server
66+
67+
**REST Bridge Implementation** ([`AbilitiesRestBridge.php`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Internal/Abilities/AbilitiesRestBridge.php))
68+
- Current preview implementation that maps REST operations to WordPress abilities
69+
- Provides explicit ability definitions with schemas for products and orders
70+
- Demonstrates how abilities can be implemented using existing REST controllers
71+
72+
**WooCommerce Transport** ([`WooCommerceRestTransport.php`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Internal/MCP/Transport/WooCommerceRestTransport.php))
73+
- Handles WooCommerce API key authentication
74+
- Enforces HTTPS requirements
75+
- Validates permissions based on API key scope
76+
77+
### Implementation Approach
78+
79+
For this developer preview, WooCommerce abilities are implemented by bridging to existing REST API endpoints. This approach allows us to quickly expose core functionality while leveraging proven REST controllers. However, the WordPress Abilities API is designed to be flexible - abilities can be implemented in various ways beyond REST endpoint proxying, including direct database operations, custom business logic, or integration with external services.
80+
81+
## Enabling MCP Integration
82+
83+
The MCP feature is controlled by the `mcp_integration` feature flag. You can enable it programmatically:
84+
85+
```php
86+
add_filter( 'woocommerce_features', function( $features ) {
87+
$features['mcp_integration'] = true;
88+
return $features;
89+
});
90+
```
91+
92+
## Authentication and Security
93+
94+
### API Key Requirements
95+
96+
MCP clients authenticate using WooCommerce REST API keys in the `X-MCP-API-Key` header:
97+
98+
```
99+
X-MCP-API-Key: ck_your_consumer_key:cs_your_consumer_secret
100+
```
101+
102+
To create API keys:
103+
104+
1. Navigate to **WooCommerce → Settings → Advanced → REST API**
105+
2. Click **Add Key**
106+
3. Set appropriate permissions (`read`, `write`, or `read_write`)
107+
4. Generate and securely store the consumer key and secret
108+
109+
### HTTPS Enforcement
110+
111+
MCP requests require HTTPS by default. For local development, you can disable this requirement:
112+
113+
```php
114+
add_filter( 'woocommerce_mcp_allow_insecure_transport', '__return_true' );
115+
```
116+
117+
### Permission Validation
118+
119+
The transport layer validates operations against API key permissions:
120+
- `read` permissions: Allow GET requests
121+
- `write` permissions: Allow POST, PUT, PATCH, DELETE requests
122+
- `read_write` permissions: Allow all operations
123+
124+
## Server Endpoint
125+
126+
The WooCommerce MCP server is available at:
127+
128+
```
129+
https://yourstore.com/wp-json/woocommerce/mcp
130+
```
131+
132+
## Connecting to the MCP Server
133+
134+
**Current Implementation Note**: The MCP integration currently requires the `@automattic/mcp-wordpress-remote` proxy package to bridge between the MCP protocol and WordPress REST API. This proxy requirement is temporary and may change in future releases as the implementation evolves.
135+
136+
### Claude Code Integration
137+
138+
To connect Claude Code to your WooCommerce MCP server:
139+
140+
1. Go to **WooCommerce → Settings → Advanced → REST API**
141+
2. Create a new API key with "Read/Write" permissions
142+
3. Configure MCP with your API key using Claude Code:
143+
144+
```bash
145+
claude mcp add woocommerce_mcp \
146+
--env WP_API_URL=https://yourstore.com/wp-json/woocommerce/mcp \
147+
--env CUSTOM_HEADERS='{"X-MCP-API-Key": "YOUR_CONSUMER_KEY:YOUR_CONSUMER_SECRET"}' \
148+
-- npx -y @automattic/mcp-wordpress-remote@latest
149+
```
150+
151+
### Manual MCP Client Configuration
152+
153+
For other MCP clients, add this configuration to your MCP settings:
154+
155+
```json
156+
{
157+
"mcpServers": {
158+
"woocommerce_mcp": {
159+
"type": "stdio",
160+
"command": "npx",
161+
"args": [
162+
"-y",
163+
"@automattic/mcp-wordpress-remote@latest"
164+
],
165+
"env": {
166+
"WP_API_URL": "https://yourstore.com/wp-json/woocommerce/mcp",
167+
"CUSTOM_HEADERS": "{\"X-MCP-API-Key\": \"YOUR_CONSUMER_KEY:YOUR_CONSUMER_SECRET\"}"
168+
}
169+
}
170+
}
171+
}
172+
```
173+
174+
**Important**: Replace `YOUR_CONSUMER_KEY:YOUR_CONSUMER_SECRET` with your actual WooCommerce API credentials.
175+
176+
## Extending MCP Capabilities
177+
178+
### Adding Custom Abilities
179+
180+
Third-party plugins can register additional abilities using the WordPress Abilities API. Abilities can be implemented in various ways - REST endpoint bridging, direct operations, custom logic, or external integrations. Here's a basic example:
181+
182+
```php
183+
add_action( 'abilities_api_init', function() {
184+
wp_register_ability(
185+
'your-plugin/custom-operation',
186+
array(
187+
'label' => __( 'Custom Store Operation', 'your-plugin' ),
188+
'description' => __( 'Performs a custom store operation.', 'your-plugin' ),
189+
'callback' => 'your_custom_ability_handler',
190+
'permission' => 'manage_woocommerce',
191+
'input_schema' => array(
192+
'type' => 'object',
193+
'properties' => array(
194+
'store_id' => array(
195+
'type' => 'integer',
196+
'description' => 'Store identifier'
197+
)
198+
),
199+
'required' => array( 'store_id' )
200+
),
201+
'output_schema' => array(
202+
'type' => 'object',
203+
'properties' => array(
204+
'success' => array(
205+
'type' => 'boolean',
206+
'description' => 'Operation result'
207+
)
208+
)
209+
)
210+
)
211+
);
212+
});
213+
```
214+
215+
### Including Custom Abilities in WooCommerce MCP Server
216+
217+
By default, only abilities with the `woocommerce/` namespace are included. To include abilities from other namespaces:
218+
219+
```php
220+
add_filter( 'woocommerce_mcp_include_ability', function( $include, $ability_id ) {
221+
if ( str_starts_with( $ability_id, 'your-plugin/' ) ) {
222+
return true;
223+
}
224+
return $include;
225+
}, 10, 2 );
226+
```
227+
228+
## Development Example
229+
230+
For a complete working example, see the [WooCommerce MCP Ability Demo Plugin](https://github.com/WordPress/wc-mcp-ability). This demonstration plugin shows how third-party developers can:
231+
232+
- Register custom abilities using the WordPress Abilities API
233+
- Define comprehensive input and output schemas
234+
- Implement proper permission handling
235+
- Integrate with the WooCommerce MCP server
236+
237+
The demo plugin creates a `woocommerce-demo/store-info` ability that retrieves store information and statistics, demonstrating the integration patterns for extending WooCommerce MCP capabilities while using a direct implementation approach rather than REST endpoint bridging.
238+
239+
## Troubleshooting
240+
241+
### Common Issues
242+
243+
**MCP Server Not Available**
244+
- Verify the `mcp_integration` feature flag is enabled
245+
- Check that the MCP adapter is properly loaded
246+
- Review WooCommerce logs for initialization errors
247+
248+
**Authentication Failures**
249+
- Confirm API key format: `consumer_key:consumer_secret`
250+
- Verify API key permissions match operation requirements
251+
- Ensure HTTPS is used or explicitly allowed for development
252+
253+
**Ability Not Found**
254+
- Confirm abilities are registered during `abilities_api_init`
255+
- Check namespace inclusion using the `woocommerce_mcp_include_ability` filter
256+
- Verify ability callbacks are accessible
257+
258+
### Debug Logging
259+
260+
Enable WooCommerce logging to debug MCP operations:
261+
262+
```php
263+
add_filter( 'woocommerce_logging_enabled', '__return_true' );
264+
```
265+
266+
Check **WooCommerce → Status → Logs** for entries with source `woocommerce-mcp`.
267+
268+
## Important Considerations
269+
270+
- **Developer Preview**: This feature is in preview status and may change
271+
- **Implementation Approach**: Current abilities use REST endpoint bridging as a preview implementation
272+
- **Breaking Changes**: Future updates may introduce breaking changes
273+
- **Production Testing**: Thoroughly test before deploying to production
274+
- **API Stability**: The WordPress Abilities API and MCP adapter are evolving
275+
276+
## Related Resources
277+
278+
- [WordPress Abilities API Repository](https://github.com/WordPress/abilities-api)
279+
- [WooCommerce MCP Adapter Repository](https://github.com/WordPress/mcp-adapter)
280+
- [WooCommerce MCP Demo Plugin](https://github.com/WordPress/wc-mcp-ability)
281+
- [Model Context Protocol Specification](https://modelcontextprotocol.io/)
282+
- [WooCommerce REST API Documentation](https://woocommerce.github.io/woocommerce-rest-api-docs/)

docs/features/mcp/_category_.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"position": 5,
3+
"label": "Model Context Protocol (MCP)",
4+
"collapsed": false
5+
}

0 commit comments

Comments
 (0)