Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
46c36ce
Refactor Core layer to use WP_Error instead of exceptions
galatanovidiu Oct 20, 2025
7078e08
Refactor Domain layer validators to use WP_Error instead of exceptions
galatanovidiu Oct 20, 2025
c90599c
Refactor registration classes to propagate WP_Error instead of throwi…
galatanovidiu Oct 20, 2025
ff641c4
Add WP_Error handling in Prompts and Resources handlers
galatanovidiu Oct 20, 2025
160bdf5
Fix PHPStan errors by making all get_ability() methods return WP_Error
galatanovidiu Oct 20, 2025
07071bb
Refactor error logging in DefaultServerFactory to use _doing_it_wrong.
galatanovidiu Oct 21, 2025
c641a0b
Remove unused WP_Ability imports from McpPrompt, McpPromptBuilder, an…
galatanovidiu Oct 21, 2025
93ecae6
Update error logging in DefaultServerFactory to ensure error codes ar…
galatanovidiu Oct 21, 2025
fffd11b
Adds unit tests for handlers and component registry
galatanovidiu Oct 21, 2025
1681d29
Fix tool error handling to comply with MCP specification
galatanovidiu Oct 20, 2025
b0a98ee
Fix WP_Error handling in Prompts and Resources handlers (#74)
galatanovidiu Oct 22, 2025
9038f03
Fix permission error tests to align with MCP specification
galatanovidiu Oct 22, 2025
6118da1
Fixed backwards conditional logic in TestCase::set_up_before_class()
galatanovidiu Oct 22, 2025
3f77a62
Merge branch 'trunk' into refactor/24-exception-to-wp-error
galatanovidiu Nov 4, 2025
8d7ce04
Removes a comment
galatanovidiu Nov 4, 2025
9e430fa
Adds assertions for registered abilities
galatanovidiu Nov 4, 2025
75464f1
Guards prompt building against exceptions
galatanovidiu Nov 4, 2025
49b89f4
Adds return type declaration
galatanovidiu Nov 4, 2025
41739fc
Improves developer error handling and testing
galatanovidiu Nov 4, 2025
54ba44b
Improves error handling in prompt builder
galatanovidiu Nov 4, 2025
40fd7f4
Registers abilities during the API init hook
galatanovidiu Nov 4, 2025
95d7ed1
Refactors ability registration in tests
galatanovidiu Nov 5, 2025
6a82e0b
Enhances ability registration tests
galatanovidiu Nov 5, 2025
effdc2e
Enables MCP component validation during registration
galatanovidiu Nov 5, 2025
3d1e4d5
Enhances error handling in MCP component tests
galatanovidiu Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions includes/Core/McpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ public function init(): void {
* @param array $prompts Prompts to register.
* @param callable|null $transport_permission_callback Optional custom permission callback for transport-level authentication. If null, defaults to is_user_logged_in().
*
* @return \WP\MCP\Core\McpAdapter
* @throws \Exception If the server already exists or if called outside of the mcp_adapter_init action.
* @return \WP\MCP\Core\McpAdapter|\WP_Error McpAdapter instance on success, WP_Error on failure.
*/
public function create_server( string $server_id, string $server_route_namespace, string $server_route, string $server_name, string $server_description, string $server_version, array $mcp_transports, ?string $error_handler, ?string $observability_handler = null, array $tools = array(), array $resources = array(), array $prompts = array(), ?callable $transport_permission_callback = null ): self {
public function create_server( string $server_id, string $server_route_namespace, string $server_route, string $server_name, string $server_description, string $server_version, array $mcp_transports, ?string $error_handler, ?string $observability_handler = null, array $tools = array(), array $resources = array(), array $prompts = array(), ?callable $transport_permission_callback = null ) {
// Use NullMcpErrorHandler if no error handler is provided.
if ( ! $error_handler ) {
$error_handler = NullMcpErrorHandler::class;
}

// Validate error handler class exists and implements McpErrorHandlerInterface.
if ( ! class_exists( $error_handler ) ) {
throw new \Exception(
return new \WP_Error(
'invalid_error_handler',
sprintf(
/* translators: %s: error handler class name */
esc_html__( 'Error handler class "%s" does not exist.', 'mcp-adapter' ),
Expand All @@ -123,7 +123,8 @@ public function create_server( string $server_id, string $server_route_namespace
}

if ( ! in_array( McpErrorHandlerInterface::class, class_implements( $error_handler ) ?: array(), true ) ) {
throw new \Exception(
return new \WP_Error(
'invalid_error_handler',
sprintf(
/* translators: %s: error handler class name */
esc_html__( 'Error handler class "%s" must implement the McpErrorHandlerInterface.', 'mcp-adapter' ),
Expand All @@ -139,7 +140,8 @@ public function create_server( string $server_id, string $server_route_namespace

// Validate observability handler class exists and implements McpObservabilityHandlerInterface.
if ( ! class_exists( $observability_handler ) ) {
throw new \Exception(
return new \WP_Error(
'invalid_observability_handler',
sprintf(
/* translators: %s: observability handler class name */
esc_html__( 'Observability handler class "%s" does not exist.', 'mcp-adapter' ),
Expand All @@ -149,7 +151,8 @@ public function create_server( string $server_id, string $server_route_namespace
}

if ( ! in_array( McpObservabilityHandlerInterface::class, class_implements( $observability_handler ) ?: array(), true ) ) {
throw new \Exception(
return new \WP_Error(
'invalid_observability_handler',
sprintf(
/* translators: %s: observability handler class name */
esc_html__( 'Observability handler class "%s" must implement the McpObservabilityHandlerInterface interface.', 'mcp-adapter' ),
Expand All @@ -164,7 +167,8 @@ public function create_server( string $server_id, string $server_route_namespace
esc_html__( 'MCP Servers must be created during the "mcp_adapter_init" action. Hook into "mcp_adapter_init" to register your server.', 'mcp-adapter' ),
'0.1.0'
);
throw new \Exception(
return new \WP_Error(
'invalid_timing',
esc_html__( 'MCP Server creation must be done during mcp_adapter_init action.', 'mcp-adapter' )
);
}
Expand All @@ -179,8 +183,9 @@ public function create_server( string $server_id, string $server_route_namespace
),
'0.1.0'
);
throw new \Exception(
// translators: %s: server ID.
return new \WP_Error(
'duplicate_server_id',
// translators: %s: server ID.
sprintf( esc_html__( 'Server with ID "%s" already exists.', 'mcp-adapter' ), esc_html( $server_id ) )
);
}
Expand Down
Loading