WordPress服务器工具集

提供WordPress REST API客户端、WP-CLI工具、模式转换、日志记录和缓存功能的服务端工具包

  • by Akungapaul
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 Akungapaul/wp-mcp-shared

使用说明

@阿昆加保尔/wp-mcp分享

WordPress MCP(模型上下文协议)服务器的共享实用程序。

安装

npm install @akungapaul/wp-mcp-shared

对于GitHub软件包,请添加到您的 .npmrc:

@akungapaul:registry=https://npm.pkg.github.com

模块

客户

WordPressRestClient

用于WordPress REST API的HTTP客户端,内置缓存和身份验证。

import { WordPressRestClient } from '@akungapaul/wp-mcp-shared';

const client = new WordPressRestClient({
  url: 'https://your-site.com',
  username: 'your-username',
  appPassword: 'your-app-password'
});

// Posts
const posts = await client.getPosts({ per_page: 10 });
const post = await client.createPost({ title: 'New Post', content: 'Content' });

// Media
const media = await client.getMedia();

// Categories & Tags
const categories = await client.getCategories();

WPCLIClient

在本地或通过SSH执行WP-CLI命令。

import { WPCLIClient } from '@akungapaul/wp-mcp-shared';

const cli = new WPCLIClient({
  enabled: true,
  wpCliPath: '/usr/local/bin/wp',
  wordPressPath: '/var/www/html',
  // SSH options (optional)
  sshHost: 'server.com',
  sshUser: 'user',
  sshKeyPath: '~/.ssh/id_rsa'
});

await cli.cacheFlush();
await cli.installPlugin('akismet', true);
await cli.dbOptimize();

公用事业

架构实用程序

将Zod模式转换为MCP工具的干净JSON模式。

import { convertSchema, createMcpServer, startServer } from '@akungapaul/wp-mcp-shared';
import { z } from 'zod';

// Convert individual schema
const jsonSchema = convertSchema(z.object({
  title: z.string(),
  content: z.string().optional()
}));

// Create full MCP server
const tools = [
  {
    name: 'create_post',
    description: 'Create a WordPress post',
    inputSchema: z.object({ title: z.string() }),
    handler: async (args) => { /* ... */ }
  }
];

const server = createMcpServer('my-mcp', '1.0.0', tools);
await startServer(server);

日志记录器

基于Winston的结构化日志记录。

import { logger } from '@akungapaul/wp-mcp-shared';

logger.info('Message');
logger.error('Error', { details: 'context' });
logger.debug('Debug info');

缓存

支持TTL的内存缓存。

import { cache } from '@akungapaul/wp-mcp-shared';

cache.set('key', value, 300); // 5 minute TTL
const data = cache.get('key');
cache.invalidatePattern('posts');
cache.flush();

环境变量

变量 描述 默认值
WORDPRESS_URL WordPress网站URL -
WORDPRESS_USERNAME WordPress用户名 -
WORDPRESS_APP_PASSWORD 应用程序密码 -
ENABLE_WP_CLI 启用WP-CLI客户端 false
WP_CLI_PATH wp-cli路径 wp
WORDPRESS_PATH WordPress安装路径 .
SSH_HOST 远程WP-CLI的SSH主机 -
SSH_PORT SSH端口 22
SSH_USER SSH用户名 -
SSH_KEY_PATH SSH私钥路径 -
CACHE_ENABLED 启用响应缓存 true
CACHE_TTL 缓存TTL(秒) 300
LOG_LEVEL 日志记录级别 info

相关套餐

此软件包由以下人员使用:

  • wp-content-mcp -帖子和页面管理
  • wp-media-mcp -媒体库管理
  • wp-taxonomy-mcp -类别和标签
  • wp-themes-mcp -主题管理
  • wp-menus-mcp -导航菜单
  • wp-design-mcp -自定义CSS和颜色
  • wp-plugins-mcp -插件管理
  • wp-settings-mcp -站点设置
  • wp-blocks-mcp -块模式和可重用块
  • wp-seo-mcp -SEO和元标签
  • wp-advanced-mcp -数据库和高级操作

许可证

麻省理工学院