@codeqr/ts-mcp 0.8.0 → 0.19.3

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 (477) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +16 -218
  3. package/auth.d.mts +6 -0
  4. package/auth.d.mts.map +1 -0
  5. package/auth.d.ts +6 -0
  6. package/auth.d.ts.map +1 -0
  7. package/auth.js +37 -0
  8. package/auth.js.map +1 -0
  9. package/{headers.mjs → auth.mjs} +16 -2
  10. package/auth.mjs.map +1 -0
  11. package/code-tool-paths.cjs +4 -2
  12. package/code-tool-paths.cjs.map +1 -1
  13. package/code-tool-paths.d.cts +1 -1
  14. package/code-tool-paths.d.cts.map +1 -1
  15. package/code-tool-types.d.mts +7 -9
  16. package/code-tool-types.d.mts.map +1 -1
  17. package/code-tool-types.d.ts +7 -9
  18. package/code-tool-types.d.ts.map +1 -1
  19. package/code-tool-worker.d.mts.map +1 -1
  20. package/code-tool-worker.d.ts.map +1 -1
  21. package/code-tool-worker.js +95 -32
  22. package/code-tool-worker.js.map +1 -1
  23. package/code-tool-worker.mjs +95 -32
  24. package/code-tool-worker.mjs.map +1 -1
  25. package/code-tool.d.mts +12 -3
  26. package/code-tool.d.mts.map +1 -1
  27. package/code-tool.d.ts +12 -3
  28. package/code-tool.d.ts.map +1 -1
  29. package/code-tool.js +275 -109
  30. package/code-tool.js.map +1 -1
  31. package/code-tool.mjs +275 -109
  32. package/code-tool.mjs.map +1 -1
  33. package/docs-search-tool.d.mts +22 -9
  34. package/docs-search-tool.d.mts.map +1 -1
  35. package/docs-search-tool.d.ts +22 -9
  36. package/docs-search-tool.d.ts.map +1 -1
  37. package/docs-search-tool.js +31 -5
  38. package/docs-search-tool.js.map +1 -1
  39. package/docs-search-tool.mjs +31 -5
  40. package/docs-search-tool.mjs.map +1 -1
  41. package/http.d.mts +6 -3
  42. package/http.d.mts.map +1 -1
  43. package/http.d.ts +6 -3
  44. package/http.d.ts.map +1 -1
  45. package/http.js +108 -49
  46. package/http.js.map +1 -1
  47. package/http.mjs +108 -49
  48. package/http.mjs.map +1 -1
  49. package/index.js +19 -50
  50. package/index.js.map +1 -1
  51. package/index.mjs +19 -50
  52. package/index.mjs.map +1 -1
  53. package/instructions.d.mts +2 -0
  54. package/instructions.d.mts.map +1 -0
  55. package/instructions.d.ts +2 -0
  56. package/instructions.d.ts.map +1 -0
  57. package/instructions.js +42 -0
  58. package/instructions.js.map +1 -0
  59. package/instructions.mjs +39 -0
  60. package/instructions.mjs.map +1 -0
  61. package/logger.d.mts +7 -0
  62. package/logger.d.mts.map +1 -0
  63. package/logger.d.ts +7 -0
  64. package/logger.d.ts.map +1 -0
  65. package/logger.js +29 -0
  66. package/logger.js.map +1 -0
  67. package/logger.mjs +22 -0
  68. package/logger.mjs.map +1 -0
  69. package/methods.d.mts +10 -0
  70. package/methods.d.mts.map +1 -0
  71. package/methods.d.ts +10 -0
  72. package/methods.d.ts.map +1 -0
  73. package/methods.js +215 -0
  74. package/methods.js.map +1 -0
  75. package/methods.mjs +211 -0
  76. package/methods.mjs.map +1 -0
  77. package/options.d.mts +9 -9
  78. package/options.d.mts.map +1 -1
  79. package/options.d.ts +9 -9
  80. package/options.d.ts.map +1 -1
  81. package/options.js +54 -359
  82. package/options.js.map +1 -1
  83. package/options.mjs +54 -359
  84. package/options.mjs.map +1 -1
  85. package/package.json +67 -60
  86. package/server.d.mts +11 -16
  87. package/server.d.mts.map +1 -1
  88. package/server.d.ts +11 -16
  89. package/server.d.ts.map +1 -1
  90. package/server.js +86 -101
  91. package/server.js.map +1 -1
  92. package/server.mjs +85 -96
  93. package/server.mjs.map +1 -1
  94. package/src/{headers.ts → auth.ts} +18 -1
  95. package/src/code-tool-paths.cts +3 -1
  96. package/src/code-tool-types.ts +8 -9
  97. package/src/code-tool-worker.ts +110 -47
  98. package/src/code-tool.ts +362 -134
  99. package/src/docs-search-tool.ts +54 -6
  100. package/src/http.ts +128 -54
  101. package/src/index.ts +22 -63
  102. package/src/instructions.ts +60 -0
  103. package/src/logger.ts +28 -0
  104. package/src/methods.ts +236 -0
  105. package/src/options.ts +72 -384
  106. package/src/server.ts +99 -116
  107. package/src/stdio.ts +6 -5
  108. package/src/{tools/types.ts → types.ts} +14 -5
  109. package/src/util.ts +25 -0
  110. package/stdio.d.mts +1 -1
  111. package/stdio.d.mts.map +1 -1
  112. package/stdio.d.ts +1 -1
  113. package/stdio.d.ts.map +1 -1
  114. package/stdio.js +5 -4
  115. package/stdio.js.map +1 -1
  116. package/stdio.mjs +5 -4
  117. package/stdio.mjs.map +1 -1
  118. package/{tools/types.d.mts → types.d.mts} +10 -2
  119. package/types.d.mts.map +1 -0
  120. package/{tools/types.d.ts → types.d.ts} +10 -2
  121. package/types.d.ts.map +1 -0
  122. package/types.js.map +1 -0
  123. package/types.mjs.map +1 -0
  124. package/util.d.mts +4 -0
  125. package/util.d.mts.map +1 -0
  126. package/util.d.ts +4 -0
  127. package/util.d.ts.map +1 -0
  128. package/util.js +30 -0
  129. package/util.js.map +1 -0
  130. package/util.mjs +24 -0
  131. package/util.mjs.map +1 -0
  132. package/compat.d.mts +0 -58
  133. package/compat.d.mts.map +0 -1
  134. package/compat.d.ts +0 -58
  135. package/compat.d.ts.map +0 -1
  136. package/compat.js +0 -387
  137. package/compat.js.map +0 -1
  138. package/compat.mjs +0 -378
  139. package/compat.mjs.map +0 -1
  140. package/dynamic-tools.d.mts +0 -12
  141. package/dynamic-tools.d.mts.map +0 -1
  142. package/dynamic-tools.d.ts +0 -12
  143. package/dynamic-tools.d.ts.map +0 -1
  144. package/dynamic-tools.js +0 -135
  145. package/dynamic-tools.js.map +0 -1
  146. package/dynamic-tools.mjs +0 -132
  147. package/dynamic-tools.mjs.map +0 -1
  148. package/filtering.d.mts +0 -3
  149. package/filtering.d.mts.map +0 -1
  150. package/filtering.d.ts +0 -3
  151. package/filtering.d.ts.map +0 -1
  152. package/filtering.js +0 -24
  153. package/filtering.js.map +0 -1
  154. package/filtering.mjs +0 -16
  155. package/filtering.mjs.map +0 -1
  156. package/headers.d.mts +0 -4
  157. package/headers.d.mts.map +0 -1
  158. package/headers.d.ts +0 -4
  159. package/headers.d.ts.map +0 -1
  160. package/headers.js +0 -22
  161. package/headers.js.map +0 -1
  162. package/headers.mjs.map +0 -1
  163. package/src/compat.ts +0 -483
  164. package/src/dynamic-tools.ts +0 -153
  165. package/src/filtering.ts +0 -18
  166. package/src/tools/analytics/retrieve-analytics.ts +0 -441
  167. package/src/tools/domains/create-domains.ts +0 -75
  168. package/src/tools/domains/delete-domains.ts +0 -55
  169. package/src/tools/domains/list-domains.ts +0 -68
  170. package/src/tools/domains/update-domains.ts +0 -79
  171. package/src/tools/events/list-events.ts +0 -421
  172. package/src/tools/index.ts +0 -133
  173. package/src/tools/links/bulk/create-links-bulk.ts +0 -966
  174. package/src/tools/links/bulk/delete-links-bulk.ts +0 -59
  175. package/src/tools/links/count-links.ts +0 -957
  176. package/src/tools/links/create-links.ts +0 -957
  177. package/src/tools/links/delete-links.ts +0 -56
  178. package/src/tools/links/list-links.ts +0 -980
  179. package/src/tools/links/retrieve-info-links.ts +0 -75
  180. package/src/tools/links/update-links.ts +0 -964
  181. package/src/tools/links/upsert-links.ts +0 -958
  182. package/src/tools/projects/list-projects.ts +0 -51
  183. package/src/tools/projects/retrieve-projects.ts +0 -56
  184. package/src/tools/qrcodes/bulk/create-qrcodes-bulk.ts +0 -1077
  185. package/src/tools/qrcodes/bulk/delete-qrcodes-bulk.ts +0 -59
  186. package/src/tools/qrcodes/count-qrcodes.ts +0 -220
  187. package/src/tools/qrcodes/create-qrcodes.ts +0 -1067
  188. package/src/tools/qrcodes/delete-qrcodes.ts +0 -56
  189. package/src/tools/qrcodes/list-qrcodes.ts +0 -221
  190. package/src/tools/qrcodes/retrieve-qrcodes.ts +0 -67
  191. package/src/tools/qrcodes/update-qrcodes.ts +0 -1074
  192. package/src/tools/qrcodes/upsert-qrcodes.ts +0 -1068
  193. package/src/tools/tags/create-tags.ts +0 -59
  194. package/src/tools/tags/delete-tags.ts +0 -55
  195. package/src/tools/tags/list-tags.ts +0 -87
  196. package/src/tools/tags/update-tags.ts +0 -63
  197. package/src/tools/track/track-lead-track.ts +0 -93
  198. package/src/tools/track/track-sale-track.ts +0 -108
  199. package/src/tools.ts +0 -1
  200. package/tools/analytics/retrieve-analytics.d.mts +0 -45
  201. package/tools/analytics/retrieve-analytics.d.mts.map +0 -1
  202. package/tools/analytics/retrieve-analytics.d.ts +0 -45
  203. package/tools/analytics/retrieve-analytics.d.ts.map +0 -1
  204. package/tools/analytics/retrieve-analytics.js +0 -438
  205. package/tools/analytics/retrieve-analytics.js.map +0 -1
  206. package/tools/analytics/retrieve-analytics.mjs +0 -431
  207. package/tools/analytics/retrieve-analytics.mjs.map +0 -1
  208. package/tools/domains/create-domains.d.mts +0 -45
  209. package/tools/domains/create-domains.d.mts.map +0 -1
  210. package/tools/domains/create-domains.d.ts +0 -45
  211. package/tools/domains/create-domains.d.ts.map +0 -1
  212. package/tools/domains/create-domains.js +0 -74
  213. package/tools/domains/create-domains.js.map +0 -1
  214. package/tools/domains/create-domains.mjs +0 -67
  215. package/tools/domains/create-domains.mjs.map +0 -1
  216. package/tools/domains/delete-domains.d.mts +0 -45
  217. package/tools/domains/delete-domains.d.mts.map +0 -1
  218. package/tools/domains/delete-domains.d.ts +0 -45
  219. package/tools/domains/delete-domains.d.ts.map +0 -1
  220. package/tools/domains/delete-domains.js +0 -55
  221. package/tools/domains/delete-domains.js.map +0 -1
  222. package/tools/domains/delete-domains.mjs +0 -48
  223. package/tools/domains/delete-domains.mjs.map +0 -1
  224. package/tools/domains/list-domains.d.mts +0 -45
  225. package/tools/domains/list-domains.d.mts.map +0 -1
  226. package/tools/domains/list-domains.d.ts +0 -45
  227. package/tools/domains/list-domains.d.ts.map +0 -1
  228. package/tools/domains/list-domains.js +0 -67
  229. package/tools/domains/list-domains.js.map +0 -1
  230. package/tools/domains/list-domains.mjs +0 -60
  231. package/tools/domains/list-domains.mjs.map +0 -1
  232. package/tools/domains/update-domains.d.mts +0 -45
  233. package/tools/domains/update-domains.d.mts.map +0 -1
  234. package/tools/domains/update-domains.d.ts +0 -45
  235. package/tools/domains/update-domains.d.ts.map +0 -1
  236. package/tools/domains/update-domains.js +0 -78
  237. package/tools/domains/update-domains.js.map +0 -1
  238. package/tools/domains/update-domains.mjs +0 -71
  239. package/tools/domains/update-domains.mjs.map +0 -1
  240. package/tools/events/list-events.d.mts +0 -45
  241. package/tools/events/list-events.d.mts.map +0 -1
  242. package/tools/events/list-events.d.ts +0 -45
  243. package/tools/events/list-events.d.ts.map +0 -1
  244. package/tools/events/list-events.js +0 -418
  245. package/tools/events/list-events.js.map +0 -1
  246. package/tools/events/list-events.mjs +0 -411
  247. package/tools/events/list-events.mjs.map +0 -1
  248. package/tools/index.d.mts +0 -10
  249. package/tools/index.d.mts.map +0 -1
  250. package/tools/index.d.ts +0 -10
  251. package/tools/index.d.ts.map +0 -1
  252. package/tools/index.js +0 -117
  253. package/tools/index.js.map +0 -1
  254. package/tools/index.mjs +0 -110
  255. package/tools/index.mjs.map +0 -1
  256. package/tools/links/bulk/create-links-bulk.d.mts +0 -45
  257. package/tools/links/bulk/create-links-bulk.d.mts.map +0 -1
  258. package/tools/links/bulk/create-links-bulk.d.ts +0 -45
  259. package/tools/links/bulk/create-links-bulk.d.ts.map +0 -1
  260. package/tools/links/bulk/create-links-bulk.js +0 -956
  261. package/tools/links/bulk/create-links-bulk.js.map +0 -1
  262. package/tools/links/bulk/create-links-bulk.mjs +0 -949
  263. package/tools/links/bulk/create-links-bulk.mjs.map +0 -1
  264. package/tools/links/bulk/delete-links-bulk.d.mts +0 -45
  265. package/tools/links/bulk/delete-links-bulk.d.mts.map +0 -1
  266. package/tools/links/bulk/delete-links-bulk.d.ts +0 -45
  267. package/tools/links/bulk/delete-links-bulk.d.ts.map +0 -1
  268. package/tools/links/bulk/delete-links-bulk.js +0 -58
  269. package/tools/links/bulk/delete-links-bulk.js.map +0 -1
  270. package/tools/links/bulk/delete-links-bulk.mjs +0 -51
  271. package/tools/links/bulk/delete-links-bulk.mjs.map +0 -1
  272. package/tools/links/count-links.d.mts +0 -45
  273. package/tools/links/count-links.d.mts.map +0 -1
  274. package/tools/links/count-links.d.ts +0 -45
  275. package/tools/links/count-links.d.ts.map +0 -1
  276. package/tools/links/count-links.js +0 -951
  277. package/tools/links/count-links.js.map +0 -1
  278. package/tools/links/count-links.mjs +0 -944
  279. package/tools/links/count-links.mjs.map +0 -1
  280. package/tools/links/create-links.d.mts +0 -45
  281. package/tools/links/create-links.d.mts.map +0 -1
  282. package/tools/links/create-links.d.ts +0 -45
  283. package/tools/links/create-links.d.ts.map +0 -1
  284. package/tools/links/create-links.js +0 -947
  285. package/tools/links/create-links.js.map +0 -1
  286. package/tools/links/create-links.mjs +0 -940
  287. package/tools/links/create-links.mjs.map +0 -1
  288. package/tools/links/delete-links.d.mts +0 -45
  289. package/tools/links/delete-links.d.mts.map +0 -1
  290. package/tools/links/delete-links.d.ts +0 -45
  291. package/tools/links/delete-links.d.ts.map +0 -1
  292. package/tools/links/delete-links.js +0 -55
  293. package/tools/links/delete-links.js.map +0 -1
  294. package/tools/links/delete-links.mjs +0 -48
  295. package/tools/links/delete-links.mjs.map +0 -1
  296. package/tools/links/list-links.d.mts +0 -45
  297. package/tools/links/list-links.d.mts.map +0 -1
  298. package/tools/links/list-links.d.ts +0 -45
  299. package/tools/links/list-links.d.ts.map +0 -1
  300. package/tools/links/list-links.js +0 -973
  301. package/tools/links/list-links.js.map +0 -1
  302. package/tools/links/list-links.mjs +0 -966
  303. package/tools/links/list-links.mjs.map +0 -1
  304. package/tools/links/retrieve-info-links.d.mts +0 -45
  305. package/tools/links/retrieve-info-links.d.mts.map +0 -1
  306. package/tools/links/retrieve-info-links.d.ts +0 -45
  307. package/tools/links/retrieve-info-links.d.ts.map +0 -1
  308. package/tools/links/retrieve-info-links.js +0 -71
  309. package/tools/links/retrieve-info-links.js.map +0 -1
  310. package/tools/links/retrieve-info-links.mjs +0 -64
  311. package/tools/links/retrieve-info-links.mjs.map +0 -1
  312. package/tools/links/update-links.d.mts +0 -45
  313. package/tools/links/update-links.d.mts.map +0 -1
  314. package/tools/links/update-links.d.ts +0 -45
  315. package/tools/links/update-links.d.ts.map +0 -1
  316. package/tools/links/update-links.js +0 -953
  317. package/tools/links/update-links.js.map +0 -1
  318. package/tools/links/update-links.mjs +0 -946
  319. package/tools/links/update-links.mjs.map +0 -1
  320. package/tools/links/upsert-links.d.mts +0 -45
  321. package/tools/links/upsert-links.d.mts.map +0 -1
  322. package/tools/links/upsert-links.d.ts +0 -45
  323. package/tools/links/upsert-links.d.ts.map +0 -1
  324. package/tools/links/upsert-links.js +0 -947
  325. package/tools/links/upsert-links.js.map +0 -1
  326. package/tools/links/upsert-links.mjs +0 -940
  327. package/tools/links/upsert-links.mjs.map +0 -1
  328. package/tools/projects/list-projects.d.mts +0 -45
  329. package/tools/projects/list-projects.d.mts.map +0 -1
  330. package/tools/projects/list-projects.d.ts +0 -45
  331. package/tools/projects/list-projects.d.ts.map +0 -1
  332. package/tools/projects/list-projects.js +0 -51
  333. package/tools/projects/list-projects.js.map +0 -1
  334. package/tools/projects/list-projects.mjs +0 -44
  335. package/tools/projects/list-projects.mjs.map +0 -1
  336. package/tools/projects/retrieve-projects.d.mts +0 -45
  337. package/tools/projects/retrieve-projects.d.mts.map +0 -1
  338. package/tools/projects/retrieve-projects.d.ts +0 -45
  339. package/tools/projects/retrieve-projects.d.ts.map +0 -1
  340. package/tools/projects/retrieve-projects.js +0 -55
  341. package/tools/projects/retrieve-projects.js.map +0 -1
  342. package/tools/projects/retrieve-projects.mjs +0 -48
  343. package/tools/projects/retrieve-projects.mjs.map +0 -1
  344. package/tools/qrcodes/bulk/create-qrcodes-bulk.d.mts +0 -45
  345. package/tools/qrcodes/bulk/create-qrcodes-bulk.d.mts.map +0 -1
  346. package/tools/qrcodes/bulk/create-qrcodes-bulk.d.ts +0 -45
  347. package/tools/qrcodes/bulk/create-qrcodes-bulk.d.ts.map +0 -1
  348. package/tools/qrcodes/bulk/create-qrcodes-bulk.js +0 -1068
  349. package/tools/qrcodes/bulk/create-qrcodes-bulk.js.map +0 -1
  350. package/tools/qrcodes/bulk/create-qrcodes-bulk.mjs +0 -1061
  351. package/tools/qrcodes/bulk/create-qrcodes-bulk.mjs.map +0 -1
  352. package/tools/qrcodes/bulk/delete-qrcodes-bulk.d.mts +0 -45
  353. package/tools/qrcodes/bulk/delete-qrcodes-bulk.d.mts.map +0 -1
  354. package/tools/qrcodes/bulk/delete-qrcodes-bulk.d.ts +0 -45
  355. package/tools/qrcodes/bulk/delete-qrcodes-bulk.d.ts.map +0 -1
  356. package/tools/qrcodes/bulk/delete-qrcodes-bulk.js +0 -58
  357. package/tools/qrcodes/bulk/delete-qrcodes-bulk.js.map +0 -1
  358. package/tools/qrcodes/bulk/delete-qrcodes-bulk.mjs +0 -51
  359. package/tools/qrcodes/bulk/delete-qrcodes-bulk.mjs.map +0 -1
  360. package/tools/qrcodes/count-qrcodes.d.mts +0 -45
  361. package/tools/qrcodes/count-qrcodes.d.mts.map +0 -1
  362. package/tools/qrcodes/count-qrcodes.d.ts +0 -45
  363. package/tools/qrcodes/count-qrcodes.d.ts.map +0 -1
  364. package/tools/qrcodes/count-qrcodes.js +0 -215
  365. package/tools/qrcodes/count-qrcodes.js.map +0 -1
  366. package/tools/qrcodes/count-qrcodes.mjs +0 -208
  367. package/tools/qrcodes/count-qrcodes.mjs.map +0 -1
  368. package/tools/qrcodes/create-qrcodes.d.mts +0 -45
  369. package/tools/qrcodes/create-qrcodes.d.mts.map +0 -1
  370. package/tools/qrcodes/create-qrcodes.d.ts +0 -45
  371. package/tools/qrcodes/create-qrcodes.d.ts.map +0 -1
  372. package/tools/qrcodes/create-qrcodes.js +0 -1059
  373. package/tools/qrcodes/create-qrcodes.js.map +0 -1
  374. package/tools/qrcodes/create-qrcodes.mjs +0 -1052
  375. package/tools/qrcodes/create-qrcodes.mjs.map +0 -1
  376. package/tools/qrcodes/delete-qrcodes.d.mts +0 -45
  377. package/tools/qrcodes/delete-qrcodes.d.mts.map +0 -1
  378. package/tools/qrcodes/delete-qrcodes.d.ts +0 -45
  379. package/tools/qrcodes/delete-qrcodes.d.ts.map +0 -1
  380. package/tools/qrcodes/delete-qrcodes.js +0 -55
  381. package/tools/qrcodes/delete-qrcodes.js.map +0 -1
  382. package/tools/qrcodes/delete-qrcodes.mjs +0 -48
  383. package/tools/qrcodes/delete-qrcodes.mjs.map +0 -1
  384. package/tools/qrcodes/list-qrcodes.d.mts +0 -45
  385. package/tools/qrcodes/list-qrcodes.d.mts.map +0 -1
  386. package/tools/qrcodes/list-qrcodes.d.ts +0 -45
  387. package/tools/qrcodes/list-qrcodes.d.ts.map +0 -1
  388. package/tools/qrcodes/list-qrcodes.js +0 -217
  389. package/tools/qrcodes/list-qrcodes.js.map +0 -1
  390. package/tools/qrcodes/list-qrcodes.mjs +0 -210
  391. package/tools/qrcodes/list-qrcodes.mjs.map +0 -1
  392. package/tools/qrcodes/retrieve-qrcodes.d.mts +0 -45
  393. package/tools/qrcodes/retrieve-qrcodes.d.mts.map +0 -1
  394. package/tools/qrcodes/retrieve-qrcodes.d.ts +0 -45
  395. package/tools/qrcodes/retrieve-qrcodes.d.ts.map +0 -1
  396. package/tools/qrcodes/retrieve-qrcodes.js +0 -65
  397. package/tools/qrcodes/retrieve-qrcodes.js.map +0 -1
  398. package/tools/qrcodes/retrieve-qrcodes.mjs +0 -58
  399. package/tools/qrcodes/retrieve-qrcodes.mjs.map +0 -1
  400. package/tools/qrcodes/update-qrcodes.d.mts +0 -45
  401. package/tools/qrcodes/update-qrcodes.d.mts.map +0 -1
  402. package/tools/qrcodes/update-qrcodes.d.ts +0 -45
  403. package/tools/qrcodes/update-qrcodes.d.ts.map +0 -1
  404. package/tools/qrcodes/update-qrcodes.js +0 -1065
  405. package/tools/qrcodes/update-qrcodes.js.map +0 -1
  406. package/tools/qrcodes/update-qrcodes.mjs +0 -1058
  407. package/tools/qrcodes/update-qrcodes.mjs.map +0 -1
  408. package/tools/qrcodes/upsert-qrcodes.d.mts +0 -45
  409. package/tools/qrcodes/upsert-qrcodes.d.mts.map +0 -1
  410. package/tools/qrcodes/upsert-qrcodes.d.ts +0 -45
  411. package/tools/qrcodes/upsert-qrcodes.d.ts.map +0 -1
  412. package/tools/qrcodes/upsert-qrcodes.js +0 -1059
  413. package/tools/qrcodes/upsert-qrcodes.js.map +0 -1
  414. package/tools/qrcodes/upsert-qrcodes.mjs +0 -1052
  415. package/tools/qrcodes/upsert-qrcodes.mjs.map +0 -1
  416. package/tools/tags/create-tags.d.mts +0 -45
  417. package/tools/tags/create-tags.d.mts.map +0 -1
  418. package/tools/tags/create-tags.d.ts +0 -45
  419. package/tools/tags/create-tags.d.ts.map +0 -1
  420. package/tools/tags/create-tags.js +0 -58
  421. package/tools/tags/create-tags.js.map +0 -1
  422. package/tools/tags/create-tags.mjs +0 -51
  423. package/tools/tags/create-tags.mjs.map +0 -1
  424. package/tools/tags/delete-tags.d.mts +0 -45
  425. package/tools/tags/delete-tags.d.mts.map +0 -1
  426. package/tools/tags/delete-tags.d.ts +0 -45
  427. package/tools/tags/delete-tags.d.ts.map +0 -1
  428. package/tools/tags/delete-tags.js +0 -55
  429. package/tools/tags/delete-tags.js.map +0 -1
  430. package/tools/tags/delete-tags.mjs +0 -48
  431. package/tools/tags/delete-tags.mjs.map +0 -1
  432. package/tools/tags/list-tags.d.mts +0 -45
  433. package/tools/tags/list-tags.d.mts.map +0 -1
  434. package/tools/tags/list-tags.d.ts +0 -45
  435. package/tools/tags/list-tags.d.ts.map +0 -1
  436. package/tools/tags/list-tags.js +0 -87
  437. package/tools/tags/list-tags.js.map +0 -1
  438. package/tools/tags/list-tags.mjs +0 -80
  439. package/tools/tags/list-tags.mjs.map +0 -1
  440. package/tools/tags/update-tags.d.mts +0 -45
  441. package/tools/tags/update-tags.d.mts.map +0 -1
  442. package/tools/tags/update-tags.d.ts +0 -45
  443. package/tools/tags/update-tags.d.ts.map +0 -1
  444. package/tools/tags/update-tags.js +0 -63
  445. package/tools/tags/update-tags.js.map +0 -1
  446. package/tools/tags/update-tags.mjs +0 -56
  447. package/tools/tags/update-tags.mjs.map +0 -1
  448. package/tools/track/track-lead-track.d.mts +0 -45
  449. package/tools/track/track-lead-track.d.mts.map +0 -1
  450. package/tools/track/track-lead-track.d.ts +0 -45
  451. package/tools/track/track-lead-track.d.ts.map +0 -1
  452. package/tools/track/track-lead-track.js +0 -87
  453. package/tools/track/track-lead-track.js.map +0 -1
  454. package/tools/track/track-lead-track.mjs +0 -80
  455. package/tools/track/track-lead-track.mjs.map +0 -1
  456. package/tools/track/track-sale-track.d.mts +0 -45
  457. package/tools/track/track-sale-track.d.mts.map +0 -1
  458. package/tools/track/track-sale-track.d.ts +0 -45
  459. package/tools/track/track-sale-track.d.ts.map +0 -1
  460. package/tools/track/track-sale-track.js +0 -99
  461. package/tools/track/track-sale-track.js.map +0 -1
  462. package/tools/track/track-sale-track.mjs +0 -92
  463. package/tools/track/track-sale-track.mjs.map +0 -1
  464. package/tools/types.d.mts.map +0 -1
  465. package/tools/types.d.ts.map +0 -1
  466. package/tools/types.js.map +0 -1
  467. package/tools/types.mjs.map +0 -1
  468. package/tools.d.mts +0 -2
  469. package/tools.d.mts.map +0 -1
  470. package/tools.d.ts +0 -2
  471. package/tools.d.ts.map +0 -1
  472. package/tools.js +0 -18
  473. package/tools.js.map +0 -1
  474. package/tools.mjs +0 -2
  475. package/tools.mjs.map +0 -1
  476. /package/{tools/types.js → types.js} +0 -0
  477. /package/{tools/types.mjs → types.mjs} +0 -0
package/src/code-tool.ts CHANGED
@@ -1,13 +1,43 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { dirname } from 'node:path';
4
- import { pathToFileURL } from 'node:url';
5
- import Codeqr, { ClientOptions } from '@codeqr/ts';
6
- import { ContentBlock, Endpoint, Metadata, ToolCallResult } from './tools/types';
7
-
3
+ import {
4
+ ContentBlock,
5
+ McpRequestContext,
6
+ McpTool,
7
+ Metadata,
8
+ ToolCallResult,
9
+ asErrorResult,
10
+ asTextContentResult,
11
+ } from './types';
8
12
  import { Tool } from '@modelcontextprotocol/sdk/types.js';
13
+ import { readEnv, requireValue } from './util';
14
+ import { WorkerInput, WorkerOutput } from './code-tool-types';
15
+ import { getLogger } from './logger';
16
+ import { SdkMethod } from './methods';
17
+ import { McpCodeExecutionMode } from './options';
18
+ import { ClientOptions } from '@codeqr/ts';
19
+
20
+ const prompt = `Runs JavaScript code to interact with the Codeqr API.
21
+
22
+ You are a skilled TypeScript programmer writing code to interface with the service.
23
+ Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
24
+ For example:
25
+
26
+ \`\`\`
27
+ async function run(client) {
28
+ const link = await client.links.create({ url: 'REPLACE_ME' });
9
29
 
10
- import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types';
30
+ console.log(link.id);
31
+ }
32
+ \`\`\`
33
+
34
+ You will be returned anything that your function returns, plus the results of any console.log statements.
35
+ Do not add try-catch blocks for single API calls. The tool will handle errors for you.
36
+ Do not add comments unless necessary for generating better code.
37
+ Code will run in a container, and cannot interact with the network outside of the given SDK client.
38
+ Variables will not persist between calls, so make sure to return or log any data you might need later.
39
+ Remember that you are writing TypeScript code, so you need to be careful with your types.
40
+ Always type dynamic key-value stores explicitly as Record<string, YourValueType> instead of {}.`;
11
41
 
12
42
  /**
13
43
  * A tool that runs code against a copy of the SDK.
@@ -16,153 +46,351 @@ import { WorkerInput, WorkerError, WorkerSuccess } from './code-tool-types';
16
46
  * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
17
47
  * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
18
48
  *
19
- * @param endpoints - The endpoints to include in the list.
49
+ * @param blockedMethods - The methods to block for code execution. Blocking is done by simple string
50
+ * matching, so it is not secure against obfuscation. For stronger security, block in the downstream API
51
+ * with limited API keys.
52
+ * @param codeExecutionMode - Whether to execute code in a local Deno environment or in a remote
53
+ * sandbox environment hosted by Stainless.
20
54
  */
21
- export async function codeTool(): Promise<Endpoint> {
55
+ export function codeTool({
56
+ blockedMethods,
57
+ codeExecutionMode,
58
+ }: {
59
+ blockedMethods: SdkMethod[] | undefined;
60
+ codeExecutionMode: McpCodeExecutionMode;
61
+ }): McpTool {
22
62
  const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] };
23
63
  const tool: Tool = {
24
64
  name: 'execute',
25
- description:
26
- 'Runs JavaScript code to interact with the API.\n\nYou are a skilled programmer writing code to interface with the service.\nDefine an async function named "run" that takes a single parameter of an initialized client named "client", and it will be run.\nWrite code within this template:\n\n```\nasync function run(client) {\n // Fill this out\n}\n```\n\nYou will be returned anything that your function returns, plus the results of any console.log statements.\nIf any code triggers an error, the tool will return an error response, so you do not need to add error handling unless you want to output something more helpful than the raw error.\nIt is not necessary to add comments to code, unless by adding those comments you believe that you can generate better code.\nThis code will run in a container, and you will not be able to use fetch or otherwise interact with the network calls other than through the client you are given.\nAny variables you define won\'t live between successive uses of this call, so make sure to return or log any data you might need later.',
27
- inputSchema: { type: 'object', properties: { code: { type: 'string' } } },
65
+ description: prompt,
66
+ inputSchema: {
67
+ type: 'object',
68
+ properties: {
69
+ code: {
70
+ type: 'string',
71
+ description: 'Code to execute.',
72
+ },
73
+ intent: {
74
+ type: 'string',
75
+ description: 'Task you are trying to perform. Used for improving the service.',
76
+ },
77
+ },
78
+ required: ['code'],
79
+ },
28
80
  };
29
81
 
30
- // Import dynamically to avoid failing at import time in cases where the environment is not well-supported.
31
- const { newDenoHTTPWorker } = await import('@valtown/deno-http-worker');
32
- const { workerPath } = await import('./code-tool-paths.cjs');
33
-
34
- const handler = async (client: Codeqr, args: unknown): Promise<ToolCallResult> => {
35
- const baseURLHostname = new URL(client.baseURL).hostname;
36
- const { code } = args as { code: string };
37
-
38
- const worker = await newDenoHTTPWorker(pathToFileURL(workerPath), {
39
- runFlags: [
40
- `--node-modules-dir=manual`,
41
- `--allow-read=code-tool-worker.mjs,${workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
42
- `--allow-net=${baseURLHostname}`,
43
- // Allow environment variables because instantiating the client will try to read from them,
44
- // even though they are not set.
45
- '--allow-env',
46
- ],
47
- printOutput: true,
48
- spawnOptions: {
49
- cwd: dirname(workerPath),
82
+ const logger = getLogger();
83
+
84
+ const handler = async ({
85
+ reqContext,
86
+ args,
87
+ }: {
88
+ reqContext: McpRequestContext;
89
+ args: any;
90
+ }): Promise<ToolCallResult> => {
91
+ const code = args.code as string;
92
+ // Do very basic blocking of code that includes forbidden method names.
93
+ //
94
+ // WARNING: This is not secure against obfuscation and other evasion methods. If
95
+ // stronger security blocks are required, then these should be enforced in the downstream
96
+ // API (e.g., by having users call the MCP server with API keys with limited permissions).
97
+ if (blockedMethods) {
98
+ const blockedMatches = blockedMethods.filter((method) => code.includes(method.fullyQualifiedName));
99
+ if (blockedMatches.length > 0) {
100
+ return asErrorResult(
101
+ `The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
102
+ .map((m) => m.fullyQualifiedName)
103
+ .join(', ')}`,
104
+ );
105
+ }
106
+ }
107
+
108
+ let result: ToolCallResult;
109
+ const startTime = Date.now();
110
+
111
+ if (codeExecutionMode === 'local') {
112
+ logger.debug('Executing code in local Deno environment');
113
+ result = await localDenoHandler({ reqContext, args });
114
+ } else {
115
+ logger.debug('Executing code in remote Stainless environment');
116
+ result = await remoteStainlessHandler({ reqContext, args });
117
+ }
118
+
119
+ logger.info(
120
+ {
121
+ codeExecutionMode,
122
+ durationMs: Date.now() - startTime,
123
+ isError: result.isError,
124
+ contentRows: result.content?.length ?? 0,
50
125
  },
51
- });
126
+ 'Got code tool execution result',
127
+ );
128
+ return result;
129
+ };
130
+
131
+ return { metadata, tool, handler };
132
+ }
133
+
134
+ const remoteStainlessHandler = async ({
135
+ reqContext,
136
+ args,
137
+ }: {
138
+ reqContext: McpRequestContext;
139
+ args: any;
140
+ }): Promise<ToolCallResult> => {
141
+ const code = args.code as string;
142
+ const intent = args.intent as string | undefined;
143
+ const client = reqContext.client;
144
+
145
+ const codeModeEndpoint = readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
146
+
147
+ const localClientEnvs = {
148
+ CODEQR_API_KEY: requireValue(
149
+ readEnv('CODEQR_API_KEY') ?? client.apiKey,
150
+ 'set CODEQR_API_KEY environment variable or provide apiKey client option',
151
+ ),
152
+ CODEQR_BASE_URL: readEnv('CODEQR_BASE_URL') ?? client.baseURL ?? undefined,
153
+ };
154
+ // Merge any upstream client envs from the request header, with upstream values taking precedence.
155
+ const mergedClientEnvs = { ...localClientEnvs, ...reqContext.upstreamClientEnvs };
156
+
157
+ // Setting a Stainless API key authenticates requests to the code tool endpoint.
158
+ const res = await fetch(codeModeEndpoint, {
159
+ method: 'POST',
160
+ headers: {
161
+ ...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
162
+ 'Content-Type': 'application/json',
163
+ 'x-stainless-mcp-client-envs': JSON.stringify(mergedClientEnvs),
164
+ },
165
+ body: JSON.stringify({
166
+ project_name: 'codeqr',
167
+ code,
168
+ intent,
169
+ client_opts: {},
170
+ } satisfies WorkerInput),
171
+ });
172
+
173
+ if (!res.ok) {
174
+ if (res.status === 404 && !reqContext.stainlessApiKey) {
175
+ throw new Error(
176
+ 'Could not access code tool for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.',
177
+ );
178
+ }
179
+ throw new Error(
180
+ `${res.status}: ${
181
+ res.statusText
182
+ } error when trying to contact Code Tool server. Details: ${await res.text()}`,
183
+ );
184
+ }
185
+
186
+ const { is_error, result, log_lines, err_lines } = (await res.json()) as WorkerOutput;
187
+ const hasLogs = log_lines.length > 0 || err_lines.length > 0;
188
+ const output = {
189
+ result,
190
+ ...(log_lines.length > 0 && { log_lines }),
191
+ ...(err_lines.length > 0 && { err_lines }),
192
+ };
193
+ if (is_error) {
194
+ return asErrorResult(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
195
+ }
196
+ return asTextContentResult(output);
197
+ };
198
+
199
+ const localDenoHandler = async ({
200
+ reqContext,
201
+ args,
202
+ }: {
203
+ reqContext: McpRequestContext;
204
+ args: unknown;
205
+ }): Promise<ToolCallResult> => {
206
+ const fs = await import('node:fs');
207
+ const path = await import('node:path');
208
+ const url = await import('node:url');
209
+ const { newDenoHTTPWorker } = await import('@valtown/deno-http-worker');
210
+ const { getWorkerPath } = await import('./code-tool-paths.cjs');
211
+ const workerPath = getWorkerPath();
52
212
 
213
+ const client = reqContext.client;
214
+ const baseURLHostname = new URL(client.baseURL).hostname;
215
+ const { code } = args as { code: string };
216
+
217
+ let denoPath: string;
218
+
219
+ const packageRoot = path.resolve(path.dirname(workerPath), '..');
220
+ const packageNodeModulesPath = path.resolve(packageRoot, 'node_modules');
221
+
222
+ // Check if deno is in PATH
223
+ const { execSync } = await import('node:child_process');
224
+ try {
225
+ execSync('command -v deno', { stdio: 'ignore' });
226
+ denoPath = 'deno';
227
+ } catch {
53
228
  try {
54
- const resp = await new Promise<Response>((resolve, reject) => {
55
- worker.addEventListener('exit', (exitCode) => {
56
- reject(new Error(`Worker exited with code ${exitCode}`));
57
- });
229
+ // Use deno binary in node_modules if it's found
230
+ const denoNodeModulesPath = path.resolve(packageNodeModulesPath, 'deno', 'bin.cjs');
231
+ await fs.promises.access(denoNodeModulesPath, fs.constants.X_OK);
232
+ denoPath = denoNodeModulesPath;
233
+ } catch {
234
+ return asErrorResult(
235
+ 'Deno is required for code execution but was not found. ' +
236
+ 'Install it from https://deno.land or run: npm install deno',
237
+ );
238
+ }
239
+ }
240
+
241
+ const allowReadPaths = [
242
+ 'code-tool-worker.mjs',
243
+ `${workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
244
+ packageRoot,
245
+ ];
246
+
247
+ // Follow symlinks in node_modules to allow read access to workspace-linked packages
248
+ try {
249
+ const sdkPkgName = '@codeqr/ts';
250
+ const sdkDir = path.resolve(packageNodeModulesPath, sdkPkgName);
251
+ const realSdkDir = fs.realpathSync(sdkDir);
252
+ if (realSdkDir !== sdkDir) {
253
+ allowReadPaths.push(realSdkDir);
254
+ }
255
+ } catch {
256
+ // Ignore if symlink resolution fails
257
+ }
258
+
259
+ const allowRead = allowReadPaths.join(',');
58
260
 
59
- const opts: ClientOptions = {
261
+ const worker = await newDenoHTTPWorker(url.pathToFileURL(workerPath), {
262
+ denoExecutable: denoPath,
263
+ runFlags: [
264
+ `--node-modules-dir=manual`,
265
+ `--allow-read=${allowRead}`,
266
+ `--allow-net=${baseURLHostname}`,
267
+ // Allow environment variables because instantiating the client will try to read from them,
268
+ // even though they are not set.
269
+ '--allow-env',
270
+ ],
271
+ printOutput: true,
272
+ spawnOptions: {
273
+ cwd: path.dirname(workerPath),
274
+ // Merge any upstream client envs into the Deno subprocess environment,
275
+ // with the upstream env vars taking precedence.
276
+ env: { ...process.env, ...reqContext.upstreamClientEnvs },
277
+ },
278
+ });
279
+
280
+ try {
281
+ const resp = await new Promise<Response>((resolve, reject) => {
282
+ worker.addEventListener('exit', (exitCode) => {
283
+ reject(new Error(`Worker exited with code ${exitCode}`));
284
+ });
285
+
286
+ // Strip null/undefined values so that the worker SDK client can fall back to
287
+ // reading from environment variables (including any upstreamClientEnvs).
288
+ const opts: ClientOptions = Object.fromEntries(
289
+ Object.entries({
60
290
  baseURL: client.baseURL,
61
291
  apiKey: client.apiKey,
62
292
  defaultHeaders: {
63
293
  'X-Stainless-MCP': 'true',
64
294
  },
65
- };
295
+ }).filter(([_, v]) => v != null),
296
+ ) as ClientOptions;
66
297
 
67
- const req = worker.request(
68
- 'http://localhost',
69
- {
70
- headers: {
71
- 'content-type': 'application/json',
72
- },
73
- method: 'POST',
298
+ const req = worker.request(
299
+ 'http://localhost',
300
+ {
301
+ headers: {
302
+ 'content-type': 'application/json',
74
303
  },
75
- (resp) => {
76
- const body: Uint8Array[] = [];
77
- resp.on('error', (err) => {
78
- reject(err);
79
- });
80
- resp.on('data', (chunk) => {
81
- body.push(chunk);
82
- });
83
- resp.on('end', () => {
84
- resolve(
85
- new Response(Buffer.concat(body).toString(), {
86
- status: resp.statusCode ?? 200,
87
- headers: resp.headers as any,
88
- }),
89
- );
90
- });
91
- },
92
- );
93
-
94
- const body = JSON.stringify({
95
- opts,
96
- code,
97
- } satisfies WorkerInput);
98
-
99
- req.write(body, (err) => {
100
- if (err != null) {
304
+ method: 'POST',
305
+ },
306
+ (resp) => {
307
+ const body: Uint8Array[] = [];
308
+ resp.on('error', (err) => {
101
309
  reject(err);
102
- }
103
- });
310
+ });
311
+ resp.on('data', (chunk) => {
312
+ body.push(chunk);
313
+ });
314
+ resp.on('end', () => {
315
+ resolve(
316
+ new Response(Buffer.concat(body).toString(), {
317
+ status: resp.statusCode ?? 200,
318
+ headers: resp.headers as any,
319
+ }),
320
+ );
321
+ });
322
+ },
323
+ );
104
324
 
105
- req.end();
325
+ const body = JSON.stringify({
326
+ opts,
327
+ code,
106
328
  });
107
329
 
108
- if (resp.status === 200) {
109
- const { result, logLines, errLines } = (await resp.json()) as WorkerSuccess;
110
- const returnOutput: ContentBlock | null =
111
- result == null ? null : (
112
- {
113
- type: 'text',
114
- text: typeof result === 'string' ? result : JSON.stringify(result),
115
- }
116
- );
117
- const logOutput: ContentBlock | null =
118
- logLines.length === 0 ?
119
- null
120
- : {
121
- type: 'text',
122
- text: logLines.join('\n'),
123
- };
124
- const errOutput: ContentBlock | null =
125
- errLines.length === 0 ?
126
- null
127
- : {
128
- type: 'text',
129
- text: 'Error output:\n' + errLines.join('\n'),
130
- };
131
- return {
132
- content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
133
- };
134
- } else {
135
- const { message, logLines, errLines } = (await resp.json()) as WorkerError;
136
- const messageOutput: ContentBlock | null =
137
- message == null ? null : (
138
- {
139
- type: 'text',
140
- text: message,
141
- }
142
- );
143
- const logOutput: ContentBlock | null =
144
- logLines.length === 0 ?
145
- null
146
- : {
147
- type: 'text',
148
- text: logLines.join('\n'),
149
- };
150
- const errOutput: ContentBlock | null =
151
- errLines.length === 0 ?
152
- null
153
- : {
154
- type: 'text',
155
- text: 'Error output:\n' + errLines.join('\n'),
156
- };
157
- return {
158
- content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
159
- isError: true,
160
- };
161
- }
162
- } finally {
163
- worker.terminate();
164
- }
165
- };
330
+ req.write(body, (err) => {
331
+ if (err != null) {
332
+ reject(err);
333
+ }
334
+ });
166
335
 
167
- return { metadata, tool, handler };
168
- }
336
+ req.end();
337
+ });
338
+
339
+ if (resp.status === 200) {
340
+ const { result, log_lines, err_lines } = (await resp.json()) as WorkerOutput;
341
+ const returnOutput: ContentBlock | null =
342
+ result == null ? null : (
343
+ {
344
+ type: 'text',
345
+ text: typeof result === 'string' ? result : JSON.stringify(result),
346
+ }
347
+ );
348
+ const logOutput: ContentBlock | null =
349
+ log_lines.length === 0 ?
350
+ null
351
+ : {
352
+ type: 'text',
353
+ text: log_lines.join('\n'),
354
+ };
355
+ const errOutput: ContentBlock | null =
356
+ err_lines.length === 0 ?
357
+ null
358
+ : {
359
+ type: 'text',
360
+ text: 'Error output:\n' + err_lines.join('\n'),
361
+ };
362
+ return {
363
+ content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
364
+ };
365
+ } else {
366
+ const { result, log_lines, err_lines } = (await resp.json()) as WorkerOutput;
367
+ const messageOutput: ContentBlock | null =
368
+ result == null ? null : (
369
+ {
370
+ type: 'text',
371
+ text: typeof result === 'string' ? result : JSON.stringify(result),
372
+ }
373
+ );
374
+ const logOutput: ContentBlock | null =
375
+ log_lines.length === 0 ?
376
+ null
377
+ : {
378
+ type: 'text',
379
+ text: log_lines.join('\n'),
380
+ };
381
+ const errOutput: ContentBlock | null =
382
+ err_lines.length === 0 ?
383
+ null
384
+ : {
385
+ type: 'text',
386
+ text: 'Error output:\n' + err_lines.join('\n'),
387
+ };
388
+ return {
389
+ content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
390
+ isError: true,
391
+ };
392
+ }
393
+ } finally {
394
+ worker.terminate();
395
+ }
396
+ };
@@ -1,8 +1,8 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { Metadata, asTextContentResult } from './tools/types';
4
-
5
3
  import { Tool } from '@modelcontextprotocol/sdk/types.js';
4
+ import { Metadata, McpRequestContext, asTextContentResult } from './types';
5
+ import { getLogger } from './logger';
6
6
 
7
7
  export const metadata: Metadata = {
8
8
  resource: 'all',
@@ -13,7 +13,8 @@ export const metadata: Metadata = {
13
13
 
14
14
  export const tool: Tool = {
15
15
  name: 'search_docs',
16
- description: 'Search for documentation for how to use the client to interact with the API.',
16
+ description:
17
+ 'Search SDK documentation to find methods, parameters, and usage examples for interacting with the API. Use this before writing code when you need to discover the right approach.',
17
18
  inputSchema: {
18
19
  type: 'object',
19
20
  properties: {
@@ -42,11 +43,58 @@ export const tool: Tool = {
42
43
  const docsSearchURL =
43
44
  process.env['DOCS_SEARCH_URL'] || 'https://api.stainless.com/api/projects/codeqr/docs/search';
44
45
 
45
- export const handler = async (_: unknown, args: Record<string, unknown> | undefined) => {
46
+ export const handler = async ({
47
+ reqContext,
48
+ args,
49
+ }: {
50
+ reqContext: McpRequestContext;
51
+ args: Record<string, unknown> | undefined;
52
+ }) => {
46
53
  const body = args as any;
47
54
  const query = new URLSearchParams(body).toString();
48
- const result = await fetch(`${docsSearchURL}?${query}`);
49
- return asTextContentResult(await result.json());
55
+
56
+ const startTime = Date.now();
57
+ const result = await fetch(`${docsSearchURL}?${query}`, {
58
+ headers: {
59
+ ...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
60
+ },
61
+ });
62
+
63
+ const logger = getLogger();
64
+
65
+ if (!result.ok) {
66
+ const errorText = await result.text();
67
+ logger.warn(
68
+ {
69
+ durationMs: Date.now() - startTime,
70
+ query: body.query,
71
+ status: result.status,
72
+ statusText: result.statusText,
73
+ errorText,
74
+ },
75
+ 'Got error response from docs search tool',
76
+ );
77
+
78
+ if (result.status === 404 && !reqContext.stainlessApiKey) {
79
+ throw new Error(
80
+ 'Could not find docs for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.',
81
+ );
82
+ }
83
+
84
+ throw new Error(
85
+ `${result.status}: ${result.statusText} when using doc search tool. Details: ${errorText}`,
86
+ );
87
+ }
88
+
89
+ const resultBody = await result.json();
90
+ logger.info(
91
+ {
92
+ durationMs: Date.now() - startTime,
93
+ query: body.query,
94
+ },
95
+ 'Got docs search result',
96
+ );
97
+ return asTextContentResult(resultBody);
50
98
  };
51
99
 
52
100
  export default { metadata, tool, handler };