woocommerce-mcp

juanlurg/woocommerce-mcp Checked 2 days ago

Model-Context-Protocol to connect your store with any LLM

A powerful, modern Model-Context-Protocol (MCP) server designed to connect AI assistants with your WooCommerce store. This server provides a comprehensive set of tools to seamlessly manage orders, products, inventory, and analytics using the WooCommerce REST API. This server equips AI assistants with a robust toolkit for complete store management. This project uses uv for fast dependency management. If you don't have it, you can install it with the command below.

Summary extracted from the README.

πŸ›’ WooCommerce MCP Server

A powerful, modern Model-Context-Protocol (MCP) server designed to connect AI assistants with your WooCommerce store. This server provides a comprehensive set of tools to seamlessly manage orders, products, inventory, and analytics using the WooCommerce REST API.

✨ Features

This server equips AI assistants with a robust toolkit for complete store management.

Feature Capabilities
πŸ“¦ Order Management Retrieve, list, create, update, and cancel orders. You can also add and manage order notes for both internal and customer use.
πŸ›οΈ Product Management Access detailed product information, list the entire catalog with filters, and create or update products.
πŸ“Š Inventory Control Effortlessly manage stock levels with set, increase, or decrease operations, and automatically monitor for low-stock items.
πŸ“ˆ Analytics & Reporting Generate detailed sales reports for any period, identify top-selling products, and get alerts for low inventory.
πŸ’‘ Smart Prompts Leverage pre-configured prompts for common e-commerce workflows like processing pending orders, handling refunds, and preparing shipping batches.

πŸš€ Installation

Prerequisites

  • Python 3.12 or higher
  • A WooCommerce store with the REST API enabled
  • WooCommerce API credentials (Consumer Key & Consumer Secret)

Setup Instructions

  1. Clone the Repository

    git clone https://github.com/your-username/woocommerce-mcp.git
    cd woocommerce-mcp
    
  2. Install Dependencies

    This project uses uv for fast dependency management. If you don't have it, you can install it with the command below.

    # Install uv (if not already installed)
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # Install project dependencies
    uv sync
    
  3. Configure Environment Variables

    Create a .env file to store your store's credentials.

    # Copy the example environment file
    cp .env.example .env
    
    # Edit the .env file with your details
    nano .env
    
  4. Add Your WooCommerce Credentials

    Update the .env file with your store's URL and API keys.

    WOOCOMMERCE_URL="https://your-store.com"
    WOOCOMMERCE_CONSUMER_KEY="ck_your_consumer_key_here"
    WOOCOMMERCE_CONSUMER_SECRET="cs_your_consumer_secret_here"
    WOOCOMMERCE_API_VERSION="v3"
    WOOCOMMERCE_TIMEOUT=30
    DEBUG=false
    

How to Get WooCommerce API Credentials

  1. Log into your WordPress admin dashboard.
  2. Navigate to WooCommerce > Settings > Advanced > REST API.
  3. Click Add Key.
  4. Fill in the details:
    • Description: Give the key a recognizable name (e.g., "MCP Server Access").
    • User: Select an administrator user.
    • Permissions: Set to Read/Write.
  5. Click Generate API Key.
  6. Copy the Consumer Key and Consumer Secret into your .env file.

⚠️ Important: Keep your API credentials secure. Never commit your .env file to version control.

Usage

Running the Server

You can run the MCP server directly using uv.

# Run the server using uv
uv run python -m src.woocommerce_mcp.server

# Alternatively, activate the virtual environment first
uv shell
python -m src.woocommerce_mcp.server

Available Tools

The server exposes the following tools for an AI assistant to use:

Order Management

  • get_order(order_id): Get details for a specific order.
  • list_orders(status, after, before, page, per_page): List orders with optional filters.
  • create_order(...): Create a new order with customer and product details.
  • update_order_status(order_id, status, note, notify_customer): Update an order's status.
  • cancel_order(order_id, reason): Cancel a specific order.
  • add_order_note(order_id, note, notify_customer): Add a note to an order.

Product & Inventory Management

  • get_product(product_id): Get details for a specific product.
  • list_products(search, category, status, page, per_page): List products with filters.
  • create_product(name, product_type, regular_price, ...): Add a new product to the catalog.
  • update_product(product_id, name, regular_price, ...): Modify an existing product.
  • update_stock(product_id, quantity, operation): Manage stock levels ('set', 'increase', 'decrease').

Analytics & Reporting

  • get_sales_report(period, date_min, date_max): Generate a sales report.
  • get_top_sellers(period, limit): Get a list of top-selling products.
  • get_low_stock_products(threshold, page, per_page): Find products with low inventory.

πŸ› οΈ Development

Running Tests

To run the test suite, first install the development dependencies and then use pytest.

# Install both production and development dependencies
uv sync --dev

# Run tests
uv run pytest

# Run tests with coverage report
uv run pytest --cov=src/woocommerce_mcp

Code Quality

This project uses Ruff for linting and formatting and Pyright for type checking.

# Format code
uv run ruff format .

# Check for linting issues
uv run ruff check .

# Automatically fix linting issues
uv run ruff check . --fix

# Run static type checking
uv run pyright

πŸ“‚ Project Structure

woocommerce-mcp/
β”œβ”€β”€ .env.example         # Example environment variables
β”œβ”€β”€ .gitignore           # Git ignore file
β”œβ”€β”€ pyproject.toml       # Project metadata and dependencies
β”œβ”€β”€ main.py              # Main entry point
β”œβ”€β”€ README.md            # This file
└── src/
    └── woocommerce_mcp/
        β”œβ”€β”€ __init__.py
        β”œβ”€β”€ client.py      # WooCommerce API client
        β”œβ”€β”€ models.py      # Pydantic models for API data
        β”œβ”€β”€ prompts.py     # Smart prompt definitions
        └── server.py      # MCP server implementation