1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Core\JsonRpc;
15:
16: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcNotification;
17: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest;
18: use Nexus\Mcp\Core\Schema\Notification\CancelledNotification;
19: use Nexus\Mcp\Core\Schema\Notification\ProgressNotification;
20: use Nexus\Mcp\Core\Schema\Notification\PromptListChangedNotification;
21: use Nexus\Mcp\Core\Schema\Notification\ResourceListChangedNotification;
22: use Nexus\Mcp\Core\Schema\Notification\ResourceUpdatedNotification;
23: use Nexus\Mcp\Core\Schema\Notification\SubscriptionsAcknowledgedNotification;
24: use Nexus\Mcp\Core\Schema\Notification\ToolListChangedNotification;
25: use Nexus\Mcp\Core\Schema\Request\CallToolRequest;
26: use Nexus\Mcp\Core\Schema\Request\CompleteRequest;
27: use Nexus\Mcp\Core\Schema\Request\DiscoverRequest;
28: use Nexus\Mcp\Core\Schema\Request\GetPromptRequest;
29: use Nexus\Mcp\Core\Schema\Request\ListPromptsRequest;
30: use Nexus\Mcp\Core\Schema\Request\ListResourcesRequest;
31: use Nexus\Mcp\Core\Schema\Request\ListResourceTemplatesRequest;
32: use Nexus\Mcp\Core\Schema\Request\ListToolsRequest;
33: use Nexus\Mcp\Core\Schema\Request\ReadResourceRequest;
34: use Nexus\Mcp\Core\Schema\Request\SubscriptionsListenRequest;
35:
36: /**
37: * Spec-default method → class maps consumed by `JsonRpcMessageParser`.
38: */
39: final class JsonRpcMethodRegistry
40: {
41: /**
42: * Keyed by spec method literal (`completion/complete`, etc.), sorted by key.
43: *
44: * @return array<non-empty-string, class-string<JsonRpcRequest<non-empty-string>>>
45: */
46: public static function requests(): array
47: {
48: return [
49: CompleteRequest::getMethod() => CompleteRequest::class,
50: GetPromptRequest::getMethod() => GetPromptRequest::class,
51: ListPromptsRequest::getMethod() => ListPromptsRequest::class,
52: ListResourcesRequest::getMethod() => ListResourcesRequest::class,
53: ReadResourceRequest::getMethod() => ReadResourceRequest::class,
54: ListResourceTemplatesRequest::getMethod() => ListResourceTemplatesRequest::class,
55: DiscoverRequest::getMethod() => DiscoverRequest::class,
56: SubscriptionsListenRequest::getMethod() => SubscriptionsListenRequest::class,
57: CallToolRequest::getMethod() => CallToolRequest::class,
58: ListToolsRequest::getMethod() => ListToolsRequest::class,
59: ];
60: }
61:
62: /**
63: * Keyed by spec method literal (`notifications/cancelled`, etc.), sorted by key.
64: *
65: * @return array<non-empty-string, class-string<JsonRpcNotification<non-empty-string>>>
66: */
67: public static function notifications(): array
68: {
69: return [
70: CancelledNotification::getMethod() => CancelledNotification::class,
71: ProgressNotification::getMethod() => ProgressNotification::class,
72: PromptListChangedNotification::getMethod() => PromptListChangedNotification::class,
73: ResourceListChangedNotification::getMethod() => ResourceListChangedNotification::class,
74: ResourceUpdatedNotification::getMethod() => ResourceUpdatedNotification::class,
75: SubscriptionsAcknowledgedNotification::getMethod() => SubscriptionsAcknowledgedNotification::class,
76: ToolListChangedNotification::getMethod() => ToolListChangedNotification::class,
77: ];
78: }
79: }
80: