| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 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: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | final readonly class DiscoverRequestHandler implements RequestHandlerInterface |
| 35: | { |
| 36: | |
| 37: | |
| 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: | |