forked from paperclipai/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.ts
More file actions
41 lines (38 loc) · 1.01 KB
/
Copy pathformat.ts
File metadata and controls
41 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { PaperclipApiAuthError, PaperclipApiError } from "./client.js";
type McpTextResponse = {
content: Array<{ type: "text"; text: string }>;
};
export function formatTextResponse(value: unknown): McpTextResponse {
return {
content: [
{
type: "text",
text: typeof value === "string" ? value : JSON.stringify(value, null, 2),
},
],
};
}
export function formatErrorResponse(error: unknown): McpTextResponse {
if (error instanceof PaperclipApiAuthError) {
return formatTextResponse({
error: error.message,
errorClass: "auth_failed",
status: error.status,
method: error.method,
path: error.path,
body: error.body,
});
}
if (error instanceof PaperclipApiError) {
return formatTextResponse({
error: error.message,
status: error.status,
method: error.method,
path: error.path,
body: error.body,
});
}
return formatTextResponse({
error: error instanceof Error ? error.message : String(error),
});
}