|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the official PHP MCP SDK. |
| 5 | + * |
| 6 | + * A collaboration between Symfony and the PHP Foundation. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Mcp\Capability\Registry; |
| 13 | + |
| 14 | +use Mcp\Server\ClientGateway; |
| 15 | +use Mcp\Server\RequestContext; |
| 16 | + |
| 17 | +/** |
| 18 | + * Single source of truth for handler parameter types the SDK injects itself. |
| 19 | + * |
| 20 | + * Both schema generation (which must exclude these parameters from the |
| 21 | + * published inputSchema) and argument preparation (which must inject them) |
| 22 | + * read this list, so the two cannot drift apart. |
| 23 | + * |
| 24 | + * @internal |
| 25 | + */ |
| 26 | +final class InjectableParameters |
| 27 | +{ |
| 28 | + private const TYPES = [ |
| 29 | + RequestContext::class, |
| 30 | + ClientGateway::class, |
| 31 | + ]; |
| 32 | + |
| 33 | + private function __construct() |
| 34 | + { |
| 35 | + } |
| 36 | + |
| 37 | + public static function supports(string $typeName): bool |
| 38 | + { |
| 39 | + foreach (self::TYPES as $type) { |
| 40 | + if (is_a($typeName, $type, true)) { |
| 41 | + return true; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + return false; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param array<string, mixed> $arguments the raw argument bag including the internal "_session" and "_request" entries |
| 50 | + */ |
| 51 | + public static function resolve(string $typeName, array $arguments): ?object |
| 52 | + { |
| 53 | + if (RequestContext::class === $typeName && isset($arguments['_session'], $arguments['_request'])) { |
| 54 | + return new RequestContext($arguments['_session'], $arguments['_request']); |
| 55 | + } |
| 56 | + |
| 57 | + if (ClientGateway::class === $typeName && isset($arguments['_session'])) { |
| 58 | + return new ClientGateway($arguments['_session']); |
| 59 | + } |
| 60 | + |
| 61 | + return null; |
| 62 | + } |
| 63 | +} |
0 commit comments