| @@ -2,8 +2,11 @@ | ||
| 2 | 2 | declare(strict_types=1); |
| 3 | 3 | |
| 4 | 4 | namespace WPMedia\MCP\OAuth; |
| 5 | 5 | |
| 6 | +use WP\MCP\Infrastructure\Observability\Contracts\McpObservabilityHandlerInterface; | |
| 7 | +use WP\MCP\Infrastructure\Observability\NullMcpObservabilityHandler; | |
| 8 | + | |
| 6 | 9 | class Context { |
| 7 | 10 | /** |
| 8 | 11 | * Determines whether the MCP OAuth server is enabled. |
| 9 | 12 | * |
| @@ -22,6 +25,36 @@ | ||
| 22 | 25 | * |
| 23 | 26 | * @param bool $enabled Whether the MCP OAuth server is enabled. Default true. |
| 24 | 27 | */ |
| 25 | 28 | return wpm_apply_filters_typed( 'boolean', 'wpmedia_mcp_oauth_server_enabled', $enabled ); |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * Observability handler class used by the MCP server. | |
| 33 | + * | |
| 34 | + * Defaults to the mcp-adapter's null handler, so no observability event is | |
| 35 | + * written unless a site opts in. The verbose handler | |
| 36 | + * (`WPMedia\MCP\OAuth\Transport\McpObservabilityHandler`) records one event per | |
| 37 | + * server creation, i.e. once per REST request, which floods debug.log on sites | |
| 38 | + * running with WP_DEBUG and WP_DEBUG_LOG enabled. | |
| 39 | + * | |
| 40 | + * @return class-string<McpObservabilityHandlerInterface> Observability handler class name. | |
| 41 | + */ | |
| 42 | + public function observability_handler(): string { | |
| 43 | + /** | |
| 44 | + * Filters the observability handler class used by the MCP server. | |
| 45 | + * | |
| 46 | + * The value must be a class implementing the mcp-adapter's | |
| 47 | + * McpObservabilityHandlerInterface; any other value is ignored and the | |
| 48 | + * null handler is used instead. | |
| 49 | + * | |
| 50 | + * @param string $handler Observability handler class name. Default NullMcpObservabilityHandler. | |
| 51 | + */ | |
| 52 | + $handler = wpm_apply_filters_typed( 'string', 'wpmedia_mcp_oauth_observability_handler', NullMcpObservabilityHandler::class ); | |
| 53 | + | |
| 54 | + if ( ! is_a( $handler, McpObservabilityHandlerInterface::class, true ) ) { | |
| 55 | + return NullMcpObservabilityHandler::class; | |
| 56 | + } | |
| 57 | + | |
| 58 | + return $handler; | |
| 26 | 59 | } |
| 27 | 60 | } |