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\Server\Handler\Request;
15:
16: use Nexus\Mcp\Core\Handler\AbstractContext;
17: use Nexus\Mcp\Core\Handler\RequestHandlerInterface;
18: use Nexus\Mcp\Core\Schema\Enum\CacheScope;
19: use Nexus\Mcp\Core\Schema\Implementation;
20: use Nexus\Mcp\Core\Schema\JsonRpc\JsonRpcRequest;
21: use Nexus\Mcp\Core\Schema\MetaObject\GenericResultMetaObject;
22: use Nexus\Mcp\Core\Schema\MetaObject\ResultMetaObject;
23: use Nexus\Mcp\Core\Schema\ProtocolVersion;
24: use Nexus\Mcp\Core\Schema\Result\DiscoverResult;
25: use Nexus\Mcp\Core\Schema\ServerCapabilities;
26: use Nexus\Mcp\Server\ServerContext;
27:
28: /**
29: * Handles the `server/discover` request.
30: *
31: * @implements RequestHandlerInterface<'server/discover', DiscoverResult, ServerContext>
32: */
33: final readonly class DiscoverRequestHandler implements RequestHandlerInterface
34: {
35: /**
36: * @param null|non-empty-string $instructions
37: */
38: public function __construct(
39: private ServerCapabilities $capabilities,
40: private ?string $instructions = null,
41: private int $ttlMs = 0,
42: private CacheScope $cacheScope = CacheScope::Private,
43: private ResultMetaObject $meta = new GenericResultMetaObject(),
44: private ?Implementation $serverInfo = null,
45: ) {
46: }
47:
48: #[\Override]
49: public function handle(JsonRpcRequest $request, AbstractContext $context): DiscoverResult
50: {
51: return new DiscoverResult(
52: supportedVersions: ProtocolVersion::SUPPORTED_VERSIONS,
53: capabilities: $this->capabilities,
54: ttlMs: $this->ttlMs,
55: cacheScope: $this->cacheScope,
56: instructions: $this->instructions,
57: meta: null === $this->serverInfo
58: ? $this->meta
59: : new GenericResultMetaObject(serverInfo: $this->serverInfo, extras: $this->meta->extras),
60: );
61: }
62: }
63: