返回 MCP 目录
public公开dns本地运行

woocommerce-mcp-server-rdn

该项目是一个基于Model Context Protocol (MCP)的服务器,用于将WooCommerce电商平台与Claude等AI助手集成,提供订单查询和管理功能。

article

README

🚀 WooCommerce MCP 服务器

WooCommerce MCP 服务器是一个强大的工具,它基于模型上下文协议(MCP),能将 WooCommerce 与 Claude 等 AI 助手集成,让 AI 助手可以与 WooCommerce 店铺进行交互,实现订单数据的获取等功能。

🚀 快速开始

此服务器提供工具,使 AI 助手能够与 WooCommerce 店铺交互,允许它们:

  • 获取最近订单,带有可选过滤
  • 获取特定订单 ID 的详细信息

✨ 主要特性

  • 提供工具让 AI 助手与 WooCommerce 店铺交互。
  • 支持获取最近订单,且可进行可选过滤。
  • 能够获取特定订单 ID 的详细信息。

📦 安装指南

先决条件

要使用此 MCP 服务器,您需要以下内容:

  1. Node.js:确保安装了 Node.js(建议版本 14 或更高)。
  2. npm:验证 npm 是否已安装。
  3. WooCommerce REST API 访问权限:需要 WooCommerce 店铺的管理员访问权限以获取 API 令牌。

安装步骤

按照以下步骤安装 MCP 服务器:

  1. 克隆此仓库:
    git clone [仓库 URL]
    cdwoocommerce-mcp-server
    
  2. 安装依赖项:
    npm install
    
  3. 启动服务器:
    npm start
    

📚 详细文档

配置

WooCommerce 配置

config.js 文件中添加以下配置:

const wooCommerceConfig = {
    URL: 'YOUR_WOOCOMMERCE_SITE_URL',
    CONSUMER_KEY: 'YOUR_API_KEY',
    CONSUMER_SECRET: 'YOUR_API_SECRET'
};

MCP 服务器配置

server.js 文件中,加载 WooCommerce 配置并初始化 MCP 服务器:

const wooCommerce = require('woocommerce')(config);
const mcpServer = new McpServer(wooCommerce);
mcpServer.start();

运行服务器

启动服务器后,您可以在以下端点访问 MCP 服务:

  • 获取最近订单GET /api/orders
  • 获取特定订单GET /api/orders/{orderId}

与 Claude 桌面集成

要在 Claude 桌面中使用此 MCP 服务器,请按照以下步骤操作:

  1. 下载并安装 Claude 桌面
  2. config.json 文件中添加 MCP 服务器的详细信息:
    {
        "servers": [
            {
                "name": "WooCommerce MCP Server",
                "host": "localhost",
                "port": "3000"
            }
        ]
    }
    
  3. 启动 Claude 桌面并与您的 WooCommerce 店铺集成。

💻 使用示例

可用工具

获取最近订单

server.tool(
    'getRecentOrders',
    {
        count: z.number().int().positive().describe('获取的订单数量(最多 10 个)')
    },
    async ({count}) => {
        const orders = await wooCommerce.orders.getAll({
            per_page: count,
            page: 1
        });
        
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify(orders.data, null, 2)
                }
            ]
        };
    }
);

获取特定订单

server.tool(
    'getOrderById',
    {
        orderId: z.string().describe('要获取的订单 ID')
    },
    async ({orderId}) => {
        const order = await wooCommerce.orders.getOrder(orderId);
        
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify(order.data, null, 2)
                }
            ]
        };
    }
);

构建自定义 MCP 服务器

步骤 1 - 初始化项目

创建一个新的 Node.js 项目并安装所需的依赖项:

mkdir my-mcp-server
cd my-mcp-server
npm init
npm install @modelcontextprotocol/sdk

编辑 package.json 文件,使其支持 ES 模块:

{
    "type": "module",
    "scripts": {
        "start": "node index.js"
    }
}

步骤 2 - 定义工具

index.js 文件中定义 MCP 工具:

const { McpServer } = require('@modelcontextprotocol/sdk');

// 创建 MCP 服务器实例
const server = new McpServer();

// 注册工具:获取字符串长度
server.tool(
    'getStrLength',
    {
        input: z.string().describe('要计算长度的字符串')
    },
    async ({input}) => {
        return {
            content: [
                {
                    type: 'text',
                    text: `${input.length} 字符串长度`
                }
            ]
        };
    }
);

// 启动服务器
server.start();

步骤 3 - 测试本地

运行以下命令测试 MCP 服务器:

npm start

🔧 技术细节

该服务器基于 Node.js 和 npm 构建,利用 WooCommerce REST API 实现与 WooCommerce 店铺的交互。通过在 config.jsserver.js 中进行配置,实现服务器的启动和与 WooCommerce 的连接。同时,使用 @modelcontextprotocol/sdk 来构建 MCP 服务器和定义工具。

📄 许可证

MIT 许可证

help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端