hooks.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. // Code generated by `go generate`. DO NOT EDIT.
  2. // source: server/internal/gen/hooks.go.tmpl
  3. package server
  4. import (
  5. "context"
  6. "github.com/mark3labs/mcp-go/mcp"
  7. )
  8. // OnRegisterSessionHookFunc is a hook that will be called when a new session is registered.
  9. type OnRegisterSessionHookFunc func(ctx context.Context, session ClientSession)
  10. // OnUnregisterSessionHookFunc is a hook that will be called when a session is being unregistered.
  11. type OnUnregisterSessionHookFunc func(ctx context.Context, session ClientSession)
  12. // BeforeAnyHookFunc is a function that is called after the request is
  13. // parsed but before the method is called.
  14. type BeforeAnyHookFunc func(ctx context.Context, id any, method mcp.MCPMethod, message any)
  15. // OnSuccessHookFunc is a hook that will be called after the request
  16. // successfully generates a result, but before the result is sent to the client.
  17. type OnSuccessHookFunc func(ctx context.Context, id any, method mcp.MCPMethod, message any, result any)
  18. // OnErrorHookFunc is a hook that will be called when an error occurs,
  19. // either during the request parsing or the method execution.
  20. //
  21. // Example usage:
  22. // ```
  23. //
  24. // hooks.AddOnError(func(ctx context.Context, id any, method mcp.MCPMethod, message any, err error) {
  25. // // Check for specific error types using errors.Is
  26. // if errors.Is(err, ErrUnsupported) {
  27. // // Handle capability not supported errors
  28. // log.Printf("Capability not supported: %v", err)
  29. // }
  30. //
  31. // // Use errors.As to get specific error types
  32. // var parseErr = &UnparsableMessageError{}
  33. // if errors.As(err, &parseErr) {
  34. // // Access specific methods/fields of the error type
  35. // log.Printf("Failed to parse message for method %s: %v",
  36. // parseErr.GetMethod(), parseErr.Unwrap())
  37. // // Access the raw message that failed to parse
  38. // rawMsg := parseErr.GetMessage()
  39. // }
  40. //
  41. // // Check for specific resource/prompt/tool errors
  42. // switch {
  43. // case errors.Is(err, ErrResourceNotFound):
  44. // log.Printf("Resource not found: %v", err)
  45. // case errors.Is(err, ErrPromptNotFound):
  46. // log.Printf("Prompt not found: %v", err)
  47. // case errors.Is(err, ErrToolNotFound):
  48. // log.Printf("Tool not found: %v", err)
  49. // }
  50. // })
  51. type OnErrorHookFunc func(ctx context.Context, id any, method mcp.MCPMethod, message any, err error)
  52. // OnRequestInitializationFunc is a function that called before handle diff request method
  53. // Should any errors arise during func execution, the service will promptly return the corresponding error message.
  54. type OnRequestInitializationFunc func(ctx context.Context, id any, message any) error
  55. type OnBeforeInitializeFunc func(ctx context.Context, id any, message *mcp.InitializeRequest)
  56. type OnAfterInitializeFunc func(ctx context.Context, id any, message *mcp.InitializeRequest, result *mcp.InitializeResult)
  57. type OnBeforePingFunc func(ctx context.Context, id any, message *mcp.PingRequest)
  58. type OnAfterPingFunc func(ctx context.Context, id any, message *mcp.PingRequest, result *mcp.EmptyResult)
  59. type OnBeforeSetLevelFunc func(ctx context.Context, id any, message *mcp.SetLevelRequest)
  60. type OnAfterSetLevelFunc func(ctx context.Context, id any, message *mcp.SetLevelRequest, result *mcp.EmptyResult)
  61. type OnBeforeListResourcesFunc func(ctx context.Context, id any, message *mcp.ListResourcesRequest)
  62. type OnAfterListResourcesFunc func(ctx context.Context, id any, message *mcp.ListResourcesRequest, result *mcp.ListResourcesResult)
  63. type OnBeforeListResourceTemplatesFunc func(ctx context.Context, id any, message *mcp.ListResourceTemplatesRequest)
  64. type OnAfterListResourceTemplatesFunc func(ctx context.Context, id any, message *mcp.ListResourceTemplatesRequest, result *mcp.ListResourceTemplatesResult)
  65. type OnBeforeReadResourceFunc func(ctx context.Context, id any, message *mcp.ReadResourceRequest)
  66. type OnAfterReadResourceFunc func(ctx context.Context, id any, message *mcp.ReadResourceRequest, result *mcp.ReadResourceResult)
  67. type OnBeforeListPromptsFunc func(ctx context.Context, id any, message *mcp.ListPromptsRequest)
  68. type OnAfterListPromptsFunc func(ctx context.Context, id any, message *mcp.ListPromptsRequest, result *mcp.ListPromptsResult)
  69. type OnBeforeGetPromptFunc func(ctx context.Context, id any, message *mcp.GetPromptRequest)
  70. type OnAfterGetPromptFunc func(ctx context.Context, id any, message *mcp.GetPromptRequest, result *mcp.GetPromptResult)
  71. type OnBeforeListToolsFunc func(ctx context.Context, id any, message *mcp.ListToolsRequest)
  72. type OnAfterListToolsFunc func(ctx context.Context, id any, message *mcp.ListToolsRequest, result *mcp.ListToolsResult)
  73. type OnBeforeCallToolFunc func(ctx context.Context, id any, message *mcp.CallToolRequest)
  74. type OnAfterCallToolFunc func(ctx context.Context, id any, message *mcp.CallToolRequest, result *mcp.CallToolResult)
  75. type Hooks struct {
  76. OnRegisterSession []OnRegisterSessionHookFunc
  77. OnUnregisterSession []OnUnregisterSessionHookFunc
  78. OnBeforeAny []BeforeAnyHookFunc
  79. OnSuccess []OnSuccessHookFunc
  80. OnError []OnErrorHookFunc
  81. OnRequestInitialization []OnRequestInitializationFunc
  82. OnBeforeInitialize []OnBeforeInitializeFunc
  83. OnAfterInitialize []OnAfterInitializeFunc
  84. OnBeforePing []OnBeforePingFunc
  85. OnAfterPing []OnAfterPingFunc
  86. OnBeforeSetLevel []OnBeforeSetLevelFunc
  87. OnAfterSetLevel []OnAfterSetLevelFunc
  88. OnBeforeListResources []OnBeforeListResourcesFunc
  89. OnAfterListResources []OnAfterListResourcesFunc
  90. OnBeforeListResourceTemplates []OnBeforeListResourceTemplatesFunc
  91. OnAfterListResourceTemplates []OnAfterListResourceTemplatesFunc
  92. OnBeforeReadResource []OnBeforeReadResourceFunc
  93. OnAfterReadResource []OnAfterReadResourceFunc
  94. OnBeforeListPrompts []OnBeforeListPromptsFunc
  95. OnAfterListPrompts []OnAfterListPromptsFunc
  96. OnBeforeGetPrompt []OnBeforeGetPromptFunc
  97. OnAfterGetPrompt []OnAfterGetPromptFunc
  98. OnBeforeListTools []OnBeforeListToolsFunc
  99. OnAfterListTools []OnAfterListToolsFunc
  100. OnBeforeCallTool []OnBeforeCallToolFunc
  101. OnAfterCallTool []OnAfterCallToolFunc
  102. }
  103. func (c *Hooks) AddBeforeAny(hook BeforeAnyHookFunc) {
  104. c.OnBeforeAny = append(c.OnBeforeAny, hook)
  105. }
  106. func (c *Hooks) AddOnSuccess(hook OnSuccessHookFunc) {
  107. c.OnSuccess = append(c.OnSuccess, hook)
  108. }
  109. // AddOnError registers a hook function that will be called when an error occurs.
  110. // The error parameter contains the actual error object, which can be interrogated
  111. // using Go's error handling patterns like errors.Is and errors.As.
  112. //
  113. // Example:
  114. // ```
  115. // // Create a channel to receive errors for testing
  116. // errChan := make(chan error, 1)
  117. //
  118. // // Register hook to capture and inspect errors
  119. // hooks := &Hooks{}
  120. //
  121. // hooks.AddOnError(func(ctx context.Context, id any, method mcp.MCPMethod, message any, err error) {
  122. // // For capability-related errors
  123. // if errors.Is(err, ErrUnsupported) {
  124. // // Handle capability not supported
  125. // errChan <- err
  126. // return
  127. // }
  128. //
  129. // // For parsing errors
  130. // var parseErr = &UnparsableMessageError{}
  131. // if errors.As(err, &parseErr) {
  132. // // Handle unparsable message errors
  133. // fmt.Printf("Failed to parse %s request: %v\n",
  134. // parseErr.GetMethod(), parseErr.Unwrap())
  135. // errChan <- parseErr
  136. // return
  137. // }
  138. //
  139. // // For resource/prompt/tool not found errors
  140. // if errors.Is(err, ErrResourceNotFound) ||
  141. // errors.Is(err, ErrPromptNotFound) ||
  142. // errors.Is(err, ErrToolNotFound) {
  143. // // Handle not found errors
  144. // errChan <- err
  145. // return
  146. // }
  147. //
  148. // // For other errors
  149. // errChan <- err
  150. // })
  151. //
  152. // server := NewMCPServer("test-server", "1.0.0", WithHooks(hooks))
  153. // ```
  154. func (c *Hooks) AddOnError(hook OnErrorHookFunc) {
  155. c.OnError = append(c.OnError, hook)
  156. }
  157. func (c *Hooks) beforeAny(ctx context.Context, id any, method mcp.MCPMethod, message any) {
  158. if c == nil {
  159. return
  160. }
  161. for _, hook := range c.OnBeforeAny {
  162. hook(ctx, id, method, message)
  163. }
  164. }
  165. func (c *Hooks) onSuccess(ctx context.Context, id any, method mcp.MCPMethod, message any, result any) {
  166. if c == nil {
  167. return
  168. }
  169. for _, hook := range c.OnSuccess {
  170. hook(ctx, id, method, message, result)
  171. }
  172. }
  173. // onError calls all registered error hooks with the error object.
  174. // The err parameter contains the actual error that occurred, which implements
  175. // the standard error interface and may be a wrapped error or custom error type.
  176. //
  177. // This allows consumer code to use Go's error handling patterns:
  178. // - errors.Is(err, ErrUnsupported) to check for specific sentinel errors
  179. // - errors.As(err, &customErr) to extract custom error types
  180. //
  181. // Common error types include:
  182. // - ErrUnsupported: When a capability is not enabled
  183. // - UnparsableMessageError: When request parsing fails
  184. // - ErrResourceNotFound: When a resource is not found
  185. // - ErrPromptNotFound: When a prompt is not found
  186. // - ErrToolNotFound: When a tool is not found
  187. func (c *Hooks) onError(ctx context.Context, id any, method mcp.MCPMethod, message any, err error) {
  188. if c == nil {
  189. return
  190. }
  191. for _, hook := range c.OnError {
  192. hook(ctx, id, method, message, err)
  193. }
  194. }
  195. func (c *Hooks) AddOnRegisterSession(hook OnRegisterSessionHookFunc) {
  196. c.OnRegisterSession = append(c.OnRegisterSession, hook)
  197. }
  198. func (c *Hooks) RegisterSession(ctx context.Context, session ClientSession) {
  199. if c == nil {
  200. return
  201. }
  202. for _, hook := range c.OnRegisterSession {
  203. hook(ctx, session)
  204. }
  205. }
  206. func (c *Hooks) AddOnUnregisterSession(hook OnUnregisterSessionHookFunc) {
  207. c.OnUnregisterSession = append(c.OnUnregisterSession, hook)
  208. }
  209. func (c *Hooks) UnregisterSession(ctx context.Context, session ClientSession) {
  210. if c == nil {
  211. return
  212. }
  213. for _, hook := range c.OnUnregisterSession {
  214. hook(ctx, session)
  215. }
  216. }
  217. func (c *Hooks) AddOnRequestInitialization(hook OnRequestInitializationFunc) {
  218. c.OnRequestInitialization = append(c.OnRequestInitialization, hook)
  219. }
  220. func (c *Hooks) onRequestInitialization(ctx context.Context, id any, message any) error {
  221. if c == nil {
  222. return nil
  223. }
  224. for _, hook := range c.OnRequestInitialization {
  225. err := hook(ctx, id, message)
  226. if err != nil {
  227. return err
  228. }
  229. }
  230. return nil
  231. }
  232. func (c *Hooks) AddBeforeInitialize(hook OnBeforeInitializeFunc) {
  233. c.OnBeforeInitialize = append(c.OnBeforeInitialize, hook)
  234. }
  235. func (c *Hooks) AddAfterInitialize(hook OnAfterInitializeFunc) {
  236. c.OnAfterInitialize = append(c.OnAfterInitialize, hook)
  237. }
  238. func (c *Hooks) beforeInitialize(ctx context.Context, id any, message *mcp.InitializeRequest) {
  239. c.beforeAny(ctx, id, mcp.MethodInitialize, message)
  240. if c == nil {
  241. return
  242. }
  243. for _, hook := range c.OnBeforeInitialize {
  244. hook(ctx, id, message)
  245. }
  246. }
  247. func (c *Hooks) afterInitialize(ctx context.Context, id any, message *mcp.InitializeRequest, result *mcp.InitializeResult) {
  248. c.onSuccess(ctx, id, mcp.MethodInitialize, message, result)
  249. if c == nil {
  250. return
  251. }
  252. for _, hook := range c.OnAfterInitialize {
  253. hook(ctx, id, message, result)
  254. }
  255. }
  256. func (c *Hooks) AddBeforePing(hook OnBeforePingFunc) {
  257. c.OnBeforePing = append(c.OnBeforePing, hook)
  258. }
  259. func (c *Hooks) AddAfterPing(hook OnAfterPingFunc) {
  260. c.OnAfterPing = append(c.OnAfterPing, hook)
  261. }
  262. func (c *Hooks) beforePing(ctx context.Context, id any, message *mcp.PingRequest) {
  263. c.beforeAny(ctx, id, mcp.MethodPing, message)
  264. if c == nil {
  265. return
  266. }
  267. for _, hook := range c.OnBeforePing {
  268. hook(ctx, id, message)
  269. }
  270. }
  271. func (c *Hooks) afterPing(ctx context.Context, id any, message *mcp.PingRequest, result *mcp.EmptyResult) {
  272. c.onSuccess(ctx, id, mcp.MethodPing, message, result)
  273. if c == nil {
  274. return
  275. }
  276. for _, hook := range c.OnAfterPing {
  277. hook(ctx, id, message, result)
  278. }
  279. }
  280. func (c *Hooks) AddBeforeSetLevel(hook OnBeforeSetLevelFunc) {
  281. c.OnBeforeSetLevel = append(c.OnBeforeSetLevel, hook)
  282. }
  283. func (c *Hooks) AddAfterSetLevel(hook OnAfterSetLevelFunc) {
  284. c.OnAfterSetLevel = append(c.OnAfterSetLevel, hook)
  285. }
  286. func (c *Hooks) beforeSetLevel(ctx context.Context, id any, message *mcp.SetLevelRequest) {
  287. c.beforeAny(ctx, id, mcp.MethodSetLogLevel, message)
  288. if c == nil {
  289. return
  290. }
  291. for _, hook := range c.OnBeforeSetLevel {
  292. hook(ctx, id, message)
  293. }
  294. }
  295. func (c *Hooks) afterSetLevel(ctx context.Context, id any, message *mcp.SetLevelRequest, result *mcp.EmptyResult) {
  296. c.onSuccess(ctx, id, mcp.MethodSetLogLevel, message, result)
  297. if c == nil {
  298. return
  299. }
  300. for _, hook := range c.OnAfterSetLevel {
  301. hook(ctx, id, message, result)
  302. }
  303. }
  304. func (c *Hooks) AddBeforeListResources(hook OnBeforeListResourcesFunc) {
  305. c.OnBeforeListResources = append(c.OnBeforeListResources, hook)
  306. }
  307. func (c *Hooks) AddAfterListResources(hook OnAfterListResourcesFunc) {
  308. c.OnAfterListResources = append(c.OnAfterListResources, hook)
  309. }
  310. func (c *Hooks) beforeListResources(ctx context.Context, id any, message *mcp.ListResourcesRequest) {
  311. c.beforeAny(ctx, id, mcp.MethodResourcesList, message)
  312. if c == nil {
  313. return
  314. }
  315. for _, hook := range c.OnBeforeListResources {
  316. hook(ctx, id, message)
  317. }
  318. }
  319. func (c *Hooks) afterListResources(ctx context.Context, id any, message *mcp.ListResourcesRequest, result *mcp.ListResourcesResult) {
  320. c.onSuccess(ctx, id, mcp.MethodResourcesList, message, result)
  321. if c == nil {
  322. return
  323. }
  324. for _, hook := range c.OnAfterListResources {
  325. hook(ctx, id, message, result)
  326. }
  327. }
  328. func (c *Hooks) AddBeforeListResourceTemplates(hook OnBeforeListResourceTemplatesFunc) {
  329. c.OnBeforeListResourceTemplates = append(c.OnBeforeListResourceTemplates, hook)
  330. }
  331. func (c *Hooks) AddAfterListResourceTemplates(hook OnAfterListResourceTemplatesFunc) {
  332. c.OnAfterListResourceTemplates = append(c.OnAfterListResourceTemplates, hook)
  333. }
  334. func (c *Hooks) beforeListResourceTemplates(ctx context.Context, id any, message *mcp.ListResourceTemplatesRequest) {
  335. c.beforeAny(ctx, id, mcp.MethodResourcesTemplatesList, message)
  336. if c == nil {
  337. return
  338. }
  339. for _, hook := range c.OnBeforeListResourceTemplates {
  340. hook(ctx, id, message)
  341. }
  342. }
  343. func (c *Hooks) afterListResourceTemplates(ctx context.Context, id any, message *mcp.ListResourceTemplatesRequest, result *mcp.ListResourceTemplatesResult) {
  344. c.onSuccess(ctx, id, mcp.MethodResourcesTemplatesList, message, result)
  345. if c == nil {
  346. return
  347. }
  348. for _, hook := range c.OnAfterListResourceTemplates {
  349. hook(ctx, id, message, result)
  350. }
  351. }
  352. func (c *Hooks) AddBeforeReadResource(hook OnBeforeReadResourceFunc) {
  353. c.OnBeforeReadResource = append(c.OnBeforeReadResource, hook)
  354. }
  355. func (c *Hooks) AddAfterReadResource(hook OnAfterReadResourceFunc) {
  356. c.OnAfterReadResource = append(c.OnAfterReadResource, hook)
  357. }
  358. func (c *Hooks) beforeReadResource(ctx context.Context, id any, message *mcp.ReadResourceRequest) {
  359. c.beforeAny(ctx, id, mcp.MethodResourcesRead, message)
  360. if c == nil {
  361. return
  362. }
  363. for _, hook := range c.OnBeforeReadResource {
  364. hook(ctx, id, message)
  365. }
  366. }
  367. func (c *Hooks) afterReadResource(ctx context.Context, id any, message *mcp.ReadResourceRequest, result *mcp.ReadResourceResult) {
  368. c.onSuccess(ctx, id, mcp.MethodResourcesRead, message, result)
  369. if c == nil {
  370. return
  371. }
  372. for _, hook := range c.OnAfterReadResource {
  373. hook(ctx, id, message, result)
  374. }
  375. }
  376. func (c *Hooks) AddBeforeListPrompts(hook OnBeforeListPromptsFunc) {
  377. c.OnBeforeListPrompts = append(c.OnBeforeListPrompts, hook)
  378. }
  379. func (c *Hooks) AddAfterListPrompts(hook OnAfterListPromptsFunc) {
  380. c.OnAfterListPrompts = append(c.OnAfterListPrompts, hook)
  381. }
  382. func (c *Hooks) beforeListPrompts(ctx context.Context, id any, message *mcp.ListPromptsRequest) {
  383. c.beforeAny(ctx, id, mcp.MethodPromptsList, message)
  384. if c == nil {
  385. return
  386. }
  387. for _, hook := range c.OnBeforeListPrompts {
  388. hook(ctx, id, message)
  389. }
  390. }
  391. func (c *Hooks) afterListPrompts(ctx context.Context, id any, message *mcp.ListPromptsRequest, result *mcp.ListPromptsResult) {
  392. c.onSuccess(ctx, id, mcp.MethodPromptsList, message, result)
  393. if c == nil {
  394. return
  395. }
  396. for _, hook := range c.OnAfterListPrompts {
  397. hook(ctx, id, message, result)
  398. }
  399. }
  400. func (c *Hooks) AddBeforeGetPrompt(hook OnBeforeGetPromptFunc) {
  401. c.OnBeforeGetPrompt = append(c.OnBeforeGetPrompt, hook)
  402. }
  403. func (c *Hooks) AddAfterGetPrompt(hook OnAfterGetPromptFunc) {
  404. c.OnAfterGetPrompt = append(c.OnAfterGetPrompt, hook)
  405. }
  406. func (c *Hooks) beforeGetPrompt(ctx context.Context, id any, message *mcp.GetPromptRequest) {
  407. c.beforeAny(ctx, id, mcp.MethodPromptsGet, message)
  408. if c == nil {
  409. return
  410. }
  411. for _, hook := range c.OnBeforeGetPrompt {
  412. hook(ctx, id, message)
  413. }
  414. }
  415. func (c *Hooks) afterGetPrompt(ctx context.Context, id any, message *mcp.GetPromptRequest, result *mcp.GetPromptResult) {
  416. c.onSuccess(ctx, id, mcp.MethodPromptsGet, message, result)
  417. if c == nil {
  418. return
  419. }
  420. for _, hook := range c.OnAfterGetPrompt {
  421. hook(ctx, id, message, result)
  422. }
  423. }
  424. func (c *Hooks) AddBeforeListTools(hook OnBeforeListToolsFunc) {
  425. c.OnBeforeListTools = append(c.OnBeforeListTools, hook)
  426. }
  427. func (c *Hooks) AddAfterListTools(hook OnAfterListToolsFunc) {
  428. c.OnAfterListTools = append(c.OnAfterListTools, hook)
  429. }
  430. func (c *Hooks) beforeListTools(ctx context.Context, id any, message *mcp.ListToolsRequest) {
  431. c.beforeAny(ctx, id, mcp.MethodToolsList, message)
  432. if c == nil {
  433. return
  434. }
  435. for _, hook := range c.OnBeforeListTools {
  436. hook(ctx, id, message)
  437. }
  438. }
  439. func (c *Hooks) afterListTools(ctx context.Context, id any, message *mcp.ListToolsRequest, result *mcp.ListToolsResult) {
  440. c.onSuccess(ctx, id, mcp.MethodToolsList, message, result)
  441. if c == nil {
  442. return
  443. }
  444. for _, hook := range c.OnAfterListTools {
  445. hook(ctx, id, message, result)
  446. }
  447. }
  448. func (c *Hooks) AddBeforeCallTool(hook OnBeforeCallToolFunc) {
  449. c.OnBeforeCallTool = append(c.OnBeforeCallTool, hook)
  450. }
  451. func (c *Hooks) AddAfterCallTool(hook OnAfterCallToolFunc) {
  452. c.OnAfterCallTool = append(c.OnAfterCallTool, hook)
  453. }
  454. func (c *Hooks) beforeCallTool(ctx context.Context, id any, message *mcp.CallToolRequest) {
  455. c.beforeAny(ctx, id, mcp.MethodToolsCall, message)
  456. if c == nil {
  457. return
  458. }
  459. for _, hook := range c.OnBeforeCallTool {
  460. hook(ctx, id, message)
  461. }
  462. }
  463. func (c *Hooks) afterCallTool(ctx context.Context, id any, message *mcp.CallToolRequest, result *mcp.CallToolResult) {
  464. c.onSuccess(ctx, id, mcp.MethodToolsCall, message, result)
  465. if c == nil {
  466. return
  467. }
  468. for _, hook := range c.OnAfterCallTool {
  469. hook(ctx, id, message, result)
  470. }
  471. }