11import { z , type ZodRawShape , type ZodNever , AnyZodObject } from "zod" ;
22import 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" ;
44import { Session } from "../session.js" ;
55import logger , { LogId } from "../logger.js" ;
66import { Telemetry } from "../telemetry/telemetry.js" ;
@@ -27,13 +27,17 @@ export abstract class ToolBase {
2727
2828 protected abstract argsShape : ZodRawShape ;
2929
30+ protected abstract annotations : ToolAnnotations ;
31+
3032 protected abstract execute ( ...args : Parameters < ToolCallback < typeof this . argsShape > > ) : Promise < CallToolResult > ;
3133
3234 constructor (
3335 protected readonly session : Session ,
3436 protected readonly config : UserConfig ,
3537 protected readonly telemetry : Telemetry
36- ) { }
38+ ) {
39+ this . updateAnnotations ( ) ;
40+ }
3741
3842 public register ( server : McpServer ) : void {
3943 if ( ! this . verifyAllowed ( ) ) {
@@ -56,7 +60,7 @@ export abstract class ToolBase {
5660 }
5761 } ;
5862
59- server . tool ( this . name , this . description , this . argsShape , callback ) ;
63+ server . tool ( this . name , this . description , this . argsShape , this . annotations , callback ) ;
6064
6165 // This is very similar to RegisteredTool.update, but without the bugs around the name.
6266 // In the upstream update method, the name is captured in the closure and not updated when
@@ -132,6 +136,19 @@ export abstract class ToolBase {
132136 } ;
133137 }
134138
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+
135152 protected abstract resolveTelemetryMetadata (
136153 ...args : Parameters < ToolCallback < typeof this . argsShape > >
137154 ) : TelemetryToolMetadata ;
0 commit comments