@@ -6,132 +6,27 @@ namespace ModelContextProtocol.Protocol.Messages;
66internal static class ErrorCodes
77{
88 /// <summary>
9- /// Invalid JSON was received by the server. This error code (-32700) indicates that
10- /// the JSON syntax itself is malformed and cannot be parsed.
9+ /// Invalid JSON was received by the server.
1110 /// </summary>
12- /// <remarks>
13- /// Use this error code when the request contains invalid JSON that cannot be parsed by
14- /// the JSON parser. This typically happens when there are syntax errors like missing quotes,
15- /// invalid escape sequences, unbalanced brackets, or other JSON syntax violations.
16- /// This is different from InvalidRequest which indicates that the JSON is valid but
17- /// the request structure doesn't conform to the JSON-RPC specification.
18- /// </remarks>
1911 public const int ParseError = - 32700 ;
2012
2113 /// <summary>
22- /// The JSON sent is not a valid Request object. This error code (-32600) indicates that
23- /// the request structure doesn't conform to the JSON-RPC specification requirements.
14+ /// The JSON sent is not a valid Request object.
2415 /// </summary>
25- /// <remarks>
26- /// Use this error code when a request is malformed, such as missing required fields
27- /// (like method or id), containing invalid values, or otherwise not following the
28- /// JSON-RPC protocol structure. This is different from ParseError which indicates
29- /// invalid JSON syntax.
30- /// </remarks>
31- /// <example>
32- /// <code>
33- /// var error = new JsonRpcError
34- /// {
35- /// Id = null, // Often the ID can't be determined from an invalid request
36- /// Error = new JsonRpcErrorDetail
37- /// {
38- /// Code = ErrorCodes.InvalidRequest,
39- /// Message = "The request object is missing required 'method' field",
40- /// Data = JsonNode.Parse(@"{""receivedRequest"": " + JsonSerializer.Serialize(request) + "}")
41- /// }
42- /// };
43- /// </code>
44- /// </example>
4516 public const int InvalidRequest = - 32600 ;
4617
4718 /// <summary>
48- /// The method does not exist or is not available. This error code (-32601) indicates that
49- /// the requested method name in the JSON-RPC request is not recognized by the server.
19+ /// The method does not exist / is not available.
5020 /// </summary>
51- /// <remarks>
52- /// Use this error code when a client requests a method that isn't implemented or available.
53- /// This is a standard JSON-RPC error code that helps clients understand that the method
54- /// they're trying to call doesn't exist, rather than failing for other reasons.
55- /// </remarks>
56- /// <example>
57- /// <code>
58- /// // Example 1: Creating a JSON-RPC error response for a method not found
59- /// var methodNotFoundError = new JsonRpcError
60- /// {
61- /// Id = request.Id,
62- /// Error = new JsonRpcErrorDetail
63- /// {
64- /// Code = ErrorCodes.MethodNotFound,
65- /// Message = $"Method '{request.Method}' not found"
66- /// }
67- /// };
68- ///
69- /// // Example 2: Throwing an exception with this error code
70- /// throw new McpException("The method does not exist or is not available.", ErrorCodes.MethodNotFound);
71- ///
72- /// // Example 3: Handling this specific error in exception handling
73- /// try
74- /// {
75- /// await client.CallToolAsync("nonExistentTool", new { });
76- /// }
77- /// catch (McpException ex)
78- /// {
79- /// if (ex.ErrorCode == ErrorCodes.MethodNotFound)
80- /// {
81- /// // Handle tool not found error specifically
82- /// Console.WriteLine("Tool not found. Available tools: " + string.Join(", ", await client.ListToolsAsync()));
83- /// }
84- /// }
85- /// </code>
86- /// </example>
8721 public const int MethodNotFound = - 32601 ;
8822
8923 /// <summary>
90- /// Invalid method parameter(s). This error code (-32602) indicates that the parameters
91- /// provided in the request are invalid, missing, or of the wrong type.
24+ /// Invalid method parameter(s).
9225 /// </summary>
93- /// <remarks>
94- /// Use this error code when a request contains parameters that don't conform to the
95- /// expected format or when required parameters are missing. This helps clients understand
96- /// exactly what's wrong with their request.
97- /// </remarks>
98- /// <example>
99- /// <code>
100- /// var error = new JsonRpcError
101- /// {
102- /// Id = request.Id,
103- /// Error = new JsonRpcErrorDetail
104- /// {
105- /// Code = ErrorCodes.InvalidParams,
106- /// Message = "Missing required 'location' parameter",
107- /// Data = JsonNode.Parse(@"{""requiredParams"": [""location""]}")
108- /// }
109- /// };
110- /// </code>
111- /// </example>
11226 public const int InvalidParams = - 32602 ;
11327
11428 /// <summary>
115- /// Internal JSON-RPC error. This error code (-32603) indicates that an internal error occurred
116- /// while processing the request that is not covered by more specific error codes.
29+ /// Internal JSON-RPC error.
11730 /// </summary>
118- /// <remarks>
119- /// This is often used as a fallback error code when handling unexpected exceptions
120- /// or when a more specific error code is not available.
121- /// </remarks>
122- /// <example>
123- /// <code>
124- /// var error = new JsonRpcError
125- /// {
126- /// Id = request.Id,
127- /// Error = new JsonRpcErrorDetail
128- /// {
129- /// Code = ErrorCodes.InternalError,
130- /// Message = "An internal error occurred while processing the request",
131- /// Data = JsonNode.Parse($"{{\"errorDetails\": \"{ex.Message}\"}}")
132- /// }
133- /// };
134- /// </code>
135- /// </example>
13631 public const int InternalError = - 32603 ;
13732}
0 commit comments