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\Exception;
15:
16: use Nexus\Mcp\Core\Exception\AbstractJsonRpcProtocolException;
17: use Nexus\Mcp\Core\Schema\Enum\ProtocolErrorCode;
18: use Nexus\Mcp\Core\Schema\RequestId;
19:
20: /**
21: * Thrown when a `subscriptions/listen` asks for more than one of the store's budgets allows.
22: */
23: final class SubscriptionLimitReachedException extends AbstractJsonRpcProtocolException
24: {
25: /**
26: * @param bool $perPeer Whether the per-peer budget refused the stream, rather than the server-wide one
27: * @param bool $perStream Whether the stream named more resource URIs than one may watch
28: */
29: public function __construct(
30: public readonly int $limit,
31: ?RequestId $requestId = null,
32: ?\Throwable $previous = null,
33: bool $perPeer = false,
34: bool $perStream = false,
35: ) {
36: parent::__construct(
37: $requestId,
38: $perStream
39: ? \sprintf('Subscription limit reached: this server watches at most %d resource URIs per stream.', $limit)
40: : \sprintf(
41: 'Subscription limit reached: this server holds at most %d open streams%s.',
42: $limit,
43: $perPeer ? ' per client' : '',
44: ),
45: $previous,
46: errorData: ['limit' => $limit],
47: );
48: }
49:
50: #[\Override]
51: public static function getErrorCode(): ProtocolErrorCode
52: {
53: return ProtocolErrorCode::InternalError;
54: }
55: }
56: