Woocommerce Mcp Server Rdn

Woocommerce Mcp Server Rdn

🚀 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 许可证

  • 0 关注
  • 0 收藏,26 浏览
  • system 提出于 2025-10-04 02:57

相似服务问题

相关AI产品