1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2025 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\Enum;
15:
16: /**
17: * Standard JSON-RPC error code and SDK error codes.
18: */
19: enum ErrorCode: int
20: {
21: // SDK error codes
22:
23: /**
24: * The connection was closed.
25: */
26: case ConnectionClosed = -32000;
27:
28: /**
29: * The request timed out after a set period.
30: */
31: case RequestTimeout = -32001;
32:
33: /**
34: * The requested resource was not found.
35: */
36: case ResourceNotFound = -32002;
37:
38: // Standard JSON-RPC error codes
39:
40: /**
41: * Invalid JSON was received by the server.
42: * An error occurred on the server while parsing the JSON text.
43: */
44: case ParseError = -32700;
45:
46: /**
47: * The JSON sent is not a valid Request object.
48: */
49: case InvalidRequest = -32600;
50:
51: /**
52: * The method does not exist / is not available.
53: */
54: case MethodNotFound = -32601;
55:
56: /**
57: * Invalid method parameter(s).
58: */
59: case InvalidParams = -32602;
60:
61: /**
62: * Internal JSON-RPC error.
63: */
64: case InternalError = -32603;
65:
66: /**
67: * Get the error message for the error code.
68: *
69: * @return non-empty-string
70: */
71: public function message(): string
72: {
73: return match ($this) {
74: self::ConnectionClosed => 'The connection was closed.',
75: self::RequestTimeout => 'The request timed out.',
76: self::ResourceNotFound => 'The requested resource was not found.',
77: self::ParseError => 'Invalid JSON was received by the server.',
78: self::InvalidRequest => 'The JSON sent is not a valid Request object.',
79: self::MethodNotFound => 'The method does not exist / is not available.',
80: self::InvalidParams => 'Invalid method parameter(s).',
81: self::InternalError => 'Internal error.',
82: };
83: }
84: }
85: