1
1
import { z , type ZodRawShape , type ZodNever , AnyZodObject } from "zod" ;
2
2
import type { McpServer , RegisteredTool , ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js" ;
3
- import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
3
+ import { ToolAnnotationsSchema , type CallToolResult , type ToolAnnotations } from "@modelcontextprotocol/sdk/types.js" ;
4
4
import { Session } from "../session.js" ;
5
5
import logger , { LogId } from "../logger.js" ;
6
6
import { Telemetry } from "../telemetry/telemetry.js" ;
@@ -27,13 +27,17 @@ export abstract class ToolBase {
27
27
28
28
protected abstract argsShape : ZodRawShape ;
29
29
30
+ protected abstract annotations : ToolAnnotations ;
31
+
30
32
protected abstract execute ( ...args : Parameters < ToolCallback < typeof this . argsShape > > ) : Promise < CallToolResult > ;
31
33
32
34
constructor (
33
35
protected readonly session : Session ,
34
36
protected readonly config : UserConfig ,
35
37
protected readonly telemetry : Telemetry
36
- ) { }
38
+ ) {
39
+ this . updateAnnotations ( ) ;
40
+ }
37
41
38
42
public register ( server : McpServer ) : void {
39
43
if ( ! this . verifyAllowed ( ) ) {
@@ -56,7 +60,7 @@ export abstract class ToolBase {
56
60
}
57
61
} ;
58
62
59
- server . tool ( this . name , this . description , this . argsShape , callback ) ;
63
+ server . tool ( this . name , this . description , this . argsShape , this . annotations , callback ) ;
60
64
61
65
// This is very similar to RegisteredTool.update, but without the bugs around the name.
62
66
// In the upstream update method, the name is captured in the closure and not updated when
@@ -132,6 +136,19 @@ export abstract class ToolBase {
132
136
} ;
133
137
}
134
138
139
+ protected updateAnnotations ( ) {
140
+ this . annotations : ToolAnnotationsSchema = {
141
+ description : this . description ,
142
+ } ;
143
+ if ( this . operationType === "read" ) {
144
+ this . annotations . readOnlyHint = true ;
145
+ }
146
+
147
+ if ( this . operationType == "delete" ) {
148
+ this . annotations . destructiveHint = true ;
149
+ }
150
+ }
151
+
135
152
protected abstract resolveTelemetryMetadata (
136
153
...args : Parameters < ToolCallback < typeof this . argsShape > >
137
154
) : TelemetryToolMetadata ;
0 commit comments