| 1 |
<?php |
| 2 |
declare( strict_types=1 ); |
| 3 |
|
| 4 |
namespace WPMedia\MCP\OAuth\Transport; |
| 5 |
|
| 6 |
use WP\MCP\Core\McpAdapter; |
| 7 |
use WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler; |
| 8 |
use WPMedia\MCP\OAuth\Context; |
| 9 |
|
| 10 |
class Server { |
| 11 |
/** |
| 12 |
* OAuth server context. |
| 13 |
* |
| 14 |
* @var Context |
| 15 |
*/ |
| 16 |
private $context; |
| 17 |
|
| 18 |
/** |
| 19 |
* Constructor. |
| 20 |
* |
| 21 |
* @param Context $context OAuth server context. |
| 22 |
*/ |
| 23 |
public function __construct( Context $context ) { |
| 24 |
$this->context = $context; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Register the MCP server with the adapter. |
| 29 |
* |
| 30 |
* Creates an isolated server at /wp-json/mcp/mcp-oauth-server using the custom |
| 31 |
* OAuthHttpTransport for JWT Bearer authentication. |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public function register_server(): void { |
| 36 |
if ( ! class_exists( McpAdapter::class ) ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
$adapter = McpAdapter::instance(); |
| 41 |
|
| 42 |
$adapter->create_server( |
| 43 |
'mcp-oauth-server', |
| 44 |
'mcp', |
| 45 |
'mcp-oauth-server', |
| 46 |
'MCP OAuth Server', |
| 47 |
'MCP Server with OAuth 2.1 authentication', |
| 48 |
'v1.0.0', |
| 49 |
[ OAuthHttpTransport::class ], |
| 50 |
ErrorLogMcpErrorHandler::class, |
| 51 |
$this->context->observability_handler(), |
| 52 |
[ |
| 53 |
'mcp-adapter/discover-abilities', |
| 54 |
'mcp-adapter/get-ability-info', |
| 55 |
'mcp-adapter/execute-ability', |
| 56 |
] |
| 57 |
); |
| 58 |
} |
| 59 |
} |
| 60 |
|