Files
WP-LIT-MCP/src/Admin/SiteHealth.php
T

64 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace LIT\MCP\Admin;
/**
* Site Health test for our MCP endpoint (401 + WWW-Authenticate without a token).
* The discovery documents are covered by mcp-oauth's own Site Health test.
*/
final class SiteHealth
{
public const TEST = 'lit_mcp_endpoint';
public function __construct(private ConnectionStatus $status)
{
}
public function register(): void
{
add_filter('site_status_tests', [$this, 'addTest']);
}
public function addTest(mixed $tests): mixed
{
if (! is_array($tests)) {
return $tests;
}
$tests['direct'][self::TEST] = [
'label' => __('LIT MCP Endpunkt', 'wp-lit-mcp'),
'test' => [$this, 'run'],
];
return $tests;
}
/** @return array<string, mixed> */
public function run(): array
{
$oauth = $this->status->oauthEnabled();
$endpoint = $oauth ? $this->status->endpoint(true) : null;
$good = $oauth && ($endpoint['ok'] ?? false) === true;
$detail = $oauth
? (string) ($endpoint['message'] ?? '')
: __('Der OAuth-Server ist deaktiviert (Filter wpmedia_mcp_oauth_server_enabled).', 'wp-lit-mcp');
return [
'label' => $good
? __('Der LIT-MCP-Endpunkt ist erreichbar und verlangt OAuth', 'wp-lit-mcp')
: __('Der LIT-MCP-Endpunkt ist nicht nutzbar', 'wp-lit-mcp'),
'status' => $good ? 'good' : 'critical',
'badge' => ['label' => 'LIT MCP', 'color' => $good ? 'blue' : 'red'],
'description' => '<p>' . esc_html($detail) . '</p>',
'actions' => sprintf(
'<a href="%s">%s</a>',
esc_url(SettingsPage::url('verbindung')),
esc_html__('Einstellungen → LIT MCP', 'wp-lit-mcp')
),
'test' => self::TEST,
];
}
}