Add ResourceNotFound error code (-32002) (#1062)

This commit is contained in:
Copilot 2025-12-05 10:39:30 -08:00 • committed by GitHub
commit d76bc16bd1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 26 deletions

View file

@ -6,12 +6,29 @@ namespace ModelContextProtocol;
public enum McpErrorCode
{
/// <summary>
/// Indicates that the JSON received could not be parsed.
/// Indicates that the requested resource could not be found.
/// </summary>
/// <remarks>
/// This error occurs when the input contains malformed JSON or incorrect syntax.
/// This error should be used when a resource URI does not match any available resource on the server.
/// It allows clients to distinguish between missing resources and other types of errors.
/// </remarks>
ParseError = -32700,
ResourceNotFound = -32002,
/// <summary>
/// Indicates that URL-mode elicitation is required to complete the requested operation.
/// </summary>
/// <remarks>
/// <para>
/// This error is returned when a server operation requires additional user input through URL-mode elicitation
/// before it can proceed. The error data must include the `data.elicitations` payload describing the pending
/// elicitation(s) for the client to present to the user.
/// </para>
/// <para>
/// Common scenarios include OAuth authorization and other out-of-band flows that cannot be completed inside
/// the MCP client.
/// </para>
/// </remarks>
UrlElicitationRequired = -32042,
/// <summary>
/// Indicates that the JSON payload does not conform to the expected Request object structure.
@ -58,18 +75,10 @@ public enum McpErrorCode
InternalError = -32603,
/// <summary>
/// Indicates that URL-mode elicitation is required to complete the requested operation.
/// Indicates that the JSON received could not be parsed.
/// </summary>
/// <remarks>
/// <para>
/// This error is returned when a server operation requires additional user input through URL-mode elicitation
/// before it can proceed. The error data must include the `data.elicitations` payload describing the pending
/// elicitation(s) for the client to present to the user.
/// </para>
/// <para>
/// Common scenarios include OAuth authorization and other out-of-band flows that cannot be completed inside
/// the MCP client.
/// </para>
/// This error occurs when the input contains malformed JSON or incorrect syntax.
/// </remarks>
UrlElicitationRequired = -32042,
ParseError = -32700,
}

View file

@ -273,7 +273,7 @@ internal sealed partial class McpServerImpl : McpServer
listResourcesHandler ??= (static async (_, __) => new ListResourcesResult());
listResourceTemplatesHandler ??= (static async (_, __) => new ListResourceTemplatesResult());
readResourceHandler ??= (static async (request, _) => throw new McpProtocolException($"Unknown resource URI: '{request.Params?.Uri}'", McpErrorCode.InvalidParams));
readResourceHandler ??= (static async (request, _) => throw new McpProtocolException($"Unknown resource URI: '{request.Params?.Uri}'", McpErrorCode.ResourceNotFound));
subscribeHandler ??= (static async (_, __) => new EmptyResult());
unsubscribeHandler ??= (static async (_, __) => new EmptyResult());
var listChanged = resourcesCapability?.ListChanged;