File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments