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, advertising the server's supported
30: * protocol versions, capabilities, and full identity.
31: *
32: * @implements RequestHandlerInterface<'server/discover', DiscoverResult, ServerContext>
33: */
34: final readonly class DiscoverRequestHandler implements RequestHandlerInterface
35: {
36: /**
37: * @param null|non-empty-string $instructions
38: */
39: public function __construct(
40: private ServerCapabilities $capabilities,
41: private ?string $instructions = null,
42: private int $ttlMs = 0,
43: private CacheScope $cacheScope = CacheScope::Private,
44: private ResultMetaObject $meta = new GenericResultMetaObject(),
45: private ?Implementation $serverInfo = null,
46: ) {
47: }
48:
49: #[\Override]
50: public function handle(JsonRpcRequest $request, AbstractContext $context): DiscoverResult
51: {
52: return new DiscoverResult(
53: supportedVersions: ProtocolVersion::SUPPORTED_VERSIONS,
54: capabilities: $this->capabilities,
55: ttlMs: $this->ttlMs,
56: cacheScope: $this->cacheScope,
57: instructions: $this->instructions,
58: meta: null === $this->serverInfo
59: ? $this->meta
60: : new GenericResultMetaObject(serverInfo: $this->serverInfo, extras: $this->meta->extras),
61: );
62: }
63: }
64: