Skip to content

Commit fd8e48a

Browse files
committed
Add a specific "resource not found" error with optional URI data
This mirrors the MCP resource not found error. Signed-off-by: Ben Brandt <benjamin.j.brandt@gmail.com>
1 parent 5d5fbda commit fd8e48a

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

rust/error.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ impl Error {
9494
Error::new(ErrorCode::AUTH_REQUIRED)
9595
}
9696

97+
/// A given resource, such as a file, was not found.
98+
#[must_use]
99+
pub fn resource_not_found(uri: Option<&str>) -> Self {
100+
let err = Error::new(ErrorCode::RESOURCE_NOT_FOUND);
101+
if let Some(uri) = uri {
102+
err.with_data(serde_json::json!({ "uri": uri }))
103+
} else {
104+
err
105+
}
106+
}
107+
97108
/// Converts a standard error into an internal JSON-RPC error.
98109
///
99110
/// The error's string representation is included as additional data.
@@ -153,6 +164,13 @@ impl ErrorCode {
153164
code: -32000,
154165
message: "Authentication required",
155166
};
167+
168+
/// A given resource, such as a file, was not found.
169+
/// This is an ACP-specific error code in the reserved range.
170+
pub const RESOURCE_NOT_FOUND: ErrorCode = ErrorCode {
171+
code: -32002,
172+
message: "Resource not found",
173+
};
156174
}
157175

158176
impl From<ErrorCode> for (i32, String) {

typescript/acp.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,13 @@ export class RequestError extends Error {
963963
return new RequestError(-32000, "Authentication required", data);
964964
}
965965

966+
/**
967+
* Resource, such as a file, was not found
968+
*/
969+
static resourceNotFound(uri?: string): RequestError {
970+
return new RequestError(-32002, "Resource not found", uri && { uri });
971+
}
972+
966973
toResult<T>(): Result<T> {
967974
return {
968975
error: {

0 commit comments

Comments
 (0)