Skip to content

Commit 6b51594

Browse files
committed
feat: add Base Tool
0 parents  commit 6b51594

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/tools/BaseTool.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {
2+
CallToolRequestSchema,
3+
Tool,
4+
} from "@modelcontextprotocol/sdk/types.js";
5+
import { z } from "zod";
6+
7+
export interface BaseTool {
8+
name: string;
9+
toolDefinition: Tool;
10+
toolCall(request: z.infer<typeof CallToolRequestSchema>): Promise<any>;
11+
}
12+
13+
export abstract class BaseToolImplementation implements BaseTool {
14+
abstract name: string;
15+
abstract toolDefinition: Tool;
16+
abstract toolCall(
17+
request: z.infer<typeof CallToolRequestSchema>
18+
): Promise<any>;
19+
20+
protected createSuccessResponse(data: any) {
21+
return {
22+
content: [{ type: "text", text: JSON.stringify(data) }],
23+
};
24+
}
25+
26+
protected createErrorResponse(error: Error | string) {
27+
const message = error instanceof Error ? error.message : error;
28+
return {
29+
content: [{ type: "error", text: message }],
30+
};
31+
}
32+
}

0 commit comments

Comments
 (0)