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;
22: use Nexus\Mcp\Core\Schema\ProtocolVersion;
23: use Nexus\Mcp\Core\Schema\Result\DiscoverResult;
24: use Nexus\Mcp\Core\Schema\ServerCapabilities;
25: use Nexus\Mcp\Server\ServerContext;
26:
27: /**
28: * Handles the `server/discover` request, advertising the server's supported
29: * protocol versions, capabilities, and identification info.
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 Implementation $serverInfo,
40: private ServerCapabilities $capabilities,
41: private ?string $instructions = null,
42: private int $ttlMs = 0,
43: private CacheScope $cacheScope = CacheScope::Private,
44: private MetaObject $meta = new MetaObject(),
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: serverInfo: $this->serverInfo,
55: ttlMs: $this->ttlMs,
56: cacheScope: $this->cacheScope,
57: instructions: $this->instructions,
58: meta: $this->meta,
59: );
60: }
61: }
62: