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\Client\Exception;
15:
16: use Nexus\Mcp\Core\Exception\McpExceptionInterface;
17:
18: /**
19: * Thrown when an MCP server answers that the token's scopes are insufficient and the client is configured to
20: * report that rather than ask the resource owner for more.
21: *
22: * @see https://datatracker.ietf.org/doc/html/rfc6750#section-3.1
23: */
24: final class InsufficientScopeException extends \RuntimeException implements McpExceptionInterface
25: {
26: /**
27: * @param list<non-empty-string> $required Scopes the challenge named, empty when it named none
28: */
29: public function __construct(public readonly array $required)
30: {
31: parent::__construct([] === $required
32: ? 'The MCP server requires a scope the token does not carry, and named none.'
33: : \sprintf('The MCP server requires the scope "%s", which the token does not carry.', implode(' ', $required)));
34: }
35: }
36: