-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathresult.ts
More file actions
40 lines (35 loc) · 1.08 KB
/
Copy pathresult.ts
File metadata and controls
40 lines (35 loc) · 1.08 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
/**
* Helpers for building MCP tool results.
*
* Tools return BOTH a human-readable text block and structuredContent (PRD §11).
* Errors return actionable messages with isError:true so the agent can recover
* (PRD §11: "guide the agent to a fix").
*/
export interface ToolTextContent {
type: "text";
text: string;
}
export interface ToolResult {
// Index signature required for assignability to the SDK's CallToolResult type.
[key: string]: unknown;
content: ToolTextContent[];
structuredContent?: Record<string, unknown>;
isError?: boolean;
}
export function ok(text: string, structured: Record<string, unknown>): ToolResult {
return {
content: [{ type: "text", text }],
structuredContent: structured,
};
}
export function fail(text: string): ToolResult {
return {
content: [{ type: "text", text }],
isError: true,
};
}
/** Wrap an unknown thrown value into an actionable error message. */
export function describeError(prefix: string, err: unknown): string {
const msg = err instanceof Error ? err.message : String(err);
return `${prefix}: ${msg}`;
}