MCP Adapter
OfficialMCP Adapter
属于 AI Building Blocks for WordPress 计划 的一部分
这是 WordPress 官方的 MCP 集成包,它将 WordPress 的能力以 Model Context Protocol (MCP) 工具、资源和提示的形式暴露给 AI 代理。
概述
该适配器将 WordPress 的 Abilities API 与 MCP 规范 桥接起来,为 AI 代理与 WordPress 功能交互提供了一种标准化的方式。它支持 HTTP 和 STDIO 传输、全面的错误处理,以及用于自定义集成的可扩展架构。
Related MCP server: MCP Adapter Implementation Example
功能特性
核心功能
能力到 MCP 的转换:自动将 WordPress 能力转换为 MCP 工具、资源和提示
多服务器管理:创建和管理多个具有独特配置的 MCP 服务器
可扩展的传输层:
HTTP 传输:实现 MCP 2025-11-25 规范 的统一传输,用于基于 HTTP 的通信
STDIO 传输:通过标准输入/输出进行基于进程的通信,适用于本地开发和 CLI 集成
自定义传输支持:实现
McpTransportInterface以创建专门的通信协议多传输配置:同时使用多种传输方法配置服务器
灵活的错误处理:
内置错误处理器:包含默认的 WordPress 兼容错误日志记录
自定义错误处理器:实现
McpErrorHandlerInterface以用于自定义日志记录、监控或通知系统服务器特定处理器:每个 MCP 服务器采用不同的错误处理策略
可观测性:
内置可观测性:默认的零开销指标跟踪,带有可配置的处理器
自定义可观测性处理器:实现
McpObservabilityHandlerInterface以与监控系统集成
验证:内置对工具、资源和提示的验证,并支持可扩展的验证规则
权限控制:对所有暴露的功能进行细粒度的权限检查,并支持可配置的传输权限
MCP 组件支持
工具:将 WordPress 能力转换为可执行的 MCP 工具,供 AI 代理交互
资源:将 WordPress 数据作为 MCP 资源暴露,用于上下文信息访问
提示:将能力转换为结构化的 MCP 提示,用于 AI 指导和模板
服务器发现:按照 MCP 协议标准自动注册和发现 MCP 服务器
内置能力:用于系统自省和能力管理的核心 WordPress 能力
CLI 集成:支持 MCP 规范中定义的 STDIO 传输的 WP-CLI 命令
架构
有关组件结构的完整说明,请参阅架构概述。
依赖项
PHP:>= 7.4
WordPress:>= 6.9(包含核心中的 Abilities API — 无需单独插件)
php-mcp-schema (
^0.1.0):用于 MCP 协议类型的类型化 DTO
安装
MCP Adapter 作为 WordPress 插件分发。像其他插件一样安装并激活它。发布版本自带所有必需内容,因此无需配置自动加载器,也无需运行构建步骤。
需要 WordPress 6.9 或更高版本;Abilities API 是核心的一部分,因此无需安装单独的插件。
手动安装
从 GitHub Releases 页面 下载最新的稳定版 mcp-adapter.zip,然后从 插件 → 安装插件 → 上传插件 上传并激活它。
使用 WP-CLI
wp plugin install https://github.com/WordPress/mcp-adapter/releases/latest/download/mcp-adapter.zip --activate使用 WP-Env
// .wp-env.json
{
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
"plugins": [
"https://github.com/WordPress/mcp-adapter/releases/latest/download/mcp-adapter.zip"
]
}作为你插件的依赖项
WP\MCP 类由 MCP Adapter 插件提供,因此请在插件头部中使用 Requires Plugins 字段将其声明为插件依赖:
<?php
/**
* Plugin Name: My Plugin
* Description: Adds MCP tools for my feature.
* Requires Plugins: mcp-adapter
*/在你的插件中使用 MCP Adapter
在 plugins_loaded 时检查可用性并初始化,以便在适配器启动之前所有插件都可用:
add_action( 'plugins_loaded', function() {
if ( ! class_exists( 'WP\MCP\Core\McpAdapter' ) ) {
// MCP Adapter is not active — show an admin notice or return early.
return;
}
\WP\MCP\Core\McpAdapter::instance();
} );基本用法
MCP Adapter 会自动创建一个默认服务器,通过分层架构暴露已注册的 WordPress 能力。这提供了即时的 MCP 功能,无需手动配置服务器。
工作原理:
通过
wp_register_ability()注册且meta.public设置为true的 WordPress 能力,可通过其内置的适配器工具在默认服务器上被发现和执行显式设置
meta.mcp.public以覆盖仅针对 MCP 的高级设置;false使公共能力不参与 MCP,而true则将原本私有的能力暴露给 MCP在默认服务器上,公共能力通过
mcp-adapter/discover-abilities、mcp-adapter/get-ability-info和mcp-adapter/execute-ability访问,而不是在tools/list中单独自动注册或者,在创建自定义 MCP 服务器时可以显式列出能力;在这种情况下,它们可以直接作为 MCP 工具、资源或提示暴露,无需
meta.mcp.public标志默认服务器支持 HTTP 和 STDIO 两种传输,并支持多个 MCP 协议版本
包含内置的错误处理和可观测性
通过 HTTP 访问:
/wp-json/mcp/mcp-adapter-default-server通过 STDIO 访问:
wp mcp-adapter serve --server=mcp-adapter-default-server
// Simply register a WordPress ability
add_action( 'wp_abilities_api_init', function() {
wp_register_ability( 'my-plugin/get-posts', [
'label' => 'Get Posts',
'description' => 'Retrieve WordPress posts with optional filtering',
'category' => 'site',
'input_schema' => [
'type' => 'object',
'properties' => [
'numberposts' => [
'type' => 'integer',
'description' => 'Number of posts to retrieve',
'default' => 5,
'minimum' => 1,
'maximum' => 100
],
'post_status' => [
'type' => 'string',
'description' => 'Post status to filter by',
'enum' => ['publish', 'draft', 'private'],
'default' => 'publish'
]
]
],
'output_schema' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'ID' => ['type' => 'integer'],
'post_title' => ['type' => 'string'],
'post_content' => ['type' => 'string'],
'post_date' => ['type' => 'string'],
'post_author' => ['type' => 'string']
]
]
],
'execute_callback' => function( $input ) {
$args = [
'numberposts' => $input['numberposts'] ?? 5,
'post_status' => $input['post_status'] ?? 'publish'
];
return get_posts( $args );
},
'permission_callback' => function() {
return current_user_can( 'read' );
},
'meta' => [
'public' => true, // Expose to clients, including the default MCP server
],
]);
});
// With the meta.public flag, the ability is exposed through the default MCP server.
// In the default server configuration, discover it via `discover-abilities`
// and invoke it via `mcp-adapter/execute-ability` rather than expecting
// it to appear as its own entry in `tools/list`.
// To opt out of MCP while remaining public to other clients, explicitly set
// meta.mcp.public to false.
// To expose only through MCP, omit `meta.public` and set `meta.mcp.public` to true.
// Without either public flag, abilities are only accessible through custom MCP
// servers that explicitly list them.
// Note: how far `meta.public` reaches depends on the WordPress version. WordPress
// core starts applying `meta.public` to the REST API (`meta.show_in_rest`) in 7.1. On
// WordPress 6.9 and 7.0, this adapter honors `meta.public` for MCP, but REST API
// access still requires setting `meta.show_in_rest` to true.有关创建 WordPress 能力的详细信息,请参阅 Abilities API 开发者文档。
连接到 MCP 服务器
MCP Adapter 支持多种连接方式。以下是使用 MCP 客户端连接的示例:
STDIO 传输(本地开发)
对于本地开发和测试,你可以使用 WP-CLI 命令直接与 MCP 服务器交互:
# List all available MCP servers
wp mcp-adapter list
# Test the discover abilities tool to see all available WordPress abilities
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"mcp-adapter-discover-abilities","arguments":{}}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server
# Test listing available tools
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-serverMCP 客户端配置
配置 MCP 客户端(Claude Desktop、Claude Code、VS Code、Cursor 等)以连接到你的 WordPress MCP 服务器。
{
"mcpServers": {
"wordpress-default": {
"command": "wp",
"args": [
"--path=/path/to/your/wordpress/site",
"mcp-adapter",
"serve",
"--server=mcp-adapter-default-server",
"--user=admin"
]
},
"wordpress-custom": {
"command": "wp",
"args": [
"--path=/path/to/your/wordpress/site",
"mcp-adapter",
"serve",
"--server=your-custom-server-id",
"--user=admin"
]
}
}
}@automattic/mcp-wordpress-remote 代理在本地运行,将来自 AI 客户端的基于 STDIO 的 MCP 通信转换为 WordPress 能够理解的 HTTP REST API 调用。身份验证使用 WordPress 应用程序密码。
{
"mcpServers": {
"wordpress-http-default": {
"command": "npx",
"args": [
"-y",
"@automattic/mcp-wordpress-remote@latest"
],
"env": {
"WP_API_URL": "http://your-site.test/wp-json/mcp/mcp-adapter-default-server",
"LOG_FILE": "/path/to/logs/mcp-adapter.log",
"WP_API_USERNAME": "your-username",
"WP_API_PASSWORD": "your-application-password"
}
},
"wordpress-http-custom": {
"command": "npx",
"args": [
"-y",
"@automattic/mcp-wordpress-remote@latest"
],
"env": {
"WP_API_URL": "http://your-site.test/wp-json/your-namespace/your-route",
"LOG_FILE": "/path/to/logs/mcp-adapter.log",
"WP_API_USERNAME": "your-username",
"WP_API_PASSWORD": "your-application-password"
}
}
}
}高级用法
创建自定义 MCP 服务器
对于高级用例,你可以创建具有特定配置的自定义 MCP 服务器:
add_action( 'mcp_adapter_init', function( $adapter ) {
$adapter->create_server(
'my-server-id', // Unique server identifier
'my-namespace', // REST API namespace
'mcp', // REST API route
'My MCP Server', // Server name
'Description of my server', // Server description
'v1.0.0', // Server version
array( // Transport methods
\WP\MCP\Transport\HttpTransport::class,
),
\WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler::class, // Error handler
\WP\MCP\Infrastructure\Observability\NullMcpObservabilityHandler::class, // Observability handler
array( 'my-plugin/my-ability' ), // Abilities to expose as tools
array(), // Resources (optional)
array() // Prompts (optional)
);
} );自定义传输实现
MCP Adapter 包含生产就绪的 HTTP 传输。对于自定义身份验证、消息队列或企业集成等特殊需求,你可以创建自定义传输协议。
有关详细的实现说明,请参阅自定义传输指南。
自定义传输权限
MCP Adapter 通过传输权限回调支持自定义身份验证逻辑。你可以为 MCP 服务器实现自定义身份验证,而不是默认的 is_user_logged_in() 检查。
有关详细的身份验证模式,请参阅传输权限指南。
自定义错误处理器
MCP Adapter 包含默认的 WordPress 兼容错误处理器,但你可以实现自定义错误处理,以与现有的日志系统、监控工具集成或满足特定需求。
有关详细的实现说明,请参阅错误处理指南。
自定义可观测性处理器
MCP Adapter 包含内置的可观测性,用于跟踪指标和事件。你可以实现自定义可观测性处理器,以与监控系统、分析平台或性能跟踪工具集成。
有关详细的指标跟踪和自定义处理器实现,请参阅可观测性指南。
迁移
迁移指南:v0.5.0 — 破坏性变更和升级说明
迁移指南:v0.3.0 — 传输、可观测性和钩子名称变更
许可证
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
AlicenseBqualityFmaintenanceA WordPress plugin that implements the Model Context Protocol to enable AI models and applications to interact with WordPress sites in a structured and secure way.536944ISC- FlicenseNot gradedqualityDmaintenanceEnables WordPress content management through the Model Context Protocol, allowing AI agents to create, read, update, and delete posts, metadata, taxonomies, and terms, as well as interact with Gutenberg blocks.1
- FlicenseNot gradedqualityFmaintenanceEnables WordPress content management (posts, metadata, taxonomies, Gutenberg blocks) via the Model Context Protocol, demonstrating MCP Adapter integration patterns.
- AlicenseNot gradedqualityCmaintenanceA comprehensive WordPress plugin that implements the Model Context Protocol (MCP) to expose WordPress functionality through standardized interfaces, enabling AI models and applications to interact with WordPress sites securely using multiple transport protocols and enterprise-grade authentication.36MIT
Related MCP Connectors
Security-first WordPress MCP server. 129 tools for Claude, ChatGPT, Gemini. Free on wp.org.
WordPress MCP server: publish posts, AI images, SEO and full site management, self-hosted
WordPress MCP server: generate SEO posts, AI images, autoblog & WooCommerce on your self-hosted site
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/WordPress/mcp-adapter'
If you have feedback or need assistance with the MCP directory API, please join our Discord server