简单WP MCP适配器OAuth
为WordPress MCP适配器添加OAuth 2.1授权服务器支持。
动机
WordPress MCP适配器本身并不涵盖需要严格OAuth 2.1流程的AI客户端。
此插件通过将现有的WordPress站点转换为MCP访问的OAuth授权服务器来填补这一空白,重用:
- 现有的WordPress登录(
wp-login.php)用于身份验证 - WordPress托管的授权决策同意流
需求
- WordPress 6.8+
- PHP 7.4+
- OpenSSL扩展
- WordPress MCP适配器插件
特性
- OAuth使用同意流授权端点
- OAuth令牌端点
- 授权码流的PKCE支持(
S256) - 动态客户端注册端点
- OAuth发现端点
- JWKS端点
安装(开发)
- 跑
composer install. - 在WordPress管理中激活插件。
如何使用OAuthTransport
默认情况下,此插件会注册 SimpleWpMcpAdapterOAuth\OAuthTransport 通过过滤作为MCP传输 mcp_adapter_default_server_config.
如果你想注册一个服务器 OAuthTransport 明确地,您可以执行以下操作:
add_action(
'mcp_adapter_init',
function ( $adapter ) {
$adapter->create_server(
'alpha-server',
'alpha',
'mcp',
'Alpha MCP Server',
'Central MCP server for Alpha',
'1.0.0',
array( \SimpleWpMcpAdapterOAuth\OAuthTransport::class ),
null,
null,
array( 'alpha/get-posts' ),
array(),
array()
);
}
);激活后,您的MCP服务器将公开:
- OAuth保护的资源元数据:
/.well-known/oauth-protected-resource - OAuth授权服务器元数据:
/.well-known/oauth-authorization-server - OAuth令牌端点:
/token
所有OAuth端点
假设:
- 命名空间:
{namespace} - MCP路线:
{server_route} - REST前缀:
/wp-json
终点:
GET /wp-json/{namespace}/{server_route}(MCP服务器端点)GET /wp-json/{namespace}/{server_route}/.well-known/oauth-protected-resourceGET /wp-json/{namespace}/{server_route}/.well-known/oauth-authorization-serverGET /wp-json/{namespace}/{server_route}/.well-known/jwks.jsonPOST /wp-json/{namespace}/{server_route}/tokenPOST /wp-json/{namespace}/{server_route}/registerGET /wp-json/{namespace}/{server_route}/register/{client_id}PUT /wp-json/{namespace}/{server_route}/register/{client_id}DELETE /wp-json/{namespace}/{server_route}/register/{client_id}GET|POST /wp-admin/admin-post.php?action=simple_mcp_oauth_authorize
