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

@ -108,7 +108,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
};
}
throw new McpProtocolException($"Resource not found: {request.Params?.Uri}");
throw new McpProtocolException($"Resource not found: {request.Params?.Uri}", McpErrorCode.ResourceNotFound);
})
.WithResources<SimpleResources>();
}
@ -249,6 +249,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
cancellationToken: TestContext.Current.CancellationToken));
Assert.Contains("Resource not found", e.Message);
Assert.Equal(McpErrorCode.ResourceNotFound, e.ErrorCode);
}
[Fact]

View file

@ -36,7 +36,7 @@ public sealed class McpServerResourceRoutingTests(ITestOutputHelper testOutputHe
Assert.Equal("params: a, b, c", ((TextResourceContents)paramsResult.Contents[0]).Text);
var mcpEx = await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ReadResourceAsync("test://params{?a1,a2,a3}", null, TestContext.Current.CancellationToken));
Assert.Equal(McpErrorCode.InvalidParams, mcpEx.ErrorCode);
Assert.Equal(McpErrorCode.ResourceNotFound, mcpEx.ErrorCode);
Assert.Equal("Request failed (remote): Unknown resource URI: 'test://params{?a1,a2,a3}'", mcpEx.Message);
}
}