@tencent-ai/codebuddy-code 2.67.0 → 2.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (458) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/codebuddy-headless.js +53 -53
  3. package/dist/codebuddy.js +93 -64
  4. package/dist/web-ui/assets/index-BoMlEqUE.js +439 -0
  5. package/dist/web-ui/assets/index-Dt1puyHn.css +32 -0
  6. package/dist/web-ui/docs/cn/cli/acp.md +152 -0
  7. package/dist/web-ui/docs/cn/cli/agent-teams.md +327 -0
  8. package/dist/web-ui/docs/cn/cli/bash-sandboxing.md +290 -0
  9. package/dist/web-ui/docs/cn/cli/best-practices.md +554 -0
  10. package/dist/web-ui/docs/cn/cli/channels-reference.md +293 -0
  11. package/dist/web-ui/docs/cn/cli/channels.md +215 -0
  12. package/dist/web-ui/docs/cn/cli/checkpointing.md +51 -0
  13. package/dist/web-ui/docs/cn/cli/cli-reference.md +187 -0
  14. package/dist/web-ui/docs/cn/cli/common-workflows.md +1013 -0
  15. package/dist/web-ui/docs/cn/cli/costs.md +174 -0
  16. package/dist/web-ui/docs/cn/cli/devcontainer.md +553 -0
  17. package/dist/web-ui/docs/cn/cli/env-vars.md +326 -0
  18. package/dist/web-ui/docs/cn/cli/gitlab-ci-cd.md +357 -0
  19. package/dist/web-ui/docs/cn/cli/headless.md +258 -0
  20. package/dist/web-ui/docs/cn/cli/hooks-guide.md +9 -0
  21. package/dist/web-ui/docs/cn/cli/hooks.md +805 -0
  22. package/dist/web-ui/docs/cn/cli/iam.md +530 -0
  23. package/dist/web-ui/docs/cn/cli/ide-integrations.md +92 -0
  24. package/dist/web-ui/docs/cn/cli/installation.md +291 -0
  25. package/dist/web-ui/docs/cn/cli/interactive-mode.md +233 -0
  26. package/dist/web-ui/docs/cn/cli/mcp.md +739 -0
  27. package/dist/web-ui/docs/cn/cli/memory.md +436 -0
  28. package/dist/web-ui/docs/cn/cli/models.md +356 -0
  29. package/dist/web-ui/docs/cn/cli/overview.md +100 -0
  30. package/dist/web-ui/docs/cn/cli/plugin-marketplaces.md +533 -0
  31. package/dist/web-ui/docs/cn/cli/plugins-reference.md +774 -0
  32. package/dist/web-ui/docs/cn/cli/plugins.md +689 -0
  33. package/dist/web-ui/docs/cn/cli/quickstart.md +249 -0
  34. package/dist/web-ui/docs/cn/cli/release-notes/README.md +199 -0
  35. package/dist/web-ui/docs/cn/cli/release-notes/v2.10.0.md +23 -0
  36. package/dist/web-ui/docs/cn/cli/release-notes/v2.10.1.md +5 -0
  37. package/dist/web-ui/docs/cn/cli/release-notes/v2.11.0.md +24 -0
  38. package/dist/web-ui/docs/cn/cli/release-notes/v2.12.0.md +21 -0
  39. package/dist/web-ui/docs/cn/cli/release-notes/v2.13.0.md +20 -0
  40. package/dist/web-ui/docs/cn/cli/release-notes/v2.14.0.md +22 -0
  41. package/dist/web-ui/docs/cn/cli/release-notes/v2.14.1.md +8 -0
  42. package/dist/web-ui/docs/cn/cli/release-notes/v2.15.0.md +18 -0
  43. package/dist/web-ui/docs/cn/cli/release-notes/v2.15.1.md +11 -0
  44. package/dist/web-ui/docs/cn/cli/release-notes/v2.16.0.md +20 -0
  45. package/dist/web-ui/docs/cn/cli/release-notes/v2.17.0.md +29 -0
  46. package/dist/web-ui/docs/cn/cli/release-notes/v2.18.0.md +17 -0
  47. package/dist/web-ui/docs/cn/cli/release-notes/v2.19.0.md +11 -0
  48. package/dist/web-ui/docs/cn/cli/release-notes/v2.19.1.md +14 -0
  49. package/dist/web-ui/docs/cn/cli/release-notes/v2.19.2.md +11 -0
  50. package/dist/web-ui/docs/cn/cli/release-notes/v2.20.0.md +23 -0
  51. package/dist/web-ui/docs/cn/cli/release-notes/v2.20.1.md +15 -0
  52. package/dist/web-ui/docs/cn/cli/release-notes/v2.21.0.md +13 -0
  53. package/dist/web-ui/docs/cn/cli/release-notes/v2.22.0.md +16 -0
  54. package/dist/web-ui/docs/cn/cli/release-notes/v2.23.0.md +20 -0
  55. package/dist/web-ui/docs/cn/cli/release-notes/v2.23.2.md +5 -0
  56. package/dist/web-ui/docs/cn/cli/release-notes/v2.23.3.md +5 -0
  57. package/dist/web-ui/docs/cn/cli/release-notes/v2.23.4.md +15 -0
  58. package/dist/web-ui/docs/cn/cli/release-notes/v2.23.5.md +11 -0
  59. package/dist/web-ui/docs/cn/cli/release-notes/v2.24.0.md +17 -0
  60. package/dist/web-ui/docs/cn/cli/release-notes/v2.25.0.md +18 -0
  61. package/dist/web-ui/docs/cn/cli/release-notes/v2.25.1.md +21 -0
  62. package/dist/web-ui/docs/cn/cli/release-notes/v2.26.0.md +18 -0
  63. package/dist/web-ui/docs/cn/cli/release-notes/v2.27.0.md +16 -0
  64. package/dist/web-ui/docs/cn/cli/release-notes/v2.27.1.md +16 -0
  65. package/dist/web-ui/docs/cn/cli/release-notes/v2.27.2.md +7 -0
  66. package/dist/web-ui/docs/cn/cli/release-notes/v2.27.3.md +15 -0
  67. package/dist/web-ui/docs/cn/cli/release-notes/v2.28.0.md +26 -0
  68. package/dist/web-ui/docs/cn/cli/release-notes/v2.28.1.md +5 -0
  69. package/dist/web-ui/docs/cn/cli/release-notes/v2.29.0.md +35 -0
  70. package/dist/web-ui/docs/cn/cli/release-notes/v2.3.1.md +16 -0
  71. package/dist/web-ui/docs/cn/cli/release-notes/v2.30.0.md +19 -0
  72. package/dist/web-ui/docs/cn/cli/release-notes/v2.30.1.md +5 -0
  73. package/dist/web-ui/docs/cn/cli/release-notes/v2.31.0.md +51 -0
  74. package/dist/web-ui/docs/cn/cli/release-notes/v2.31.1.md +11 -0
  75. package/dist/web-ui/docs/cn/cli/release-notes/v2.31.2.md +16 -0
  76. package/dist/web-ui/docs/cn/cli/release-notes/v2.32.0.md +19 -0
  77. package/dist/web-ui/docs/cn/cli/release-notes/v2.33.0.md +28 -0
  78. package/dist/web-ui/docs/cn/cli/release-notes/v2.33.1.md +7 -0
  79. package/dist/web-ui/docs/cn/cli/release-notes/v2.36.3.md +17 -0
  80. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.0.md +15 -0
  81. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.1.md +15 -0
  82. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.10.md +5 -0
  83. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.11.md +8 -0
  84. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.12.md +14 -0
  85. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.13.md +11 -0
  86. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.14.md +24 -0
  87. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.15.md +11 -0
  88. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.16.md +9 -0
  89. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.17.md +5 -0
  90. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.18.md +9 -0
  91. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.19.md +5 -0
  92. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.2.md +28 -0
  93. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.20.md +8 -0
  94. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.3.md +22 -0
  95. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.4.md +19 -0
  96. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.5.md +5 -0
  97. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.6.md +5 -0
  98. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.7.md +5 -0
  99. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.8.md +5 -0
  100. package/dist/web-ui/docs/cn/cli/release-notes/v2.37.9.md +8 -0
  101. package/dist/web-ui/docs/cn/cli/release-notes/v2.38.0.md +22 -0
  102. package/dist/web-ui/docs/cn/cli/release-notes/v2.38.1.md +6 -0
  103. package/dist/web-ui/docs/cn/cli/release-notes/v2.38.2.md +9 -0
  104. package/dist/web-ui/docs/cn/cli/release-notes/v2.39.0.md +18 -0
  105. package/dist/web-ui/docs/cn/cli/release-notes/v2.4.0.md +19 -0
  106. package/dist/web-ui/docs/cn/cli/release-notes/v2.40.0.md +20 -0
  107. package/dist/web-ui/docs/cn/cli/release-notes/v2.40.1.md +6 -0
  108. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.0.md +15 -0
  109. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.1.md +6 -0
  110. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.2.md +5 -0
  111. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.3.md +8 -0
  112. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.4.md +5 -0
  113. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.5.md +10 -0
  114. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.6.md +9 -0
  115. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.7.md +14 -0
  116. package/dist/web-ui/docs/cn/cli/release-notes/v2.41.8.md +18 -0
  117. package/dist/web-ui/docs/cn/cli/release-notes/v2.42.0.md +39 -0
  118. package/dist/web-ui/docs/cn/cli/release-notes/v2.42.1.md +8 -0
  119. package/dist/web-ui/docs/cn/cli/release-notes/v2.42.3.md +18 -0
  120. package/dist/web-ui/docs/cn/cli/release-notes/v2.43.0.md +27 -0
  121. package/dist/web-ui/docs/cn/cli/release-notes/v2.43.1.md +27 -0
  122. package/dist/web-ui/docs/cn/cli/release-notes/v2.44.0.md +11 -0
  123. package/dist/web-ui/docs/cn/cli/release-notes/v2.44.1.md +22 -0
  124. package/dist/web-ui/docs/cn/cli/release-notes/v2.45.0.md +34 -0
  125. package/dist/web-ui/docs/cn/cli/release-notes/v2.45.1.md +7 -0
  126. package/dist/web-ui/docs/cn/cli/release-notes/v2.46.0.md +12 -0
  127. package/dist/web-ui/docs/cn/cli/release-notes/v2.47.0.md +20 -0
  128. package/dist/web-ui/docs/cn/cli/release-notes/v2.48.0.md +32 -0
  129. package/dist/web-ui/docs/cn/cli/release-notes/v2.48.1.md +11 -0
  130. package/dist/web-ui/docs/cn/cli/release-notes/v2.49.0.md +26 -0
  131. package/dist/web-ui/docs/cn/cli/release-notes/v2.49.1.md +14 -0
  132. package/dist/web-ui/docs/cn/cli/release-notes/v2.49.2.md +39 -0
  133. package/dist/web-ui/docs/cn/cli/release-notes/v2.49.3.md +7 -0
  134. package/dist/web-ui/docs/cn/cli/release-notes/v2.49.5.md +11 -0
  135. package/dist/web-ui/docs/cn/cli/release-notes/v2.49.6.md +9 -0
  136. package/dist/web-ui/docs/cn/cli/release-notes/v2.49.7.md +7 -0
  137. package/dist/web-ui/docs/cn/cli/release-notes/v2.5.0.md +24 -0
  138. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.0.md +25 -0
  139. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.1.md +9 -0
  140. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.2.md +11 -0
  141. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.3.md +5 -0
  142. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.4.md +17 -0
  143. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.5.md +16 -0
  144. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.6.md +15 -0
  145. package/dist/web-ui/docs/cn/cli/release-notes/v2.50.7.md +15 -0
  146. package/dist/web-ui/docs/cn/cli/release-notes/v2.51.0.md +24 -0
  147. package/dist/web-ui/docs/cn/cli/release-notes/v2.51.1.md +17 -0
  148. package/dist/web-ui/docs/cn/cli/release-notes/v2.51.2.md +5 -0
  149. package/dist/web-ui/docs/cn/cli/release-notes/v2.52.0.md +30 -0
  150. package/dist/web-ui/docs/cn/cli/release-notes/v2.52.1.md +28 -0
  151. package/dist/web-ui/docs/cn/cli/release-notes/v2.52.2.md +12 -0
  152. package/dist/web-ui/docs/cn/cli/release-notes/v2.52.3.md +13 -0
  153. package/dist/web-ui/docs/cn/cli/release-notes/v2.52.4.md +27 -0
  154. package/dist/web-ui/docs/cn/cli/release-notes/v2.52.5.md +21 -0
  155. package/dist/web-ui/docs/cn/cli/release-notes/v2.52.6.md +7 -0
  156. package/dist/web-ui/docs/cn/cli/release-notes/v2.53.0.md +29 -0
  157. package/dist/web-ui/docs/cn/cli/release-notes/v2.54.0.md +26 -0
  158. package/dist/web-ui/docs/cn/cli/release-notes/v2.55.0.md +21 -0
  159. package/dist/web-ui/docs/cn/cli/release-notes/v2.55.1.md +13 -0
  160. package/dist/web-ui/docs/cn/cli/release-notes/v2.56.0.md +20 -0
  161. package/dist/web-ui/docs/cn/cli/release-notes/v2.56.1.md +5 -0
  162. package/dist/web-ui/docs/cn/cli/release-notes/v2.57.0.md +32 -0
  163. package/dist/web-ui/docs/cn/cli/release-notes/v2.57.1.md +10 -0
  164. package/dist/web-ui/docs/cn/cli/release-notes/v2.58.0.md +34 -0
  165. package/dist/web-ui/docs/cn/cli/release-notes/v2.59.0.md +28 -0
  166. package/dist/web-ui/docs/cn/cli/release-notes/v2.6.0.md +5 -0
  167. package/dist/web-ui/docs/cn/cli/release-notes/v2.6.1.md +10 -0
  168. package/dist/web-ui/docs/cn/cli/release-notes/v2.60.0.md +20 -0
  169. package/dist/web-ui/docs/cn/cli/release-notes/v2.61.0.md +29 -0
  170. package/dist/web-ui/docs/cn/cli/release-notes/v2.61.1.md +5 -0
  171. package/dist/web-ui/docs/cn/cli/release-notes/v2.61.2.md +6 -0
  172. package/dist/web-ui/docs/cn/cli/release-notes/v2.61.3.md +13 -0
  173. package/dist/web-ui/docs/cn/cli/release-notes/v2.62.0.md +21 -0
  174. package/dist/web-ui/docs/cn/cli/release-notes/v2.62.1.md +11 -0
  175. package/dist/web-ui/docs/cn/cli/release-notes/v2.63.0.md +19 -0
  176. package/dist/web-ui/docs/cn/cli/release-notes/v2.63.1.md +5 -0
  177. package/dist/web-ui/docs/cn/cli/release-notes/v2.63.2.md +7 -0
  178. package/dist/web-ui/docs/cn/cli/release-notes/v2.63.3.md +6 -0
  179. package/dist/web-ui/docs/cn/cli/release-notes/v2.63.4.md +8 -0
  180. package/dist/web-ui/docs/cn/cli/release-notes/v2.63.5.md +6 -0
  181. package/dist/web-ui/docs/cn/cli/release-notes/v2.64.0.md +37 -0
  182. package/dist/web-ui/docs/cn/cli/release-notes/v2.64.1.md +6 -0
  183. package/dist/web-ui/docs/cn/cli/release-notes/v2.64.2.md +11 -0
  184. package/dist/web-ui/docs/cn/cli/release-notes/v2.65.0.md +19 -0
  185. package/dist/web-ui/docs/cn/cli/release-notes/v2.65.1.md +11 -0
  186. package/dist/web-ui/docs/cn/cli/release-notes/v2.66.0.md +15 -0
  187. package/dist/web-ui/docs/cn/cli/release-notes/v2.66.1.md +14 -0
  188. package/dist/web-ui/docs/cn/cli/release-notes/v2.66.2.md +5 -0
  189. package/dist/web-ui/docs/cn/cli/release-notes/v2.67.0.md +33 -0
  190. package/dist/web-ui/docs/cn/cli/release-notes/v2.7.0.md +16 -0
  191. package/dist/web-ui/docs/cn/cli/release-notes/v2.8.0.md +18 -0
  192. package/dist/web-ui/docs/cn/cli/release-notes/v2.8.1.md +17 -0
  193. package/dist/web-ui/docs/cn/cli/release-notes/v2.8.2.md +5 -0
  194. package/dist/web-ui/docs/cn/cli/release-notes/v2.8.3.md +14 -0
  195. package/dist/web-ui/docs/cn/cli/release-notes/v2.8.4.md +9 -0
  196. package/dist/web-ui/docs/cn/cli/release-notes/v2.8.5.md +5 -0
  197. package/dist/web-ui/docs/cn/cli/release-notes/v2.8.6.md +14 -0
  198. package/dist/web-ui/docs/cn/cli/release-notes/v2.9.0.md +5 -0
  199. package/dist/web-ui/docs/cn/cli/remote-control.md +247 -0
  200. package/dist/web-ui/docs/cn/cli/sandboxing.md +316 -0
  201. package/dist/web-ui/docs/cn/cli/scheduled-tasks.md +161 -0
  202. package/dist/web-ui/docs/cn/cli/sdk-custom-tools.md +1195 -0
  203. package/dist/web-ui/docs/cn/cli/sdk-demos.md +347 -0
  204. package/dist/web-ui/docs/cn/cli/sdk-hooks.md +803 -0
  205. package/dist/web-ui/docs/cn/cli/sdk-mcp.md +643 -0
  206. package/dist/web-ui/docs/cn/cli/sdk-permissions.md +501 -0
  207. package/dist/web-ui/docs/cn/cli/sdk-python.md +783 -0
  208. package/dist/web-ui/docs/cn/cli/sdk-sessions.md +332 -0
  209. package/dist/web-ui/docs/cn/cli/sdk-typescript.md +759 -0
  210. package/dist/web-ui/docs/cn/cli/sdk.md +1105 -0
  211. package/dist/web-ui/docs/cn/cli/security.md +387 -0
  212. package/dist/web-ui/docs/cn/cli/settings.md +602 -0
  213. package/dist/web-ui/docs/cn/cli/skills.md +448 -0
  214. package/dist/web-ui/docs/cn/cli/slash-commands.md +397 -0
  215. package/dist/web-ui/docs/cn/cli/statusline.md +525 -0
  216. package/dist/web-ui/docs/cn/cli/sub-agents.md +634 -0
  217. package/dist/web-ui/docs/cn/cli/terminal-config.md +77 -0
  218. package/dist/web-ui/docs/cn/cli/tools-reference.md +99 -0
  219. package/dist/web-ui/docs/cn/cli/troubleshooting.md +190 -0
  220. package/dist/web-ui/docs/cn/cli/web-ui.md +164 -0
  221. package/dist/web-ui/docs/cn/cli/wecom-bot-setup.md +274 -0
  222. package/dist/web-ui/docs/cn/cli/worktree.md +660 -0
  223. package/dist/web-ui/docs/en/cli/acp.md +126 -0
  224. package/dist/web-ui/docs/en/cli/agent-teams.md +327 -0
  225. package/dist/web-ui/docs/en/cli/bash-sandboxing.md +357 -0
  226. package/dist/web-ui/docs/en/cli/best-practices.md +554 -0
  227. package/dist/web-ui/docs/en/cli/channels-reference.md +293 -0
  228. package/dist/web-ui/docs/en/cli/channels.md +215 -0
  229. package/dist/web-ui/docs/en/cli/checkpointing.md +53 -0
  230. package/dist/web-ui/docs/en/cli/cli-reference.md +187 -0
  231. package/dist/web-ui/docs/en/cli/common-workflows.md +1011 -0
  232. package/dist/web-ui/docs/en/cli/costs.md +174 -0
  233. package/dist/web-ui/docs/en/cli/devcontainer.md +553 -0
  234. package/dist/web-ui/docs/en/cli/env-vars.md +326 -0
  235. package/dist/web-ui/docs/en/cli/gitlab-ci-cd.md +357 -0
  236. package/dist/web-ui/docs/en/cli/headless.md +258 -0
  237. package/dist/web-ui/docs/en/cli/hooks-guide.md +9 -0
  238. package/dist/web-ui/docs/en/cli/hooks.md +801 -0
  239. package/dist/web-ui/docs/en/cli/iam.md +526 -0
  240. package/dist/web-ui/docs/en/cli/ide-integrations.md +92 -0
  241. package/dist/web-ui/docs/en/cli/installation.md +266 -0
  242. package/dist/web-ui/docs/en/cli/interactive-mode.md +233 -0
  243. package/dist/web-ui/docs/en/cli/mcp.md +739 -0
  244. package/dist/web-ui/docs/en/cli/memory.md +436 -0
  245. package/dist/web-ui/docs/en/cli/models.md +355 -0
  246. package/dist/web-ui/docs/en/cli/overview.md +100 -0
  247. package/dist/web-ui/docs/en/cli/plugin-marketplaces.md +534 -0
  248. package/dist/web-ui/docs/en/cli/plugins-reference.md +774 -0
  249. package/dist/web-ui/docs/en/cli/plugins.md +688 -0
  250. package/dist/web-ui/docs/en/cli/quickstart.md +249 -0
  251. package/dist/web-ui/docs/en/cli/release-notes/README.md +193 -0
  252. package/dist/web-ui/docs/en/cli/release-notes/v2.10.0.md +23 -0
  253. package/dist/web-ui/docs/en/cli/release-notes/v2.10.1.md +5 -0
  254. package/dist/web-ui/docs/en/cli/release-notes/v2.11.0.md +24 -0
  255. package/dist/web-ui/docs/en/cli/release-notes/v2.12.0.md +21 -0
  256. package/dist/web-ui/docs/en/cli/release-notes/v2.13.0.md +20 -0
  257. package/dist/web-ui/docs/en/cli/release-notes/v2.14.0.md +22 -0
  258. package/dist/web-ui/docs/en/cli/release-notes/v2.14.1.md +8 -0
  259. package/dist/web-ui/docs/en/cli/release-notes/v2.15.0.md +18 -0
  260. package/dist/web-ui/docs/en/cli/release-notes/v2.15.1.md +11 -0
  261. package/dist/web-ui/docs/en/cli/release-notes/v2.16.0.md +20 -0
  262. package/dist/web-ui/docs/en/cli/release-notes/v2.17.0.md +29 -0
  263. package/dist/web-ui/docs/en/cli/release-notes/v2.18.0.md +17 -0
  264. package/dist/web-ui/docs/en/cli/release-notes/v2.19.0.md +11 -0
  265. package/dist/web-ui/docs/en/cli/release-notes/v2.19.1.md +14 -0
  266. package/dist/web-ui/docs/en/cli/release-notes/v2.19.2.md +11 -0
  267. package/dist/web-ui/docs/en/cli/release-notes/v2.20.0.md +23 -0
  268. package/dist/web-ui/docs/en/cli/release-notes/v2.20.1.md +15 -0
  269. package/dist/web-ui/docs/en/cli/release-notes/v2.21.0.md +13 -0
  270. package/dist/web-ui/docs/en/cli/release-notes/v2.22.0.md +16 -0
  271. package/dist/web-ui/docs/en/cli/release-notes/v2.23.0.md +41 -0
  272. package/dist/web-ui/docs/en/cli/release-notes/v2.23.2.md +5 -0
  273. package/dist/web-ui/docs/en/cli/release-notes/v2.23.3.md +5 -0
  274. package/dist/web-ui/docs/en/cli/release-notes/v2.23.4.md +15 -0
  275. package/dist/web-ui/docs/en/cli/release-notes/v2.23.5.md +11 -0
  276. package/dist/web-ui/docs/en/cli/release-notes/v2.24.0.md +17 -0
  277. package/dist/web-ui/docs/en/cli/release-notes/v2.25.0.md +18 -0
  278. package/dist/web-ui/docs/en/cli/release-notes/v2.25.1.md +21 -0
  279. package/dist/web-ui/docs/en/cli/release-notes/v2.26.0.md +18 -0
  280. package/dist/web-ui/docs/en/cli/release-notes/v2.27.0.md +16 -0
  281. package/dist/web-ui/docs/en/cli/release-notes/v2.27.1.md +16 -0
  282. package/dist/web-ui/docs/en/cli/release-notes/v2.27.2.md +7 -0
  283. package/dist/web-ui/docs/en/cli/release-notes/v2.27.3.md +15 -0
  284. package/dist/web-ui/docs/en/cli/release-notes/v2.28.0.md +26 -0
  285. package/dist/web-ui/docs/en/cli/release-notes/v2.28.1.md +5 -0
  286. package/dist/web-ui/docs/en/cli/release-notes/v2.29.0.md +35 -0
  287. package/dist/web-ui/docs/en/cli/release-notes/v2.3.1.md +16 -0
  288. package/dist/web-ui/docs/en/cli/release-notes/v2.30.0.md +19 -0
  289. package/dist/web-ui/docs/en/cli/release-notes/v2.30.1.md +5 -0
  290. package/dist/web-ui/docs/en/cli/release-notes/v2.31.0.md +51 -0
  291. package/dist/web-ui/docs/en/cli/release-notes/v2.31.1.md +11 -0
  292. package/dist/web-ui/docs/en/cli/release-notes/v2.31.2.md +16 -0
  293. package/dist/web-ui/docs/en/cli/release-notes/v2.32.0.md +19 -0
  294. package/dist/web-ui/docs/en/cli/release-notes/v2.33.0.md +28 -0
  295. package/dist/web-ui/docs/en/cli/release-notes/v2.33.1.md +7 -0
  296. package/dist/web-ui/docs/en/cli/release-notes/v2.34.0.md +27 -0
  297. package/dist/web-ui/docs/en/cli/release-notes/v2.34.1.md +7 -0
  298. package/dist/web-ui/docs/en/cli/release-notes/v2.35.0.md +22 -0
  299. package/dist/web-ui/docs/en/cli/release-notes/v2.36.0.md +23 -0
  300. package/dist/web-ui/docs/en/cli/release-notes/v2.36.1.md +5 -0
  301. package/dist/web-ui/docs/en/cli/release-notes/v2.36.2.md +22 -0
  302. package/dist/web-ui/docs/en/cli/release-notes/v2.36.3.md +17 -0
  303. package/dist/web-ui/docs/en/cli/release-notes/v2.37.0.md +15 -0
  304. package/dist/web-ui/docs/en/cli/release-notes/v2.37.1.md +15 -0
  305. package/dist/web-ui/docs/en/cli/release-notes/v2.37.10.md +5 -0
  306. package/dist/web-ui/docs/en/cli/release-notes/v2.37.11.md +8 -0
  307. package/dist/web-ui/docs/en/cli/release-notes/v2.37.12.md +14 -0
  308. package/dist/web-ui/docs/en/cli/release-notes/v2.37.13.md +11 -0
  309. package/dist/web-ui/docs/en/cli/release-notes/v2.37.14.md +24 -0
  310. package/dist/web-ui/docs/en/cli/release-notes/v2.37.15.md +11 -0
  311. package/dist/web-ui/docs/en/cli/release-notes/v2.37.16.md +9 -0
  312. package/dist/web-ui/docs/en/cli/release-notes/v2.37.17.md +5 -0
  313. package/dist/web-ui/docs/en/cli/release-notes/v2.37.18.md +9 -0
  314. package/dist/web-ui/docs/en/cli/release-notes/v2.37.19.md +5 -0
  315. package/dist/web-ui/docs/en/cli/release-notes/v2.37.2.md +28 -0
  316. package/dist/web-ui/docs/en/cli/release-notes/v2.37.20.md +8 -0
  317. package/dist/web-ui/docs/en/cli/release-notes/v2.37.3.md +22 -0
  318. package/dist/web-ui/docs/en/cli/release-notes/v2.37.4.md +19 -0
  319. package/dist/web-ui/docs/en/cli/release-notes/v2.37.5.md +5 -0
  320. package/dist/web-ui/docs/en/cli/release-notes/v2.37.6.md +5 -0
  321. package/dist/web-ui/docs/en/cli/release-notes/v2.37.7.md +5 -0
  322. package/dist/web-ui/docs/en/cli/release-notes/v2.37.8.md +5 -0
  323. package/dist/web-ui/docs/en/cli/release-notes/v2.37.9.md +8 -0
  324. package/dist/web-ui/docs/en/cli/release-notes/v2.38.0.md +22 -0
  325. package/dist/web-ui/docs/en/cli/release-notes/v2.38.1.md +6 -0
  326. package/dist/web-ui/docs/en/cli/release-notes/v2.38.2.md +9 -0
  327. package/dist/web-ui/docs/en/cli/release-notes/v2.39.0.md +18 -0
  328. package/dist/web-ui/docs/en/cli/release-notes/v2.4.0.md +19 -0
  329. package/dist/web-ui/docs/en/cli/release-notes/v2.40.0.md +20 -0
  330. package/dist/web-ui/docs/en/cli/release-notes/v2.40.1.md +6 -0
  331. package/dist/web-ui/docs/en/cli/release-notes/v2.41.0.md +15 -0
  332. package/dist/web-ui/docs/en/cli/release-notes/v2.41.1.md +6 -0
  333. package/dist/web-ui/docs/en/cli/release-notes/v2.41.2.md +5 -0
  334. package/dist/web-ui/docs/en/cli/release-notes/v2.41.3.md +8 -0
  335. package/dist/web-ui/docs/en/cli/release-notes/v2.41.4.md +5 -0
  336. package/dist/web-ui/docs/en/cli/release-notes/v2.41.5.md +10 -0
  337. package/dist/web-ui/docs/en/cli/release-notes/v2.41.6.md +9 -0
  338. package/dist/web-ui/docs/en/cli/release-notes/v2.41.7.md +14 -0
  339. package/dist/web-ui/docs/en/cli/release-notes/v2.41.8.md +18 -0
  340. package/dist/web-ui/docs/en/cli/release-notes/v2.42.0.md +39 -0
  341. package/dist/web-ui/docs/en/cli/release-notes/v2.42.1.md +8 -0
  342. package/dist/web-ui/docs/en/cli/release-notes/v2.42.3.md +18 -0
  343. package/dist/web-ui/docs/en/cli/release-notes/v2.43.0.md +27 -0
  344. package/dist/web-ui/docs/en/cli/release-notes/v2.43.1.md +27 -0
  345. package/dist/web-ui/docs/en/cli/release-notes/v2.44.0.md +11 -0
  346. package/dist/web-ui/docs/en/cli/release-notes/v2.44.1.md +22 -0
  347. package/dist/web-ui/docs/en/cli/release-notes/v2.45.0.md +34 -0
  348. package/dist/web-ui/docs/en/cli/release-notes/v2.45.1.md +7 -0
  349. package/dist/web-ui/docs/en/cli/release-notes/v2.46.0.md +12 -0
  350. package/dist/web-ui/docs/en/cli/release-notes/v2.47.0.md +20 -0
  351. package/dist/web-ui/docs/en/cli/release-notes/v2.48.0.md +32 -0
  352. package/dist/web-ui/docs/en/cli/release-notes/v2.48.1.md +11 -0
  353. package/dist/web-ui/docs/en/cli/release-notes/v2.49.0.md +26 -0
  354. package/dist/web-ui/docs/en/cli/release-notes/v2.49.1.md +14 -0
  355. package/dist/web-ui/docs/en/cli/release-notes/v2.49.2.md +39 -0
  356. package/dist/web-ui/docs/en/cli/release-notes/v2.49.3.md +7 -0
  357. package/dist/web-ui/docs/en/cli/release-notes/v2.49.5.md +11 -0
  358. package/dist/web-ui/docs/en/cli/release-notes/v2.49.6.md +9 -0
  359. package/dist/web-ui/docs/en/cli/release-notes/v2.49.7.md +7 -0
  360. package/dist/web-ui/docs/en/cli/release-notes/v2.5.0.md +24 -0
  361. package/dist/web-ui/docs/en/cli/release-notes/v2.50.0.md +25 -0
  362. package/dist/web-ui/docs/en/cli/release-notes/v2.50.1.md +9 -0
  363. package/dist/web-ui/docs/en/cli/release-notes/v2.50.2.md +11 -0
  364. package/dist/web-ui/docs/en/cli/release-notes/v2.50.3.md +5 -0
  365. package/dist/web-ui/docs/en/cli/release-notes/v2.50.4.md +17 -0
  366. package/dist/web-ui/docs/en/cli/release-notes/v2.50.5.md +16 -0
  367. package/dist/web-ui/docs/en/cli/release-notes/v2.50.6.md +15 -0
  368. package/dist/web-ui/docs/en/cli/release-notes/v2.50.7.md +15 -0
  369. package/dist/web-ui/docs/en/cli/release-notes/v2.51.0.md +24 -0
  370. package/dist/web-ui/docs/en/cli/release-notes/v2.51.1.md +17 -0
  371. package/dist/web-ui/docs/en/cli/release-notes/v2.51.2.md +5 -0
  372. package/dist/web-ui/docs/en/cli/release-notes/v2.52.0.md +30 -0
  373. package/dist/web-ui/docs/en/cli/release-notes/v2.52.1.md +28 -0
  374. package/dist/web-ui/docs/en/cli/release-notes/v2.52.2.md +12 -0
  375. package/dist/web-ui/docs/en/cli/release-notes/v2.52.3.md +13 -0
  376. package/dist/web-ui/docs/en/cli/release-notes/v2.52.4.md +27 -0
  377. package/dist/web-ui/docs/en/cli/release-notes/v2.52.5.md +21 -0
  378. package/dist/web-ui/docs/en/cli/release-notes/v2.52.6.md +7 -0
  379. package/dist/web-ui/docs/en/cli/release-notes/v2.53.0.md +29 -0
  380. package/dist/web-ui/docs/en/cli/release-notes/v2.54.0.md +26 -0
  381. package/dist/web-ui/docs/en/cli/release-notes/v2.55.0.md +21 -0
  382. package/dist/web-ui/docs/en/cli/release-notes/v2.55.1.md +13 -0
  383. package/dist/web-ui/docs/en/cli/release-notes/v2.56.0.md +20 -0
  384. package/dist/web-ui/docs/en/cli/release-notes/v2.56.1.md +5 -0
  385. package/dist/web-ui/docs/en/cli/release-notes/v2.57.0.md +32 -0
  386. package/dist/web-ui/docs/en/cli/release-notes/v2.57.1.md +10 -0
  387. package/dist/web-ui/docs/en/cli/release-notes/v2.58.0.md +34 -0
  388. package/dist/web-ui/docs/en/cli/release-notes/v2.59.0.md +28 -0
  389. package/dist/web-ui/docs/en/cli/release-notes/v2.6.0.md +5 -0
  390. package/dist/web-ui/docs/en/cli/release-notes/v2.6.1.md +10 -0
  391. package/dist/web-ui/docs/en/cli/release-notes/v2.60.0.md +20 -0
  392. package/dist/web-ui/docs/en/cli/release-notes/v2.61.0.md +29 -0
  393. package/dist/web-ui/docs/en/cli/release-notes/v2.61.1.md +5 -0
  394. package/dist/web-ui/docs/en/cli/release-notes/v2.61.2.md +6 -0
  395. package/dist/web-ui/docs/en/cli/release-notes/v2.61.3.md +13 -0
  396. package/dist/web-ui/docs/en/cli/release-notes/v2.62.0.md +21 -0
  397. package/dist/web-ui/docs/en/cli/release-notes/v2.62.1.md +11 -0
  398. package/dist/web-ui/docs/en/cli/release-notes/v2.63.0.md +19 -0
  399. package/dist/web-ui/docs/en/cli/release-notes/v2.63.1.md +5 -0
  400. package/dist/web-ui/docs/en/cli/release-notes/v2.63.2.md +7 -0
  401. package/dist/web-ui/docs/en/cli/release-notes/v2.63.3.md +6 -0
  402. package/dist/web-ui/docs/en/cli/release-notes/v2.63.4.md +8 -0
  403. package/dist/web-ui/docs/en/cli/release-notes/v2.63.5.md +6 -0
  404. package/dist/web-ui/docs/en/cli/release-notes/v2.64.0.md +37 -0
  405. package/dist/web-ui/docs/en/cli/release-notes/v2.64.1.md +6 -0
  406. package/dist/web-ui/docs/en/cli/release-notes/v2.64.2.md +11 -0
  407. package/dist/web-ui/docs/en/cli/release-notes/v2.65.0.md +19 -0
  408. package/dist/web-ui/docs/en/cli/release-notes/v2.65.1.md +11 -0
  409. package/dist/web-ui/docs/en/cli/release-notes/v2.66.0.md +15 -0
  410. package/dist/web-ui/docs/en/cli/release-notes/v2.66.1.md +14 -0
  411. package/dist/web-ui/docs/en/cli/release-notes/v2.66.2.md +5 -0
  412. package/dist/web-ui/docs/en/cli/release-notes/v2.67.0.md +33 -0
  413. package/dist/web-ui/docs/en/cli/release-notes/v2.7.0.md +16 -0
  414. package/dist/web-ui/docs/en/cli/release-notes/v2.8.0.md +18 -0
  415. package/dist/web-ui/docs/en/cli/release-notes/v2.8.1.md +17 -0
  416. package/dist/web-ui/docs/en/cli/release-notes/v2.8.2.md +5 -0
  417. package/dist/web-ui/docs/en/cli/release-notes/v2.8.3.md +14 -0
  418. package/dist/web-ui/docs/en/cli/release-notes/v2.8.4.md +9 -0
  419. package/dist/web-ui/docs/en/cli/release-notes/v2.8.5.md +5 -0
  420. package/dist/web-ui/docs/en/cli/release-notes/v2.8.6.md +14 -0
  421. package/dist/web-ui/docs/en/cli/release-notes/v2.9.0.md +5 -0
  422. package/dist/web-ui/docs/en/cli/remote-control.md +247 -0
  423. package/dist/web-ui/docs/en/cli/sandboxing.md +316 -0
  424. package/dist/web-ui/docs/en/cli/scheduled-tasks.md +160 -0
  425. package/dist/web-ui/docs/en/cli/sdk-custom-tools.md +1131 -0
  426. package/dist/web-ui/docs/en/cli/sdk-demos.md +347 -0
  427. package/dist/web-ui/docs/en/cli/sdk-hooks.md +813 -0
  428. package/dist/web-ui/docs/en/cli/sdk-mcp.md +645 -0
  429. package/dist/web-ui/docs/en/cli/sdk-permissions.md +461 -0
  430. package/dist/web-ui/docs/en/cli/sdk-python.md +797 -0
  431. package/dist/web-ui/docs/en/cli/sdk-sessions.md +340 -0
  432. package/dist/web-ui/docs/en/cli/sdk-typescript.md +770 -0
  433. package/dist/web-ui/docs/en/cli/sdk.md +1103 -0
  434. package/dist/web-ui/docs/en/cli/security.md +388 -0
  435. package/dist/web-ui/docs/en/cli/settings.md +602 -0
  436. package/dist/web-ui/docs/en/cli/skills.md +448 -0
  437. package/dist/web-ui/docs/en/cli/slash-commands.md +397 -0
  438. package/dist/web-ui/docs/en/cli/statusline.md +525 -0
  439. package/dist/web-ui/docs/en/cli/sub-agents.md +621 -0
  440. package/dist/web-ui/docs/en/cli/terminal-config.md +77 -0
  441. package/dist/web-ui/docs/en/cli/tools-reference.md +99 -0
  442. package/dist/web-ui/docs/en/cli/troubleshooting.md +190 -0
  443. package/dist/web-ui/docs/en/cli/web-ui.md +164 -0
  444. package/dist/web-ui/docs/en/cli/wecom-bot-setup.md +274 -0
  445. package/dist/web-ui/docs/en/cli/worktree.md +660 -0
  446. package/dist/web-ui/docs/search-index-en.json +1 -0
  447. package/dist/web-ui/docs/search-index-zh.json +1 -0
  448. package/dist/web-ui/docs/sidebar-en.json +1 -0
  449. package/dist/web-ui/docs/sidebar-zh.json +1 -0
  450. package/dist/web-ui/index.html +2 -2
  451. package/package.json +1 -1
  452. package/product.cloudhosted.json +2 -2
  453. package/product.internal.json +2 -2
  454. package/product.ioa.json +2 -2
  455. package/product.json +3 -3
  456. package/product.selfhosted.json +2 -2
  457. package/dist/web-ui/assets/index-BPT-qRRx.js +0 -411
  458. package/dist/web-ui/assets/index-f_ibHSHw.css +0 -32
@@ -0,0 +1,1195 @@
1
+ # SDK Custom Tools Guide
2
+
3
+ > **版本要求**:本文档针对 CodeBuddy Agent SDK v0.1.24 及以上版本。
4
+ >
5
+ > **功能状态**:SDK Custom Tools 是 CodeBuddy Agent SDK 的一项 **Preview** 功能。
6
+
7
+ 本文档介绍如何在 CodeBuddy Agent SDK 中创建和使用自定义工具。自定义工具允许你定义专属的功能,让 Agent 能够调用它们来完成特定任务。
8
+
9
+ ## 概述
10
+
11
+ Custom Tools 是 CodeBuddy Agent SDK 提供的一种通过 MCP(Model Context Protocol)创建自定义工具的方式。与配置外部 MCP 服务器不同,Custom Tools 允许你直接在应用程序中定义工具,无需单独的进程或服务器。
12
+
13
+ ### 核心优势
14
+
15
+ - **内进程执行**:工具在应用程序内执行,无需创建独立进程
16
+ - **类型安全**:支持 TypeScript 完整的类型检查和类型推断
17
+ - **简化部署**:无需单独部署 MCP 服务器,一切随应用部署
18
+ - **紧密集成**:与应用程序共享内存和状态
19
+ - **零额外依赖**:利用现有的 SDK 基础设施
20
+
21
+ ## 快速开始
22
+
23
+ ### TypeScript
24
+
25
+ 创建一个简单的计算器工具:
26
+
27
+ ```typescript
28
+ import { query, createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
29
+ import { z } from 'zod';
30
+
31
+ // 创建 MCP 服务器并定义工具
32
+ const calculatorServer = createSdkMcpServer('calculator', {
33
+ tools: [
34
+ tool({
35
+ name: 'add',
36
+ description: 'Add two numbers',
37
+ schema: z.object({
38
+ a: z.number().describe('First number'),
39
+ b: z.number().describe('Second number'),
40
+ }),
41
+ handler: async ({ a, b }) => {
42
+ return { result: a + b };
43
+ },
44
+ }),
45
+ tool({
46
+ name: 'multiply',
47
+ description: 'Multiply two numbers',
48
+ schema: z.object({
49
+ a: z.number().describe('First number'),
50
+ b: z.number().describe('Second number'),
51
+ }),
52
+ handler: async ({ a, b }) => {
53
+ return { result: a * b };
54
+ },
55
+ }),
56
+ ],
57
+ });
58
+
59
+ // 在 SDK 中使用自定义工具
60
+ const result = query({
61
+ prompt: 'Calculate 15 + 27 and then multiply the result by 3',
62
+ options: {
63
+ mcpServers: {
64
+ 'calculator': calculatorServer,
65
+ },
66
+ },
67
+ });
68
+
69
+ for await (const message of result) {
70
+ console.log(message);
71
+ }
72
+ ```
73
+
74
+ ### Python
75
+
76
+ Python SDK 使用装饰器模式定义工具:
77
+
78
+ ```python
79
+ from codebuddy_agent_sdk import query, create_sdk_mcp_server, tool
80
+ from typing import Any
81
+
82
+ # 定义工具
83
+ @tool(
84
+ "add",
85
+ "Add two numbers",
86
+ {"a": float, "b": float}
87
+ )
88
+ async def add(args: dict[str, Any]) -> dict[str, Any]:
89
+ return {'result': args['a'] + args['b']}
90
+
91
+ @tool(
92
+ "multiply",
93
+ "Multiply two numbers",
94
+ {"a": float, "b": float}
95
+ )
96
+ async def multiply(args: dict[str, Any]) -> dict[str, Any]:
97
+ return {'result': args['a'] * args['b']}
98
+
99
+ # 创建 MCP 服务器并注册工具
100
+ calculator_server = create_sdk_mcp_server(
101
+ name='calculator',
102
+ tools=[add, multiply]
103
+ )
104
+
105
+ # 在 SDK 中使用自定义工具
106
+ async def calculate():
107
+ result = query(
108
+ prompt='Calculate 15 + 27 and then multiply the result by 3',
109
+ options={
110
+ 'mcp_servers': {
111
+ 'calculator': calculator_server,
112
+ },
113
+ },
114
+ )
115
+
116
+ async for message in result:
117
+ print(message)
118
+
119
+ # 运行
120
+ import asyncio
121
+ asyncio.run(calculate())
122
+ ```
123
+
124
+ ## 创建自定义工具
125
+
126
+ ### TypeScript - 基本工具定义
127
+
128
+ ```typescript
129
+ import { createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
130
+ import { z } from 'zod';
131
+
132
+ const myServer = createSdkMcpServer('my-tools', {
133
+ tools: [
134
+ tool({
135
+ name: 'my_tool',
136
+ description: 'Description of what the tool does',
137
+ schema: z.object({
138
+ parameter1: z.string().describe('Description of parameter1'),
139
+ parameter2: z.number().optional().describe('Optional parameter'),
140
+ }),
141
+ handler: async (input) => {
142
+ // 实现工具逻辑
143
+ return {
144
+ result: 'Tool output',
145
+ details: input,
146
+ };
147
+ },
148
+ }),
149
+ ],
150
+ });
151
+ ```
152
+
153
+ ### TypeScript - 完整示例:文件分析工具
154
+
155
+ ```typescript
156
+ import { createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
157
+ import { z } from 'zod';
158
+ import * as fs from 'fs/promises';
159
+ import * as path from 'path';
160
+
161
+ const fileAnalysisServer = createSdkMcpServer('file-analysis', {
162
+ tools: [
163
+ tool({
164
+ name: 'count_lines',
165
+ description: 'Count lines in a file',
166
+ schema: z.object({
167
+ filePath: z.string().describe('Path to the file'),
168
+ }),
169
+ handler: async ({ filePath }) => {
170
+ try {
171
+ const content = await fs.readFile(filePath, 'utf-8');
172
+ const lineCount = content.split('\n').length;
173
+ return {
174
+ success: true,
175
+ filePath,
176
+ lineCount,
177
+ };
178
+ } catch (error) {
179
+ return {
180
+ success: false,
181
+ error: error instanceof Error ? error.message : 'Unknown error',
182
+ };
183
+ }
184
+ },
185
+ }),
186
+ tool({
187
+ name: 'list_files',
188
+ description: 'List all files in a directory',
189
+ schema: z.object({
190
+ dirPath: z.string().describe('Path to the directory'),
191
+ pattern: z.string().optional().describe('Optional glob pattern'),
192
+ }),
193
+ handler: async ({ dirPath, pattern }) => {
194
+ try {
195
+ const files = await fs.readdir(dirPath);
196
+
197
+ let filtered = files;
198
+ if (pattern) {
199
+ const minimatch = require('minimatch').minimatch;
200
+ filtered = files.filter(f => minimatch(f, pattern));
201
+ }
202
+
203
+ return {
204
+ success: true,
205
+ dirPath,
206
+ files: filtered,
207
+ count: filtered.length,
208
+ };
209
+ } catch (error) {
210
+ return {
211
+ success: false,
212
+ error: error instanceof Error ? error.message : 'Unknown error',
213
+ };
214
+ }
215
+ },
216
+ }),
217
+ tool({
218
+ name: 'get_file_info',
219
+ description: 'Get information about a file',
220
+ schema: z.object({
221
+ filePath: z.string().describe('Path to the file'),
222
+ }),
223
+ handler: async ({ filePath }) => {
224
+ try {
225
+ const stats = await fs.stat(filePath);
226
+ return {
227
+ success: true,
228
+ filePath,
229
+ size: stats.size,
230
+ created: stats.birthtime,
231
+ modified: stats.mtime,
232
+ isDirectory: stats.isDirectory(),
233
+ isFile: stats.isFile(),
234
+ };
235
+ } catch (error) {
236
+ return {
237
+ success: false,
238
+ error: error instanceof Error ? error.message : 'Unknown error',
239
+ };
240
+ }
241
+ },
242
+ }),
243
+ ],
244
+ });
245
+
246
+ export default fileAnalysisServer;
247
+ ```
248
+
249
+ ### Python - 装饰器模式
250
+
251
+ ```python
252
+ from codebuddy_agent_sdk import create_sdk_mcp_server, tool
253
+ from typing import Any
254
+ import os
255
+
256
+ @tool(
257
+ "count_lines",
258
+ "Count lines in a file",
259
+ {"file_path": str}
260
+ )
261
+ async def count_lines(args: dict[str, Any]) -> dict[str, Any]:
262
+ try:
263
+ with open(args['file_path'], 'r') as f:
264
+ line_count = len(f.readlines())
265
+ return {
266
+ 'success': True,
267
+ 'file_path': args['file_path'],
268
+ 'line_count': line_count,
269
+ }
270
+ except Exception as e:
271
+ return {
272
+ 'success': False,
273
+ 'error': str(e),
274
+ }
275
+
276
+ @tool(
277
+ "list_files",
278
+ "List all files in a directory",
279
+ {"dir_path": str, "pattern": str}
280
+ )
281
+ async def list_files(args: dict[str, Any]) -> dict[str, Any]:
282
+ try:
283
+ files = os.listdir(args['dir_path'])
284
+
285
+ pattern = args.get('pattern')
286
+ if pattern:
287
+ import fnmatch
288
+ files = [f for f in files if fnmatch.fnmatch(f, pattern)]
289
+
290
+ return {
291
+ 'success': True,
292
+ 'dir_path': args['dir_path'],
293
+ 'files': files,
294
+ 'count': len(files),
295
+ }
296
+ except Exception as e:
297
+ return {
298
+ 'success': False,
299
+ 'error': str(e),
300
+ }
301
+
302
+ @tool(
303
+ "get_file_info",
304
+ "Get information about a file",
305
+ {"file_path": str}
306
+ )
307
+ async def get_file_info(args: dict[str, Any]) -> dict[str, Any]:
308
+ try:
309
+ file_path = args['file_path']
310
+ stat = os.stat(file_path)
311
+ return {
312
+ 'success': True,
313
+ 'file_path': file_path,
314
+ 'size': stat.st_size,
315
+ 'created': stat.st_ctime,
316
+ 'modified': stat.st_mtime,
317
+ 'is_file': os.path.isfile(file_path),
318
+ 'is_dir': os.path.isdir(file_path),
319
+ }
320
+ except Exception as e:
321
+ return {
322
+ 'success': False,
323
+ 'error': str(e),
324
+ }
325
+
326
+ # 创建 MCP 服务器并注册工具
327
+ file_analysis_server = create_sdk_mcp_server(
328
+ name='file-analysis',
329
+ tools=[count_lines, list_files, get_file_info]
330
+ )
331
+ ```
332
+
333
+ ## 多个工具管理
334
+
335
+ ### TypeScript
336
+
337
+ ```typescript
338
+ import { createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
339
+ import { z } from 'zod';
340
+
341
+ const multiToolServer = createSdkMcpServer('multi-tools', {
342
+ tools: [
343
+ tool({
344
+ name: 'tool_one',
345
+ description: 'First tool',
346
+ schema: z.object({ input: z.string() }),
347
+ handler: async ({ input }) => ({ result: `Tool 1: ${input}` }),
348
+ }),
349
+ tool({
350
+ name: 'tool_two',
351
+ description: 'Second tool',
352
+ schema: z.object({ data: z.number() }),
353
+ handler: async ({ data }) => ({ result: `Tool 2: ${data * 2}` }),
354
+ }),
355
+ tool({
356
+ name: 'tool_three',
357
+ description: 'Third tool',
358
+ schema: z.object({
359
+ name: z.string(),
360
+ age: z.number().optional(),
361
+ }),
362
+ handler: async ({ name, age }) => ({
363
+ result: `Tool 3: ${name}, age ${age ?? 'unknown'}`,
364
+ }),
365
+ }),
366
+ ],
367
+ });
368
+
369
+ // 在 SDK 中使用
370
+ const result = query({
371
+ prompt: 'Use all the available tools',
372
+ options: {
373
+ mcpServers: {
374
+ 'multi-tools': multiToolServer,
375
+ },
376
+ },
377
+ });
378
+ ```
379
+
380
+ ### Python
381
+
382
+ ```python
383
+ from codebuddy_agent_sdk import create_sdk_mcp_server, tool
384
+ from typing import Any
385
+
386
+ @tool("tool_one", "First tool", {"input": str})
387
+ async def tool_one(args: dict[str, Any]) -> dict[str, Any]:
388
+ return {'result': f"Tool 1: {args['input']}"}
389
+
390
+ @tool("tool_two", "Second tool", {"data": int})
391
+ async def tool_two(args: dict[str, Any]) -> dict[str, Any]:
392
+ return {'result': f"Tool 2: {args['data'] * 2}"}
393
+
394
+ @tool("tool_three", "Third tool", {"name": str, "age": int})
395
+ async def tool_three(args: dict[str, Any]) -> dict[str, Any]:
396
+ age_str = args.get('age', 'unknown')
397
+ return {'result': f"Tool 3: {args['name']}, age {age_str}"}
398
+
399
+ # 创建 MCP 服务器并注册工具
400
+ server = create_sdk_mcp_server(
401
+ name='multi-tools',
402
+ tools=[tool_one, tool_two, tool_three]
403
+ )
404
+ ```
405
+
406
+ ## 类型安全
407
+
408
+ ### TypeScript - 使用 Zod 模式
409
+
410
+ Zod 提供运行时类型验证和强大的类型推断:
411
+
412
+ ```typescript
413
+ import { createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
414
+ import { z } from 'zod';
415
+
416
+ const dataProcessingServer = createSdkMcpServer('data-processing', {
417
+ tools: [
418
+ tool({
419
+ name: 'process_user_data',
420
+ description: 'Process and validate user data',
421
+ schema: z.object({
422
+ userId: z.number().int().positive().describe('User ID'),
423
+ email: z.string().email().describe('User email'),
424
+ tags: z.array(z.string()).describe('User tags'),
425
+ preferences: z.object({
426
+ notifications: z.boolean().default(true),
427
+ theme: z.enum(['light', 'dark', 'auto']).default('auto'),
428
+ }).optional(),
429
+ }),
430
+ handler: async (input) => {
431
+ // input 类型完全由 Zod schema 推断
432
+ // TypeScript 知道所有字段的类型
433
+ const result = {
434
+ userId: input.userId,
435
+ email: input.email,
436
+ tagCount: input.tags.length,
437
+ hasPreferences: !!input.preferences,
438
+ };
439
+ return result;
440
+ },
441
+ }),
442
+ ],
443
+ });
444
+ ```
445
+
446
+ ### Python - 类型注解
447
+
448
+ Python SDK 使用 `@tool` 装饰器定义工具,支持简单类型映射或 JSON Schema:
449
+
450
+ ```python
451
+ from codebuddy_agent_sdk import create_sdk_mcp_server, tool
452
+ from typing import Any
453
+
454
+ # 使用 JSON Schema 进行高级验证
455
+ @tool(
456
+ "process_user_data",
457
+ "Process and validate user data",
458
+ {
459
+ "type": "object",
460
+ "properties": {
461
+ "user_id": {"type": "integer", "minimum": 1},
462
+ "email": {"type": "string", "format": "email"},
463
+ "tags": {"type": "array", "items": {"type": "string"}},
464
+ "notifications": {"type": "boolean", "default": True},
465
+ "theme": {"type": "string", "enum": ["light", "dark", "auto"], "default": "auto"}
466
+ },
467
+ "required": ["user_id", "email", "tags"]
468
+ }
469
+ )
470
+ async def process_user_data(args: dict[str, Any]) -> dict[str, Any]:
471
+ return {
472
+ 'user_id': args['user_id'],
473
+ 'email': args['email'],
474
+ 'tag_count': len(args['tags']),
475
+ 'theme': args.get('theme', 'auto'),
476
+ 'notifications': args.get('notifications', True),
477
+ }
478
+
479
+ # 创建 MCP 服务器并注册工具
480
+ server = create_sdk_mcp_server(
481
+ name='data-processing',
482
+ tools=[process_user_data]
483
+ )
484
+ ```
485
+
486
+ ## 完整示例:数据库查询工具
487
+
488
+ ### TypeScript
489
+
490
+ ```typescript
491
+ import { createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
492
+ import { z } from 'zod';
493
+
494
+ interface QueryResult {
495
+ rows: Record<string, any>[];
496
+ rowCount: number;
497
+ }
498
+
499
+ interface Database {
500
+ query(sql: string, params?: any[]): Promise<QueryResult>;
501
+ }
502
+
503
+ // 假设你已有数据库连接
504
+ const db: Database = new Database();
505
+
506
+ const databaseServer = createSdkMcpServer('database', {
507
+ tools: [
508
+ tool({
509
+ name: 'execute_query',
510
+ description: 'Execute a read-only SQL query',
511
+ schema: z.object({
512
+ sql: z.string().describe('SQL query to execute'),
513
+ params: z.array(z.any()).optional().describe('Query parameters'),
514
+ }),
515
+ handler: async ({ sql, params }) => {
516
+ try {
517
+ // 防止危险操作
518
+ const upperSql = sql.toUpperCase();
519
+ if (
520
+ upperSql.includes('DROP') ||
521
+ upperSql.includes('DELETE') ||
522
+ upperSql.includes('UPDATE') ||
523
+ upperSql.includes('INSERT')
524
+ ) {
525
+ return {
526
+ success: false,
527
+ error: 'Only SELECT queries are allowed',
528
+ };
529
+ }
530
+
531
+ const result = await db.query(sql, params);
532
+ return {
533
+ success: true,
534
+ rows: result.rows,
535
+ rowCount: result.rowCount,
536
+ };
537
+ } catch (error) {
538
+ return {
539
+ success: false,
540
+ error: error instanceof Error ? error.message : 'Query execution failed',
541
+ };
542
+ }
543
+ },
544
+ }),
545
+ tool({
546
+ name: 'get_table_schema',
547
+ description: 'Get the schema of a table',
548
+ schema: z.object({
549
+ tableName: z.string().describe('Name of the table'),
550
+ }),
551
+ handler: async ({ tableName }) => {
552
+ try {
553
+ const result = await db.query(
554
+ `SELECT column_name, data_type FROM information_schema.columns WHERE table_name = $1`,
555
+ [tableName]
556
+ );
557
+ return {
558
+ success: true,
559
+ tableName,
560
+ columns: result.rows,
561
+ };
562
+ } catch (error) {
563
+ return {
564
+ success: false,
565
+ error: error instanceof Error ? error.message : 'Schema retrieval failed',
566
+ };
567
+ }
568
+ },
569
+ }),
570
+ ],
571
+ });
572
+ ```
573
+
574
+ ### Python
575
+
576
+ ```python
577
+ from codebuddy_agent_sdk import create_sdk_mcp_server, tool
578
+ from typing import Any
579
+
580
+ class Database:
581
+ """Simplified database wrapper"""
582
+ async def query(self, sql: str, params: list[Any] = None) -> dict[str, Any]:
583
+ # 实现实际的数据库查询
584
+ pass
585
+
586
+ db = Database()
587
+
588
+ @tool(
589
+ "execute_query",
590
+ "Execute a read-only SQL query",
591
+ {"sql": str, "params": list}
592
+ )
593
+ async def execute_query(args: dict[str, Any]) -> dict[str, Any]:
594
+ try:
595
+ sql = args['sql']
596
+ params = args.get('params')
597
+
598
+ # 防止危险操作
599
+ dangerous_keywords = ['DROP', 'DELETE', 'UPDATE', 'INSERT']
600
+ if any(keyword in sql.upper() for keyword in dangerous_keywords):
601
+ return {
602
+ 'success': False,
603
+ 'error': 'Only SELECT queries are allowed',
604
+ }
605
+
606
+ result = await db.query(sql, params)
607
+ return {
608
+ 'success': True,
609
+ 'rows': result.get('rows', []),
610
+ 'row_count': result.get('row_count', 0),
611
+ }
612
+ except Exception as e:
613
+ return {
614
+ 'success': False,
615
+ 'error': str(e),
616
+ }
617
+
618
+ @tool(
619
+ "get_table_schema",
620
+ "Get the schema of a table",
621
+ {"table_name": str}
622
+ )
623
+ async def get_table_schema(args: dict[str, Any]) -> dict[str, Any]:
624
+ try:
625
+ table_name = args['table_name']
626
+ result = await db.query(
627
+ 'SELECT column_name, data_type FROM information_schema.columns WHERE table_name = %s',
628
+ [table_name]
629
+ )
630
+ return {
631
+ 'success': True,
632
+ 'table_name': table_name,
633
+ 'columns': result.get('rows', []),
634
+ }
635
+ except Exception as e:
636
+ return {
637
+ 'success': False,
638
+ 'error': str(e),
639
+ }
640
+
641
+ # 创建 MCP 服务器并注册工具
642
+ server = create_sdk_mcp_server(
643
+ name='database',
644
+ tools=[execute_query, get_table_schema]
645
+ )
646
+ ```
647
+
648
+ ## 完整示例:API 集成工具
649
+
650
+ ### TypeScript
651
+
652
+ ```typescript
653
+ import { createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
654
+ import { z } from 'zod';
655
+
656
+ const apiGatewayServer = createSdkMcpServer('api-gateway', {
657
+ tools: [
658
+ tool({
659
+ name: 'stripe_create_payment',
660
+ description: 'Create a payment through Stripe',
661
+ schema: z.object({
662
+ amount: z.number().positive().describe('Amount in cents'),
663
+ currency: z.string().default('usd').describe('Currency code'),
664
+ description: z.string().optional().describe('Payment description'),
665
+ }),
666
+ handler: async ({ amount, currency, description }) => {
667
+ try {
668
+ const response = await fetch('https://api.stripe.com/v1/payment_intents', {
669
+ method: 'POST',
670
+ headers: {
671
+ 'Authorization': `Bearer ${process.env.STRIPE_API_KEY}`,
672
+ 'Content-Type': 'application/x-www-form-urlencoded',
673
+ },
674
+ body: new URLSearchParams({
675
+ amount: amount.toString(),
676
+ currency,
677
+ ...(description && { description }),
678
+ }),
679
+ });
680
+
681
+ if (!response.ok) {
682
+ const error = await response.json();
683
+ return {
684
+ success: false,
685
+ error: error.error?.message || 'Payment creation failed',
686
+ };
687
+ }
688
+
689
+ const data = await response.json();
690
+ return {
691
+ success: true,
692
+ paymentId: data.id,
693
+ status: data.status,
694
+ clientSecret: data.client_secret,
695
+ };
696
+ } catch (error) {
697
+ return {
698
+ success: false,
699
+ error: error instanceof Error ? error.message : 'Unknown error',
700
+ };
701
+ }
702
+ },
703
+ }),
704
+ tool({
705
+ name: 'github_search_repos',
706
+ description: 'Search repositories on GitHub',
707
+ schema: z.object({
708
+ query: z.string().describe('Search query'),
709
+ language: z.string().optional().describe('Programming language'),
710
+ sort: z.enum(['stars', 'forks', 'updated']).default('stars'),
711
+ }),
712
+ handler: async ({ query, language, sort }) => {
713
+ try {
714
+ const searchQuery = language
715
+ ? `${query} language:${language}`
716
+ : query;
717
+
718
+ const response = await fetch(
719
+ `https://api.github.com/search/repositories?q=${encodeURIComponent(
720
+ searchQuery
721
+ )}&sort=${sort}`,
722
+ {
723
+ headers: {
724
+ 'Authorization': `Bearer ${process.env.GITHUB_TOKEN}`,
725
+ },
726
+ }
727
+ );
728
+
729
+ if (!response.ok) {
730
+ return {
731
+ success: false,
732
+ error: `GitHub API error: ${response.status}`,
733
+ };
734
+ }
735
+
736
+ const data = await response.json();
737
+ return {
738
+ success: true,
739
+ repos: data.items.map((repo: any) => ({
740
+ name: repo.name,
741
+ url: repo.html_url,
742
+ stars: repo.stargazers_count,
743
+ language: repo.language,
744
+ description: repo.description,
745
+ })),
746
+ total: data.total_count,
747
+ };
748
+ } catch (error) {
749
+ return {
750
+ success: false,
751
+ error: error instanceof Error ? error.message : 'Unknown error',
752
+ };
753
+ }
754
+ },
755
+ }),
756
+ tool({
757
+ name: 'slack_send_message',
758
+ description: 'Send a message to a Slack channel',
759
+ schema: z.object({
760
+ channel: z.string().describe('Channel ID or name'),
761
+ text: z.string().describe('Message text'),
762
+ thread_ts: z.string().optional().describe('Thread timestamp (for replies)'),
763
+ }),
764
+ handler: async ({ channel, text, thread_ts }) => {
765
+ try {
766
+ const payload: Record<string, any> = {
767
+ channel,
768
+ text,
769
+ };
770
+ if (thread_ts) {
771
+ payload.thread_ts = thread_ts;
772
+ }
773
+
774
+ const response = await fetch('https://slack.com/api/chat.postMessage', {
775
+ method: 'POST',
776
+ headers: {
777
+ 'Authorization': `Bearer ${process.env.SLACK_BOT_TOKEN}`,
778
+ 'Content-Type': 'application/json',
779
+ },
780
+ body: JSON.stringify(payload),
781
+ });
782
+
783
+ const data = await response.json();
784
+ if (!data.ok) {
785
+ return {
786
+ success: false,
787
+ error: data.error || 'Failed to send message',
788
+ };
789
+ }
790
+
791
+ return {
792
+ success: true,
793
+ messageTs: data.ts,
794
+ channel: data.channel,
795
+ };
796
+ } catch (error) {
797
+ return {
798
+ success: false,
799
+ error: error instanceof Error ? error.message : 'Unknown error',
800
+ };
801
+ }
802
+ },
803
+ }),
804
+ ],
805
+ });
806
+
807
+ export default apiGatewayServer;
808
+ ```
809
+
810
+ ### Python
811
+
812
+ ```python
813
+ from codebuddy_agent_sdk import create_sdk_mcp_server, tool
814
+ from typing import Any
815
+ import requests
816
+ import os
817
+
818
+ @tool(
819
+ "stripe_create_payment",
820
+ "Create a payment through Stripe",
821
+ {"amount": float, "currency": str, "description": str}
822
+ )
823
+ async def stripe_create_payment(args: dict[str, Any]) -> dict[str, Any]:
824
+ try:
825
+ headers = {
826
+ 'Authorization': f"Bearer {os.environ.get('STRIPE_API_KEY')}",
827
+ }
828
+ data = {
829
+ 'amount': int(args['amount']),
830
+ 'currency': args.get('currency', 'usd'),
831
+ }
832
+ description = args.get('description')
833
+ if description:
834
+ data['description'] = description
835
+
836
+ response = requests.post(
837
+ 'https://api.stripe.com/v1/payment_intents',
838
+ headers=headers,
839
+ data=data,
840
+ )
841
+
842
+ if response.status_code >= 400:
843
+ error = response.json().get('error', {})
844
+ return {
845
+ 'success': False,
846
+ 'error': error.get('message', 'Payment creation failed'),
847
+ }
848
+
849
+ resp_data = response.json()
850
+ return {
851
+ 'success': True,
852
+ 'payment_id': resp_data['id'],
853
+ 'status': resp_data['status'],
854
+ 'client_secret': resp_data.get('client_secret'),
855
+ }
856
+ except Exception as e:
857
+ return {
858
+ 'success': False,
859
+ 'error': str(e),
860
+ }
861
+
862
+ @tool(
863
+ "github_search_repos",
864
+ "Search repositories on GitHub",
865
+ {"query": str, "language": str, "sort": str}
866
+ )
867
+ async def github_search_repos(args: dict[str, Any]) -> dict[str, Any]:
868
+ try:
869
+ query = args['query']
870
+ language = args.get('language')
871
+ sort = args.get('sort', 'stars')
872
+
873
+ search_query = f"{query} language:{language}" if language else query
874
+
875
+ response = requests.get(
876
+ 'https://api.github.com/search/repositories',
877
+ params={
878
+ 'q': search_query,
879
+ 'sort': sort,
880
+ },
881
+ headers={
882
+ 'Authorization': f"Bearer {os.environ.get('GITHUB_TOKEN')}",
883
+ },
884
+ )
885
+
886
+ if response.status_code >= 400:
887
+ return {
888
+ 'success': False,
889
+ 'error': f"GitHub API error: {response.status_code}",
890
+ }
891
+
892
+ data = response.json()
893
+ repos = [
894
+ {
895
+ 'name': repo['name'],
896
+ 'url': repo['html_url'],
897
+ 'stars': repo['stargazers_count'],
898
+ 'language': repo['language'],
899
+ 'description': repo['description'],
900
+ }
901
+ for repo in data.get('items', [])
902
+ ]
903
+
904
+ return {
905
+ 'success': True,
906
+ 'repos': repos,
907
+ 'total': data.get('total_count', 0),
908
+ }
909
+ except Exception as e:
910
+ return {
911
+ 'success': False,
912
+ 'error': str(e),
913
+ }
914
+
915
+ @tool(
916
+ "slack_send_message",
917
+ "Send a message to a Slack channel",
918
+ {"channel": str, "text": str, "thread_ts": str}
919
+ )
920
+ async def slack_send_message(args: dict[str, Any]) -> dict[str, Any]:
921
+ try:
922
+ payload = {
923
+ 'channel': args['channel'],
924
+ 'text': args['text'],
925
+ }
926
+ thread_ts = args.get('thread_ts')
927
+ if thread_ts:
928
+ payload['thread_ts'] = thread_ts
929
+
930
+ response = requests.post(
931
+ 'https://slack.com/api/chat.postMessage',
932
+ headers={
933
+ 'Authorization': f"Bearer {os.environ.get('SLACK_BOT_TOKEN')}",
934
+ 'Content-Type': 'application/json',
935
+ },
936
+ json=payload,
937
+ )
938
+
939
+ data = response.json()
940
+ if not data.get('ok'):
941
+ return {
942
+ 'success': False,
943
+ 'error': data.get('error', 'Failed to send message'),
944
+ }
945
+
946
+ return {
947
+ 'success': True,
948
+ 'message_ts': data['ts'],
949
+ 'channel': data['channel'],
950
+ }
951
+ except Exception as e:
952
+ return {
953
+ 'success': False,
954
+ 'error': str(e),
955
+ }
956
+
957
+ # 创建 MCP 服务器并注册工具
958
+ server = create_sdk_mcp_server(
959
+ name='api-gateway',
960
+ tools=[stripe_create_payment, github_search_repos, slack_send_message]
961
+ )
962
+ ```
963
+
964
+ ## 选择性地允许工具
965
+
966
+ 你可以选择性地允许特定工具被调用:
967
+
968
+ ### TypeScript
969
+
970
+ ```typescript
971
+ import { query, createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
972
+ import { z } from 'zod';
973
+
974
+ const result = query({
975
+ prompt: 'Search for popular repositories and send a message to Slack',
976
+ options: {
977
+ mcpServers: {
978
+ 'api-gateway': apiGatewayServer,
979
+ },
980
+ canUseTool: (toolCall) => {
981
+ // 只允许 GitHub 搜索工具
982
+ const allowedTools = [
983
+ 'mcp__api-gateway__github_search_repos',
984
+ ];
985
+
986
+ if (!allowedTools.includes(toolCall.name)) {
987
+ return false;
988
+ }
989
+ return true;
990
+ },
991
+ },
992
+ });
993
+ ```
994
+
995
+ ### Python
996
+
997
+ ```python
998
+ from codebuddy_agent_sdk import query
999
+ from api_gateway_server import server as api_gateway_server
1000
+
1001
+ async def main():
1002
+ result = query(
1003
+ prompt='Search for popular repositories and send a message to Slack',
1004
+ options={
1005
+ 'mcp_servers': {
1006
+ 'api-gateway': api_gateway_server,
1007
+ },
1008
+ 'can_use_tool': lambda tool_call: (
1009
+ # 只允许 GitHub 搜索工具
1010
+ tool_call.get('name') == 'mcp__api-gateway__github_search_repos'
1011
+ ),
1012
+ },
1013
+ )
1014
+
1015
+ async for message in result:
1016
+ print(message)
1017
+
1018
+ import asyncio
1019
+ asyncio.run(main())
1020
+ ```
1021
+
1022
+ ## 错误处理
1023
+
1024
+ ### TypeScript - API 调用错误处理
1025
+
1026
+ ```typescript
1027
+ import { createSdkMcpServer, tool } from '@tencent-ai/agent-sdk';
1028
+ import { z } from 'zod';
1029
+
1030
+ const apiServer = createSdkMcpServer('api-tools', {
1031
+ tools: [
1032
+ tool({
1033
+ name: 'fetch_data',
1034
+ description: 'Fetch data from an API',
1035
+ schema: z.object({
1036
+ endpoint: z.string().url().describe('API endpoint URL'),
1037
+ }),
1038
+ handler: async ({ endpoint }) => {
1039
+ try {
1040
+ const response = await fetch(endpoint);
1041
+ if (!response.ok) {
1042
+ return {
1043
+ content: [{
1044
+ type: 'text',
1045
+ text: `API error: ${response.status} ${response.statusText}`,
1046
+ }],
1047
+ };
1048
+ }
1049
+ const data = await response.json();
1050
+ return {
1051
+ content: [{
1052
+ type: 'text',
1053
+ text: JSON.stringify(data, null, 2),
1054
+ }],
1055
+ };
1056
+ } catch (error) {
1057
+ return {
1058
+ content: [{
1059
+ type: 'text',
1060
+ text: `Failed to fetch data: ${error instanceof Error ? error.message : String(error)}`,
1061
+ }],
1062
+ };
1063
+ }
1064
+ },
1065
+ }),
1066
+ ],
1067
+ });
1068
+ ```
1069
+
1070
+ ### Python - API 调用错误处理
1071
+
1072
+ ```python
1073
+ from codebuddy_agent_sdk import create_sdk_mcp_server, tool
1074
+ from typing import Any
1075
+ import aiohttp
1076
+ import json
1077
+
1078
+ @tool(
1079
+ "fetch_data",
1080
+ "Fetch data from an API",
1081
+ {"endpoint": str}
1082
+ )
1083
+ async def fetch_data(args: dict[str, Any]) -> dict[str, Any]:
1084
+ try:
1085
+ async with aiohttp.ClientSession() as session:
1086
+ async with session.get(args['endpoint']) as response:
1087
+ if response.status != 200:
1088
+ return {
1089
+ 'content': [{
1090
+ 'type': 'text',
1091
+ 'text': f'API error: {response.status} {response.reason}'
1092
+ }]
1093
+ }
1094
+ data = await response.json()
1095
+ return {
1096
+ 'content': [{
1097
+ 'type': 'text',
1098
+ 'text': json.dumps(data, indent=2)
1099
+ }]
1100
+ }
1101
+ except Exception as e:
1102
+ return {
1103
+ 'content': [{
1104
+ 'type': 'text',
1105
+ 'text': f'Failed to fetch data: {str(e)}'
1106
+ }]
1107
+ }
1108
+
1109
+ # 创建 MCP 服务器并注册工具
1110
+ server = create_sdk_mcp_server(
1111
+ name='api-tools',
1112
+ tools=[fetch_data]
1113
+ )
1114
+ ```
1115
+
1116
+ ## 最佳实践
1117
+
1118
+ ### 1. 使用明确的参数类型和描述
1119
+
1120
+ 为工具参数提供清晰的类型和描述,帮助 Agent 理解如何调用工具:
1121
+
1122
+ ```typescript
1123
+ tool({
1124
+ name: 'process_data',
1125
+ schema: z.object({
1126
+ data: z.array(z.string()).describe('Data to process'),
1127
+ format: z.enum(['json', 'csv']).describe('Output format'),
1128
+ }),
1129
+ handler: async ({ data, format }) => {
1130
+ // 处理逻辑
1131
+ },
1132
+ })
1133
+ ```
1134
+
1135
+ ### 2. 提供有意义的错误反馈
1136
+
1137
+ 始终返回明确的错误信息,以便 Agent 和用户理解发生了什么:
1138
+
1139
+ ```typescript
1140
+ handler: async (input) => {
1141
+ try {
1142
+ // 执行操作
1143
+ } catch (error) {
1144
+ return {
1145
+ content: [{
1146
+ type: 'text',
1147
+ text: `Operation failed: ${error instanceof Error ? error.message : String(error)}`,
1148
+ }],
1149
+ };
1150
+ }
1151
+ }
1152
+ ```
1153
+
1154
+ ### 3. 验证输入参数
1155
+
1156
+ 确保输入符合预期的格式和范围:
1157
+
1158
+ ```typescript
1159
+ handler: async ({ userId, email }) => {
1160
+ if (!Number.isInteger(userId) || userId <= 0) {
1161
+ return {
1162
+ content: [{
1163
+ type: 'text',
1164
+ text: 'Error: User ID must be a positive integer',
1165
+ }],
1166
+ };
1167
+ }
1168
+
1169
+ if (!email.includes('@')) {
1170
+ return {
1171
+ content: [{
1172
+ type: 'text',
1173
+ text: 'Error: Invalid email format',
1174
+ }],
1175
+ };
1176
+ }
1177
+
1178
+ // 继续处理
1179
+ }
1180
+ ```
1181
+
1182
+ ## 相关文档
1183
+
1184
+ - [SDK 概览](sdk.md)
1185
+ - [SDK MCP 集成](sdk-mcp.md)
1186
+ - [TypeScript SDK 参考](sdk-typescript.md)
1187
+ - [Python SDK 参考](sdk-python.md)
1188
+ - [SDK 权限系统](sdk-permissions.md)
1189
+
1190
+ ## 更多资源
1191
+
1192
+ - [MCP 官方文档](https://modelcontextprotocol.io/)
1193
+ - [MCP Python SDK - FastMCP](https://github.com/modelcontextprotocol/python-sdk)
1194
+ - [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
1195
+ - [Zod 验证库](https://zod.dev/)