@mindstone/mcp-server-google-workspace 0.1.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 (514) hide show
  1. package/LICENSE +97 -0
  2. package/README.md +71 -0
  3. package/SECURITY.md +38 -0
  4. package/dist/__fixtures__/accounts.d.ts +47 -0
  5. package/dist/__fixtures__/accounts.d.ts.map +1 -0
  6. package/dist/__fixtures__/accounts.js +56 -0
  7. package/dist/__fixtures__/accounts.js.map +1 -0
  8. package/dist/api/handler.d.ts +16 -0
  9. package/dist/api/handler.d.ts.map +1 -0
  10. package/dist/api/handler.js +68 -0
  11. package/dist/api/handler.js.map +1 -0
  12. package/dist/api/request.d.ts +13 -0
  13. package/dist/api/request.d.ts.map +1 -0
  14. package/dist/api/request.js +111 -0
  15. package/dist/api/request.js.map +1 -0
  16. package/dist/api/validators/endpoint.d.ts +8 -0
  17. package/dist/api/validators/endpoint.d.ts.map +1 -0
  18. package/dist/api/validators/endpoint.js +115 -0
  19. package/dist/api/validators/endpoint.js.map +1 -0
  20. package/dist/api/validators/parameter.d.ts +12 -0
  21. package/dist/api/validators/parameter.d.ts.map +1 -0
  22. package/dist/api/validators/parameter.js +155 -0
  23. package/dist/api/validators/parameter.js.map +1 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +28 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/modules/accounts/index.d.ts +12 -0
  29. package/dist/modules/accounts/index.d.ts.map +1 -0
  30. package/dist/modules/accounts/index.js +41 -0
  31. package/dist/modules/accounts/index.js.map +1 -0
  32. package/dist/modules/accounts/manager.d.ts +40 -0
  33. package/dist/modules/accounts/manager.d.ts.map +1 -0
  34. package/dist/modules/accounts/manager.js +359 -0
  35. package/dist/modules/accounts/manager.js.map +1 -0
  36. package/dist/modules/accounts/oauth.d.ts +36 -0
  37. package/dist/modules/accounts/oauth.d.ts.map +1 -0
  38. package/dist/modules/accounts/oauth.js +112 -0
  39. package/dist/modules/accounts/oauth.js.map +1 -0
  40. package/dist/modules/accounts/token.d.ts +32 -0
  41. package/dist/modules/accounts/token.d.ts.map +1 -0
  42. package/dist/modules/accounts/token.js +305 -0
  43. package/dist/modules/accounts/token.js.map +1 -0
  44. package/dist/modules/accounts/types.d.ts +47 -0
  45. package/dist/modules/accounts/types.d.ts.map +1 -0
  46. package/dist/modules/accounts/types.js +16 -0
  47. package/dist/modules/accounts/types.js.map +1 -0
  48. package/dist/modules/accounts/unauthorized.d.ts +3 -0
  49. package/dist/modules/accounts/unauthorized.d.ts.map +1 -0
  50. package/dist/modules/accounts/unauthorized.js +44 -0
  51. package/dist/modules/accounts/unauthorized.js.map +1 -0
  52. package/dist/modules/attachments/cleanup-service.d.ts +44 -0
  53. package/dist/modules/attachments/cleanup-service.d.ts.map +1 -0
  54. package/dist/modules/attachments/cleanup-service.js +118 -0
  55. package/dist/modules/attachments/cleanup-service.js.map +1 -0
  56. package/dist/modules/attachments/index-service.d.ts +57 -0
  57. package/dist/modules/attachments/index-service.d.ts.map +1 -0
  58. package/dist/modules/attachments/index-service.js +110 -0
  59. package/dist/modules/attachments/index-service.js.map +1 -0
  60. package/dist/modules/attachments/response-transformer.d.ts +28 -0
  61. package/dist/modules/attachments/response-transformer.d.ts.map +1 -0
  62. package/dist/modules/attachments/response-transformer.js +64 -0
  63. package/dist/modules/attachments/response-transformer.js.map +1 -0
  64. package/dist/modules/attachments/service.d.ts +47 -0
  65. package/dist/modules/attachments/service.d.ts.map +1 -0
  66. package/dist/modules/attachments/service.js +362 -0
  67. package/dist/modules/attachments/service.js.map +1 -0
  68. package/dist/modules/attachments/transformer.d.ts +28 -0
  69. package/dist/modules/attachments/transformer.d.ts.map +1 -0
  70. package/dist/modules/attachments/transformer.js +31 -0
  71. package/dist/modules/attachments/transformer.js.map +1 -0
  72. package/dist/modules/attachments/types.d.ts +33 -0
  73. package/dist/modules/attachments/types.d.ts.map +1 -0
  74. package/dist/modules/attachments/types.js +9 -0
  75. package/dist/modules/attachments/types.js.map +1 -0
  76. package/dist/modules/calendar/index.d.ts +48 -0
  77. package/dist/modules/calendar/index.d.ts.map +1 -0
  78. package/dist/modules/calendar/index.js +61 -0
  79. package/dist/modules/calendar/index.js.map +1 -0
  80. package/dist/modules/calendar/scopes.d.ts +17 -0
  81. package/dist/modules/calendar/scopes.d.ts.map +1 -0
  82. package/dist/modules/calendar/scopes.js +39 -0
  83. package/dist/modules/calendar/scopes.js.map +1 -0
  84. package/dist/modules/calendar/service.d.ts +75 -0
  85. package/dist/modules/calendar/service.d.ts.map +1 -0
  86. package/dist/modules/calendar/service.js +705 -0
  87. package/dist/modules/calendar/service.js.map +1 -0
  88. package/dist/modules/calendar/types.d.ts +154 -0
  89. package/dist/modules/calendar/types.d.ts.map +1 -0
  90. package/dist/modules/calendar/types.js +11 -0
  91. package/dist/modules/calendar/types.js.map +1 -0
  92. package/dist/modules/comments/index.d.ts +12 -0
  93. package/dist/modules/comments/index.d.ts.map +1 -0
  94. package/dist/modules/comments/index.js +23 -0
  95. package/dist/modules/comments/index.js.map +1 -0
  96. package/dist/modules/comments/service.d.ts +39 -0
  97. package/dist/modules/comments/service.d.ts.map +1 -0
  98. package/dist/modules/comments/service.js +227 -0
  99. package/dist/modules/comments/service.js.map +1 -0
  100. package/dist/modules/comments/types.d.ts +67 -0
  101. package/dist/modules/comments/types.d.ts.map +1 -0
  102. package/dist/modules/comments/types.js +2 -0
  103. package/dist/modules/comments/types.js.map +1 -0
  104. package/dist/modules/contacts/index.d.ts +12 -0
  105. package/dist/modules/contacts/index.d.ts.map +1 -0
  106. package/dist/modules/contacts/index.js +18 -0
  107. package/dist/modules/contacts/index.js.map +1 -0
  108. package/dist/modules/contacts/scopes.d.ts +4 -0
  109. package/dist/modules/contacts/scopes.d.ts.map +1 -0
  110. package/dist/modules/contacts/scopes.js +11 -0
  111. package/dist/modules/contacts/scopes.js.map +1 -0
  112. package/dist/modules/contacts/types.d.ts +55 -0
  113. package/dist/modules/contacts/types.d.ts.map +1 -0
  114. package/dist/modules/contacts/types.js +14 -0
  115. package/dist/modules/contacts/types.js.map +1 -0
  116. package/dist/modules/docs/formatters.d.ts +30 -0
  117. package/dist/modules/docs/formatters.d.ts.map +1 -0
  118. package/dist/modules/docs/formatters.js +76 -0
  119. package/dist/modules/docs/formatters.js.map +1 -0
  120. package/dist/modules/docs/index.d.ts +9 -0
  121. package/dist/modules/docs/index.d.ts.map +1 -0
  122. package/dist/modules/docs/index.js +23 -0
  123. package/dist/modules/docs/index.js.map +1 -0
  124. package/dist/modules/docs/scopes.d.ts +17 -0
  125. package/dist/modules/docs/scopes.d.ts.map +1 -0
  126. package/dist/modules/docs/scopes.js +39 -0
  127. package/dist/modules/docs/scopes.js.map +1 -0
  128. package/dist/modules/docs/service.d.ts +58 -0
  129. package/dist/modules/docs/service.d.ts.map +1 -0
  130. package/dist/modules/docs/service.js +421 -0
  131. package/dist/modules/docs/service.js.map +1 -0
  132. package/dist/modules/docs/types.d.ts +75 -0
  133. package/dist/modules/docs/types.d.ts.map +1 -0
  134. package/dist/modules/docs/types.js +2 -0
  135. package/dist/modules/docs/types.js.map +1 -0
  136. package/dist/modules/drive/index.d.ts +9 -0
  137. package/dist/modules/drive/index.d.ts.map +1 -0
  138. package/dist/modules/drive/index.js +28 -0
  139. package/dist/modules/drive/index.js.map +1 -0
  140. package/dist/modules/drive/scopes.d.ts +19 -0
  141. package/dist/modules/drive/scopes.d.ts.map +1 -0
  142. package/dist/modules/drive/scopes.js +44 -0
  143. package/dist/modules/drive/scopes.js.map +1 -0
  144. package/dist/modules/drive/service.d.ts +33 -0
  145. package/dist/modules/drive/service.d.ts.map +1 -0
  146. package/dist/modules/drive/service.js +467 -0
  147. package/dist/modules/drive/service.js.map +1 -0
  148. package/dist/modules/drive/types.d.ts +55 -0
  149. package/dist/modules/drive/types.d.ts.map +1 -0
  150. package/dist/modules/drive/types.js +2 -0
  151. package/dist/modules/drive/types.js.map +1 -0
  152. package/dist/modules/forms/index.d.ts +13 -0
  153. package/dist/modules/forms/index.d.ts.map +1 -0
  154. package/dist/modules/forms/index.js +24 -0
  155. package/dist/modules/forms/index.js.map +1 -0
  156. package/dist/modules/forms/scopes.d.ts +21 -0
  157. package/dist/modules/forms/scopes.d.ts.map +1 -0
  158. package/dist/modules/forms/scopes.js +36 -0
  159. package/dist/modules/forms/scopes.js.map +1 -0
  160. package/dist/modules/forms/service.d.ts +52 -0
  161. package/dist/modules/forms/service.d.ts.map +1 -0
  162. package/dist/modules/forms/service.js +284 -0
  163. package/dist/modules/forms/service.js.map +1 -0
  164. package/dist/modules/forms/types.d.ts +399 -0
  165. package/dist/modules/forms/types.d.ts.map +1 -0
  166. package/dist/modules/forms/types.js +6 -0
  167. package/dist/modules/forms/types.js.map +1 -0
  168. package/dist/modules/gmail/constants.d.ts +69 -0
  169. package/dist/modules/gmail/constants.d.ts.map +1 -0
  170. package/dist/modules/gmail/constants.js +100 -0
  171. package/dist/modules/gmail/constants.js.map +1 -0
  172. package/dist/modules/gmail/index.d.ts +7 -0
  173. package/dist/modules/gmail/index.d.ts.map +1 -0
  174. package/dist/modules/gmail/index.js +16 -0
  175. package/dist/modules/gmail/index.js.map +1 -0
  176. package/dist/modules/gmail/scopes.d.ts +17 -0
  177. package/dist/modules/gmail/scopes.d.ts.map +1 -0
  178. package/dist/modules/gmail/scopes.js +39 -0
  179. package/dist/modules/gmail/scopes.js.map +1 -0
  180. package/dist/modules/gmail/service.d.ts +2 -0
  181. package/dist/modules/gmail/service.d.ts.map +1 -0
  182. package/dist/modules/gmail/service.js +2 -0
  183. package/dist/modules/gmail/service.js.map +1 -0
  184. package/dist/modules/gmail/services/attachment.d.ts +41 -0
  185. package/dist/modules/gmail/services/attachment.d.ts.map +1 -0
  186. package/dist/modules/gmail/services/attachment.js +143 -0
  187. package/dist/modules/gmail/services/attachment.js.map +1 -0
  188. package/dist/modules/gmail/services/base.d.ts +79 -0
  189. package/dist/modules/gmail/services/base.d.ts.map +1 -0
  190. package/dist/modules/gmail/services/base.js +124 -0
  191. package/dist/modules/gmail/services/base.js.map +1 -0
  192. package/dist/modules/gmail/services/draft.d.ts +104 -0
  193. package/dist/modules/gmail/services/draft.d.ts.map +1 -0
  194. package/dist/modules/gmail/services/draft.js +239 -0
  195. package/dist/modules/gmail/services/draft.js.map +1 -0
  196. package/dist/modules/gmail/services/email.d.ts +82 -0
  197. package/dist/modules/gmail/services/email.d.ts.map +1 -0
  198. package/dist/modules/gmail/services/email.js +462 -0
  199. package/dist/modules/gmail/services/email.js.map +1 -0
  200. package/dist/modules/gmail/services/label.d.ts +62 -0
  201. package/dist/modules/gmail/services/label.d.ts.map +1 -0
  202. package/dist/modules/gmail/services/label.js +501 -0
  203. package/dist/modules/gmail/services/label.js.map +1 -0
  204. package/dist/modules/gmail/services/mime-builder.d.ts +26 -0
  205. package/dist/modules/gmail/services/mime-builder.d.ts.map +1 -0
  206. package/dist/modules/gmail/services/mime-builder.js +83 -0
  207. package/dist/modules/gmail/services/mime-builder.js.map +1 -0
  208. package/dist/modules/gmail/services/search.d.ts +8 -0
  209. package/dist/modules/gmail/services/search.d.ts.map +1 -0
  210. package/dist/modules/gmail/services/search.js +76 -0
  211. package/dist/modules/gmail/services/search.js.map +1 -0
  212. package/dist/modules/gmail/services/settings.d.ts +14 -0
  213. package/dist/modules/gmail/services/settings.d.ts.map +1 -0
  214. package/dist/modules/gmail/services/settings.js +104 -0
  215. package/dist/modules/gmail/services/settings.js.map +1 -0
  216. package/dist/modules/gmail/types.d.ts +279 -0
  217. package/dist/modules/gmail/types.d.ts.map +1 -0
  218. package/dist/modules/gmail/types.js +11 -0
  219. package/dist/modules/gmail/types.js.map +1 -0
  220. package/dist/modules/sheets/a1Utils.d.ts +20 -0
  221. package/dist/modules/sheets/a1Utils.d.ts.map +1 -0
  222. package/dist/modules/sheets/a1Utils.js +252 -0
  223. package/dist/modules/sheets/a1Utils.js.map +1 -0
  224. package/dist/modules/sheets/cellShape.d.ts +48 -0
  225. package/dist/modules/sheets/cellShape.d.ts.map +1 -0
  226. package/dist/modules/sheets/cellShape.js +418 -0
  227. package/dist/modules/sheets/cellShape.js.map +1 -0
  228. package/dist/modules/sheets/errorRewriter.d.ts +6 -0
  229. package/dist/modules/sheets/errorRewriter.d.ts.map +1 -0
  230. package/dist/modules/sheets/errorRewriter.js +120 -0
  231. package/dist/modules/sheets/errorRewriter.js.map +1 -0
  232. package/dist/modules/sheets/formatters.d.ts +54 -0
  233. package/dist/modules/sheets/formatters.d.ts.map +1 -0
  234. package/dist/modules/sheets/formatters.js +270 -0
  235. package/dist/modules/sheets/formatters.js.map +1 -0
  236. package/dist/modules/sheets/index.d.ts +9 -0
  237. package/dist/modules/sheets/index.d.ts.map +1 -0
  238. package/dist/modules/sheets/index.js +23 -0
  239. package/dist/modules/sheets/index.js.map +1 -0
  240. package/dist/modules/sheets/scopes.d.ts +17 -0
  241. package/dist/modules/sheets/scopes.d.ts.map +1 -0
  242. package/dist/modules/sheets/scopes.js +39 -0
  243. package/dist/modules/sheets/scopes.js.map +1 -0
  244. package/dist/modules/sheets/service.d.ts +102 -0
  245. package/dist/modules/sheets/service.d.ts.map +1 -0
  246. package/dist/modules/sheets/service.js +1650 -0
  247. package/dist/modules/sheets/service.js.map +1 -0
  248. package/dist/modules/sheets/types.d.ts +271 -0
  249. package/dist/modules/sheets/types.d.ts.map +1 -0
  250. package/dist/modules/sheets/types.js +2 -0
  251. package/dist/modules/sheets/types.js.map +1 -0
  252. package/dist/modules/sheets/writeGuards.d.ts +31 -0
  253. package/dist/modules/sheets/writeGuards.d.ts.map +1 -0
  254. package/dist/modules/sheets/writeGuards.js +254 -0
  255. package/dist/modules/sheets/writeGuards.js.map +1 -0
  256. package/dist/modules/slides/formatters.d.ts +35 -0
  257. package/dist/modules/slides/formatters.d.ts.map +1 -0
  258. package/dist/modules/slides/formatters.js +96 -0
  259. package/dist/modules/slides/formatters.js.map +1 -0
  260. package/dist/modules/slides/index.d.ts +9 -0
  261. package/dist/modules/slides/index.d.ts.map +1 -0
  262. package/dist/modules/slides/index.js +23 -0
  263. package/dist/modules/slides/index.js.map +1 -0
  264. package/dist/modules/slides/scopes.d.ts +17 -0
  265. package/dist/modules/slides/scopes.d.ts.map +1 -0
  266. package/dist/modules/slides/scopes.js +39 -0
  267. package/dist/modules/slides/scopes.js.map +1 -0
  268. package/dist/modules/slides/service.d.ts +67 -0
  269. package/dist/modules/slides/service.d.ts.map +1 -0
  270. package/dist/modules/slides/service.js +394 -0
  271. package/dist/modules/slides/service.js.map +1 -0
  272. package/dist/modules/slides/types.d.ts +63 -0
  273. package/dist/modules/slides/types.d.ts.map +1 -0
  274. package/dist/modules/slides/types.js +2 -0
  275. package/dist/modules/slides/types.js.map +1 -0
  276. package/dist/modules/tasks/index.d.ts +13 -0
  277. package/dist/modules/tasks/index.d.ts.map +1 -0
  278. package/dist/modules/tasks/index.js +24 -0
  279. package/dist/modules/tasks/index.js.map +1 -0
  280. package/dist/modules/tasks/scopes.d.ts +18 -0
  281. package/dist/modules/tasks/scopes.d.ts.map +1 -0
  282. package/dist/modules/tasks/scopes.js +28 -0
  283. package/dist/modules/tasks/scopes.js.map +1 -0
  284. package/dist/modules/tasks/service.d.ts +72 -0
  285. package/dist/modules/tasks/service.d.ts.map +1 -0
  286. package/dist/modules/tasks/service.js +319 -0
  287. package/dist/modules/tasks/service.js.map +1 -0
  288. package/dist/modules/tasks/types.d.ts +118 -0
  289. package/dist/modules/tasks/types.d.ts.map +1 -0
  290. package/dist/modules/tasks/types.js +6 -0
  291. package/dist/modules/tasks/types.js.map +1 -0
  292. package/dist/modules/tools/registry.d.ts +28 -0
  293. package/dist/modules/tools/registry.d.ts.map +1 -0
  294. package/dist/modules/tools/registry.js +229 -0
  295. package/dist/modules/tools/registry.js.map +1 -0
  296. package/dist/modules/tools/scope-registry.d.ts +31 -0
  297. package/dist/modules/tools/scope-registry.d.ts.map +1 -0
  298. package/dist/modules/tools/scope-registry.js +52 -0
  299. package/dist/modules/tools/scope-registry.js.map +1 -0
  300. package/dist/oauth/client.d.ts +15 -0
  301. package/dist/oauth/client.d.ts.map +1 -0
  302. package/dist/oauth/client.js +136 -0
  303. package/dist/oauth/client.js.map +1 -0
  304. package/dist/resources/compose-email-template.d.ts +2 -0
  305. package/dist/resources/compose-email-template.d.ts.map +1 -0
  306. package/dist/resources/compose-email-template.js +711 -0
  307. package/dist/resources/compose-email-template.js.map +1 -0
  308. package/dist/scripts/health-check.d.ts +3 -0
  309. package/dist/scripts/health-check.d.ts.map +1 -0
  310. package/dist/scripts/health-check.js +22 -0
  311. package/dist/scripts/health-check.js.map +1 -0
  312. package/dist/scripts/setup-environment.d.ts +3 -0
  313. package/dist/scripts/setup-environment.d.ts.map +1 -0
  314. package/dist/scripts/setup-environment.js +91 -0
  315. package/dist/scripts/setup-environment.js.map +1 -0
  316. package/dist/scripts/setup-google-env.d.ts +3 -0
  317. package/dist/scripts/setup-google-env.d.ts.map +1 -0
  318. package/dist/scripts/setup-google-env.js +78 -0
  319. package/dist/scripts/setup-google-env.js.map +1 -0
  320. package/dist/services/base/BaseGoogleService.d.ts +52 -0
  321. package/dist/services/base/BaseGoogleService.d.ts.map +1 -0
  322. package/dist/services/base/BaseGoogleService.js +155 -0
  323. package/dist/services/base/BaseGoogleService.js.map +1 -0
  324. package/dist/services/calendar/index.d.ts +27 -0
  325. package/dist/services/calendar/index.d.ts.map +1 -0
  326. package/dist/services/calendar/index.js +146 -0
  327. package/dist/services/calendar/index.js.map +1 -0
  328. package/dist/services/contacts/index.d.ts +40 -0
  329. package/dist/services/contacts/index.d.ts.map +1 -0
  330. package/dist/services/contacts/index.js +137 -0
  331. package/dist/services/contacts/index.js.map +1 -0
  332. package/dist/services/docs/index.d.ts +4 -0
  333. package/dist/services/docs/index.d.ts.map +1 -0
  334. package/dist/services/docs/index.js +6 -0
  335. package/dist/services/docs/index.js.map +1 -0
  336. package/dist/services/drive/index.d.ts +4 -0
  337. package/dist/services/drive/index.d.ts.map +1 -0
  338. package/dist/services/drive/index.js +6 -0
  339. package/dist/services/drive/index.js.map +1 -0
  340. package/dist/services/gmail/index.d.ts +39 -0
  341. package/dist/services/gmail/index.d.ts.map +1 -0
  342. package/dist/services/gmail/index.js +337 -0
  343. package/dist/services/gmail/index.js.map +1 -0
  344. package/dist/services/sheets/index.d.ts +4 -0
  345. package/dist/services/sheets/index.d.ts.map +1 -0
  346. package/dist/services/sheets/index.js +6 -0
  347. package/dist/services/sheets/index.js.map +1 -0
  348. package/dist/services/slides/index.d.ts +4 -0
  349. package/dist/services/slides/index.d.ts.map +1 -0
  350. package/dist/services/slides/index.js +6 -0
  351. package/dist/services/slides/index.js.map +1 -0
  352. package/dist/tools/account-handlers.d.ts +28 -0
  353. package/dist/tools/account-handlers.d.ts.map +1 -0
  354. package/dist/tools/account-handlers.js +105 -0
  355. package/dist/tools/account-handlers.js.map +1 -0
  356. package/dist/tools/arg-aliases.d.ts +6 -0
  357. package/dist/tools/arg-aliases.d.ts.map +1 -0
  358. package/dist/tools/arg-aliases.js +22 -0
  359. package/dist/tools/arg-aliases.js.map +1 -0
  360. package/dist/tools/calendar-handlers.d.ts +83 -0
  361. package/dist/tools/calendar-handlers.d.ts.map +1 -0
  362. package/dist/tools/calendar-handlers.js +658 -0
  363. package/dist/tools/calendar-handlers.js.map +1 -0
  364. package/dist/tools/comments-handlers.d.ts +59 -0
  365. package/dist/tools/comments-handlers.d.ts.map +1 -0
  366. package/dist/tools/comments-handlers.js +138 -0
  367. package/dist/tools/comments-handlers.js.map +1 -0
  368. package/dist/tools/contacts-handlers.d.ts +36 -0
  369. package/dist/tools/contacts-handlers.d.ts.map +1 -0
  370. package/dist/tools/contacts-handlers.js +128 -0
  371. package/dist/tools/contacts-handlers.js.map +1 -0
  372. package/dist/tools/definitions/account.d.ts +3 -0
  373. package/dist/tools/definitions/account.d.ts.map +1 -0
  374. package/dist/tools/definitions/account.js +77 -0
  375. package/dist/tools/definitions/account.js.map +1 -0
  376. package/dist/tools/definitions/calendar.d.ts +3 -0
  377. package/dist/tools/definitions/calendar.d.ts.map +1 -0
  378. package/dist/tools/definitions/calendar.js +565 -0
  379. package/dist/tools/definitions/calendar.js.map +1 -0
  380. package/dist/tools/definitions/comments.d.ts +3 -0
  381. package/dist/tools/definitions/comments.d.ts.map +1 -0
  382. package/dist/tools/definitions/comments.js +207 -0
  383. package/dist/tools/definitions/comments.js.map +1 -0
  384. package/dist/tools/definitions/contacts.d.ts +3 -0
  385. package/dist/tools/definitions/contacts.d.ts.map +1 -0
  386. package/dist/tools/definitions/contacts.js +93 -0
  387. package/dist/tools/definitions/contacts.js.map +1 -0
  388. package/dist/tools/definitions/destructive-overrides.json +106 -0
  389. package/dist/tools/definitions/docs.d.ts +3 -0
  390. package/dist/tools/definitions/docs.d.ts.map +1 -0
  391. package/dist/tools/definitions/docs.js +416 -0
  392. package/dist/tools/definitions/docs.js.map +1 -0
  393. package/dist/tools/definitions/drive.d.ts +3 -0
  394. package/dist/tools/definitions/drive.d.ts.map +1 -0
  395. package/dist/tools/definitions/drive.js +587 -0
  396. package/dist/tools/definitions/drive.js.map +1 -0
  397. package/dist/tools/definitions/forms.d.ts +14 -0
  398. package/dist/tools/definitions/forms.d.ts.map +1 -0
  399. package/dist/tools/definitions/forms.js +189 -0
  400. package/dist/tools/definitions/forms.js.map +1 -0
  401. package/dist/tools/definitions/gmail.d.ts +3 -0
  402. package/dist/tools/definitions/gmail.d.ts.map +1 -0
  403. package/dist/tools/definitions/gmail.js +962 -0
  404. package/dist/tools/definitions/gmail.js.map +1 -0
  405. package/dist/tools/definitions/index.d.ts +33 -0
  406. package/dist/tools/definitions/index.d.ts.map +1 -0
  407. package/dist/tools/definitions/index.js +77 -0
  408. package/dist/tools/definitions/index.js.map +1 -0
  409. package/dist/tools/definitions/labels.d.ts +3 -0
  410. package/dist/tools/definitions/labels.d.ts.map +1 -0
  411. package/dist/tools/definitions/labels.js +662 -0
  412. package/dist/tools/definitions/labels.js.map +1 -0
  413. package/dist/tools/definitions/open-world-overrides.json +106 -0
  414. package/dist/tools/definitions/sheets.d.ts +3 -0
  415. package/dist/tools/definitions/sheets.d.ts.map +1 -0
  416. package/dist/tools/definitions/sheets.js +833 -0
  417. package/dist/tools/definitions/sheets.js.map +1 -0
  418. package/dist/tools/definitions/slides.d.ts +3 -0
  419. package/dist/tools/definitions/slides.d.ts.map +1 -0
  420. package/dist/tools/definitions/slides.js +383 -0
  421. package/dist/tools/definitions/slides.js.map +1 -0
  422. package/dist/tools/definitions/tasks.d.ts +11 -0
  423. package/dist/tools/definitions/tasks.d.ts.map +1 -0
  424. package/dist/tools/definitions/tasks.js +259 -0
  425. package/dist/tools/definitions/tasks.js.map +1 -0
  426. package/dist/tools/definitions.d.ts +8 -0
  427. package/dist/tools/definitions.d.ts.map +1 -0
  428. package/dist/tools/definitions.js +9 -0
  429. package/dist/tools/definitions.js.map +1 -0
  430. package/dist/tools/docs-handlers.d.ts +96 -0
  431. package/dist/tools/docs-handlers.d.ts.map +1 -0
  432. package/dist/tools/docs-handlers.js +250 -0
  433. package/dist/tools/docs-handlers.js.map +1 -0
  434. package/dist/tools/drive-handlers.d.ts +95 -0
  435. package/dist/tools/drive-handlers.d.ts.map +1 -0
  436. package/dist/tools/drive-handlers.js +506 -0
  437. package/dist/tools/drive-handlers.js.map +1 -0
  438. package/dist/tools/forms-handlers.d.ts +72 -0
  439. package/dist/tools/forms-handlers.d.ts.map +1 -0
  440. package/dist/tools/forms-handlers.js +435 -0
  441. package/dist/tools/forms-handlers.js.map +1 -0
  442. package/dist/tools/gmail-handlers.d.ts +320 -0
  443. package/dist/tools/gmail-handlers.d.ts.map +1 -0
  444. package/dist/tools/gmail-handlers.js +1040 -0
  445. package/dist/tools/gmail-handlers.js.map +1 -0
  446. package/dist/tools/param-normalizer.d.ts +2 -0
  447. package/dist/tools/param-normalizer.d.ts.map +1 -0
  448. package/dist/tools/param-normalizer.js +96 -0
  449. package/dist/tools/param-normalizer.js.map +1 -0
  450. package/dist/tools/server.d.ts +14 -0
  451. package/dist/tools/server.d.ts.map +1 -0
  452. package/dist/tools/server.js +733 -0
  453. package/dist/tools/server.js.map +1 -0
  454. package/dist/tools/sheets-handlers.d.ts +230 -0
  455. package/dist/tools/sheets-handlers.d.ts.map +1 -0
  456. package/dist/tools/sheets-handlers.js +589 -0
  457. package/dist/tools/sheets-handlers.js.map +1 -0
  458. package/dist/tools/slides-handlers.d.ts +90 -0
  459. package/dist/tools/slides-handlers.d.ts.map +1 -0
  460. package/dist/tools/slides-handlers.js +281 -0
  461. package/dist/tools/slides-handlers.js.map +1 -0
  462. package/dist/tools/tasks-handlers.d.ts +85 -0
  463. package/dist/tools/tasks-handlers.d.ts.map +1 -0
  464. package/dist/tools/tasks-handlers.js +265 -0
  465. package/dist/tools/tasks-handlers.js.map +1 -0
  466. package/dist/tools/type-guards.d.ts +491 -0
  467. package/dist/tools/type-guards.d.ts.map +1 -0
  468. package/dist/tools/type-guards.js +1325 -0
  469. package/dist/tools/type-guards.js.map +1 -0
  470. package/dist/tools/types.d.ts +298 -0
  471. package/dist/tools/types.d.ts.map +1 -0
  472. package/dist/tools/types.js +2 -0
  473. package/dist/tools/types.js.map +1 -0
  474. package/dist/types.d.ts +70 -0
  475. package/dist/types.d.ts.map +1 -0
  476. package/dist/types.js +12 -0
  477. package/dist/types.js.map +1 -0
  478. package/dist/utils/atomicCredentialWrite.d.ts +5 -0
  479. package/dist/utils/atomicCredentialWrite.d.ts.map +1 -0
  480. package/dist/utils/atomicCredentialWrite.js +120 -0
  481. package/dist/utils/atomicCredentialWrite.js.map +1 -0
  482. package/dist/utils/emfileRetry.d.ts +3 -0
  483. package/dist/utils/emfileRetry.d.ts.map +1 -0
  484. package/dist/utils/emfileRetry.js +24 -0
  485. package/dist/utils/emfileRetry.js.map +1 -0
  486. package/dist/utils/logger.d.ts +8 -0
  487. package/dist/utils/logger.d.ts.map +1 -0
  488. package/dist/utils/logger.js +67 -0
  489. package/dist/utils/logger.js.map +1 -0
  490. package/dist/utils/request-timeout.d.ts +5 -0
  491. package/dist/utils/request-timeout.d.ts.map +1 -0
  492. package/dist/utils/request-timeout.js +27 -0
  493. package/dist/utils/request-timeout.js.map +1 -0
  494. package/dist/utils/safe-filename.d.ts +2 -0
  495. package/dist/utils/safe-filename.d.ts.map +1 -0
  496. package/dist/utils/safe-filename.js +24 -0
  497. package/dist/utils/safe-filename.js.map +1 -0
  498. package/dist/utils/scope-hierarchy.d.ts +35 -0
  499. package/dist/utils/scope-hierarchy.d.ts.map +1 -0
  500. package/dist/utils/scope-hierarchy.js +123 -0
  501. package/dist/utils/scope-hierarchy.js.map +1 -0
  502. package/dist/utils/service-initializer.d.ts +12 -0
  503. package/dist/utils/service-initializer.d.ts.map +1 -0
  504. package/dist/utils/service-initializer.js +87 -0
  505. package/dist/utils/service-initializer.js.map +1 -0
  506. package/dist/utils/untrusted-content.d.ts +3 -0
  507. package/dist/utils/untrusted-content.d.ts.map +1 -0
  508. package/dist/utils/untrusted-content.js +20 -0
  509. package/dist/utils/untrusted-content.js.map +1 -0
  510. package/dist/utils/workspace.d.ts +43 -0
  511. package/dist/utils/workspace.d.ts.map +1 -0
  512. package/dist/utils/workspace.js +98 -0
  513. package/dist/utils/workspace.js.map +1 -0
  514. package/package.json +61 -0
@@ -0,0 +1,658 @@
1
+ import { CalendarService } from '../modules/calendar/service.js';
2
+ import { DriveService } from '../modules/drive/service.js';
3
+ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
4
+ import { getAccountManager, validateEmail, resolveEmail } from '../modules/accounts/index.js';
5
+ import { CalendarError } from '../modules/calendar/types.js';
6
+ import { google } from 'googleapis';
7
+ import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
8
+ // Singleton instances
9
+ let driveService;
10
+ let calendarService;
11
+ let accountManager;
12
+ // Default time window: 14 days from now
13
+ const DEFAULT_TIME_WINDOW_DAYS = 14;
14
+ // Increased defaults to support calendar sync across multi-day ranges
15
+ const DEFAULT_MAX_RESULTS = 250;
16
+ const MAX_RESULTS_CAP = 500;
17
+ const CALENDAR_CONFIG = {
18
+ maxAttachmentSize: 10 * 1024 * 1024, // 10MB
19
+ allowedAttachmentTypes: [
20
+ 'application/pdf',
21
+ 'application/msword',
22
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
23
+ 'application/vnd.ms-excel',
24
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
25
+ 'application/vnd.ms-powerpoint',
26
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
27
+ 'image/jpeg',
28
+ 'image/png',
29
+ 'text/plain'
30
+ ]
31
+ };
32
+ // Initialize services lazily
33
+ async function initializeServices() {
34
+ if (!driveService) {
35
+ driveService = new DriveService();
36
+ }
37
+ if (!calendarService) {
38
+ calendarService = new CalendarService(CALENDAR_CONFIG);
39
+ await calendarService.ensureInitialized();
40
+ }
41
+ if (!accountManager) {
42
+ accountManager = getAccountManager();
43
+ }
44
+ }
45
+ function readAliasedString(args, canonicalKey, legacyKey) {
46
+ const value = args[canonicalKey] ?? args[legacyKey];
47
+ return typeof value === 'string' ? value : undefined;
48
+ }
49
+ function readAliasedNumber(args, canonicalKey, legacyKey) {
50
+ const value = args[canonicalKey] ?? args[legacyKey];
51
+ return typeof value === 'number' ? value : undefined;
52
+ }
53
+ function readAliasedBoolean(args, canonicalKey, legacyKey) {
54
+ const value = args[canonicalKey] ?? args[legacyKey];
55
+ return typeof value === 'boolean' ? value : undefined;
56
+ }
57
+ async function tryGetCalendarTimezone(email) {
58
+ try {
59
+ const tokenStatus = await accountManager.validateToken(email);
60
+ if (!tokenStatus.valid || !tokenStatus.token) {
61
+ console.warn('[calendar] Token invalid for timezone fetch');
62
+ return null;
63
+ }
64
+ const oauth2Client = await accountManager.getAuthClient();
65
+ oauth2Client.setCredentials(tokenStatus.token);
66
+ const calendar = google.calendar({ version: 'v3', auth: oauth2Client });
67
+ const settings = await calendar.settings.get({ setting: 'timezone' });
68
+ return settings.data.value || null;
69
+ }
70
+ catch (err) {
71
+ console.warn('[calendar] Failed to fetch timezone from settings', err instanceof Error ? err.message : '');
72
+ return null;
73
+ }
74
+ }
75
+ async function getUserCalendarTimezone(email, fallbackTimezone) {
76
+ const tz = await tryGetCalendarTimezone(email);
77
+ return tz || fallbackTimezone || 'UTC';
78
+ }
79
+ async function resolveTimezone(email, eventTimezone, deviceTimezone) {
80
+ const calendarTimezone = await tryGetCalendarTimezone(email);
81
+ let deviceTz = null;
82
+ if (deviceTimezone) {
83
+ try {
84
+ Intl.DateTimeFormat(undefined, { timeZone: deviceTimezone });
85
+ deviceTz = deviceTimezone;
86
+ }
87
+ catch {
88
+ console.warn(`[calendar] Invalid deviceTimezone "${deviceTimezone}", ignoring`);
89
+ }
90
+ }
91
+ let resolved;
92
+ let source;
93
+ if (calendarTimezone) {
94
+ resolved = calendarTimezone;
95
+ source = 'calendar_settings';
96
+ }
97
+ else if (eventTimezone) {
98
+ resolved = eventTimezone;
99
+ source = 'event';
100
+ }
101
+ else if (deviceTz) {
102
+ resolved = deviceTz;
103
+ source = 'device';
104
+ }
105
+ else {
106
+ resolved = 'UTC';
107
+ source = 'utc_fallback';
108
+ }
109
+ return {
110
+ resolved,
111
+ source,
112
+ calendarTimezone,
113
+ deviceTimezone: deviceTz,
114
+ timezoneMismatch: !!(calendarTimezone && deviceTz && calendarTimezone !== deviceTz),
115
+ };
116
+ }
117
+ /**
118
+ * Format a time range for display
119
+ */
120
+ function formatTimeRange(start, end, timezone) {
121
+ if (start.date)
122
+ return 'All day';
123
+ const startDate = new Date(start.dateTime);
124
+ const endDate = new Date(end.dateTime);
125
+ const timeOptions = {
126
+ hour: 'numeric',
127
+ minute: '2-digit',
128
+ timeZone: timezone
129
+ };
130
+ const startTime = startDate.toLocaleTimeString('en-US', timeOptions);
131
+ const endTime = endDate.toLocaleTimeString('en-US', timeOptions);
132
+ return `${startTime}–${endTime}`;
133
+ }
134
+ /**
135
+ * Format events as human-readable agenda-style text
136
+ */
137
+ export function formatEventsAsText(events, tzInfo) {
138
+ if (events.length === 0) {
139
+ return 'No events found in the specified time range.';
140
+ }
141
+ const timezone = tzInfo.resolved;
142
+ // Group events by day for agenda-style output
143
+ const byDay = new Map();
144
+ for (const event of events) {
145
+ const dateStr = event.start.dateTime || event.start.date;
146
+ if (!dateStr)
147
+ continue;
148
+ const date = new Date(dateStr);
149
+ const dayKey = date.toLocaleDateString('en-US', {
150
+ weekday: 'long',
151
+ month: 'short',
152
+ day: 'numeric',
153
+ timeZone: timezone
154
+ });
155
+ if (!byDay.has(dayKey))
156
+ byDay.set(dayKey, []);
157
+ byDay.get(dayKey).push(event);
158
+ }
159
+ // Add reference date header to ground the LLM in the current date
160
+ const now = new Date();
161
+ const todayStr = now.toLocaleDateString('en-US', {
162
+ weekday: 'long',
163
+ month: 'long',
164
+ day: 'numeric',
165
+ year: 'numeric',
166
+ timeZone: timezone
167
+ });
168
+ const lines = [];
169
+ lines.push(`Reference: Today is ${todayStr}`);
170
+ const sourceLabel = tzInfo.source === 'calendar_settings' ? 'from Google Calendar settings'
171
+ : tzInfo.source === 'event' ? 'from event data — Google Calendar settings unavailable'
172
+ : tzInfo.source === 'device' ? 'from device — Google Calendar settings unavailable'
173
+ : 'UTC fallback — could not determine user timezone';
174
+ lines.push(`Timezone: ${timezone} (${sourceLabel})`);
175
+ if (tzInfo.timezoneMismatch) {
176
+ lines.push(`NOTE: Calendar account timezone (${tzInfo.calendarTimezone}) differs from device timezone (${tzInfo.deviceTimezone}).`);
177
+ }
178
+ if (tzInfo.source === 'utc_fallback') {
179
+ lines.push(`WARNING: Times are shown in UTC. They may not match the user's local time.`);
180
+ }
181
+ lines.push(`Calendar: ${events.length} event${events.length !== 1 ? 's' : ''}\n`);
182
+ for (const [day, dayEvents] of byDay) {
183
+ lines.push(`**${day}**`);
184
+ for (const event of dayEvents) {
185
+ const time = formatTimeRange(event.start, event.end, timezone);
186
+ const location = event.location ? ` @ ${event.location}` : '';
187
+ // Extract meeting link if available
188
+ let meetLink = '';
189
+ if (event.conferenceData?.entryPoints) {
190
+ const videoEntry = event.conferenceData.entryPoints.find((ep) => ep.entryPointType === 'video');
191
+ if (videoEntry?.uri) {
192
+ meetLink = ` [Join: ${videoEntry.uri}]`;
193
+ }
194
+ }
195
+ else if (event.hangoutLink) {
196
+ meetLink = ` [Join: ${event.hangoutLink}]`;
197
+ }
198
+ lines.push(` ${time} - ${event.summary}${location}${meetLink}`);
199
+ lines.push(` [id: ${event.id}]`);
200
+ }
201
+ lines.push('');
202
+ }
203
+ return wrapUntrustedContent(lines.join('\n'), 'google-workspace:calendar:events');
204
+ }
205
+ /**
206
+ * Get current time in user's calendar timezone
207
+ * Essential for preventing LLM date hallucinations
208
+ */
209
+ export async function handleGetCurrentTime(params) {
210
+ await initializeServices();
211
+ // Resolve email - uses instance account if not provided, validates if provided
212
+ const email = await resolveEmail(params);
213
+ return accountManager.withTokenRenewal(email, async () => {
214
+ try {
215
+ // Fast-fail auth gate: throw clear error instead of helper's silent UTC fallback
216
+ const tokenStatus = await accountManager.validateToken(email);
217
+ if (!tokenStatus.valid || !tokenStatus.token) {
218
+ throw new McpError(ErrorCode.InvalidRequest, 'Authentication required');
219
+ }
220
+ const timezone = await getUserCalendarTimezone(email);
221
+ const now = new Date();
222
+ // Format date components
223
+ const dateOptions = {
224
+ year: 'numeric',
225
+ month: '2-digit',
226
+ day: '2-digit',
227
+ timeZone: timezone
228
+ };
229
+ const timeOptions = {
230
+ hour: '2-digit',
231
+ minute: '2-digit',
232
+ second: '2-digit',
233
+ hour12: false,
234
+ timeZone: timezone
235
+ };
236
+ const dayOptions = {
237
+ weekday: 'long',
238
+ timeZone: timezone
239
+ };
240
+ // Get formatted parts
241
+ const dateParts = now.toLocaleDateString('en-CA', dateOptions); // YYYY-MM-DD format
242
+ const timePart = now.toLocaleTimeString('en-US', timeOptions);
243
+ const dayOfWeek = now.toLocaleDateString('en-US', dayOptions);
244
+ // Build day-to-date lookup table for the next 14 days
245
+ // This prevents LLM hallucinations about which day a date falls on
246
+ const upcomingDays = {};
247
+ const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
248
+ for (let i = 0; i < 14; i++) {
249
+ const futureDate = new Date(now.getTime() + i * 24 * 60 * 60 * 1000);
250
+ const futureDateStr = futureDate.toLocaleDateString('en-CA', {
251
+ year: 'numeric',
252
+ month: '2-digit',
253
+ day: '2-digit',
254
+ timeZone: timezone
255
+ });
256
+ const futureDayName = dayNames[futureDate.getDay()];
257
+ // For the first week, use plain day names; for second week, prefix with "next"
258
+ const key = i < 7
259
+ ? (i === 0 ? 'today' : (i === 1 ? 'tomorrow' : futureDayName))
260
+ : `next ${futureDayName}`;
261
+ upcomingDays[key] = futureDateStr;
262
+ }
263
+ return {
264
+ datetime: now.toISOString(),
265
+ timezone,
266
+ date: dateParts,
267
+ time: timePart,
268
+ dayOfWeek,
269
+ formatted: `${dayOfWeek}, ${dateParts} ${timePart} (${timezone})`,
270
+ upcomingDays
271
+ };
272
+ }
273
+ catch (error) {
274
+ if (error instanceof McpError)
275
+ throw error;
276
+ throw new McpError(ErrorCode.InternalError, `Failed to get current time: ${error instanceof Error ? error.message : 'Unknown error'}`);
277
+ }
278
+ });
279
+ }
280
+ /**
281
+ * Find free/busy time slots using the freebusy API
282
+ */
283
+ export async function handleFindFreeSlots(params) {
284
+ await initializeServices();
285
+ const rawParams = params;
286
+ const { attendees } = params;
287
+ const timeMin = readAliasedString(rawParams, 'time_min', 'timeMin');
288
+ const timeMax = readAliasedString(rawParams, 'time_max', 'timeMax');
289
+ const minSlotDurationMinutes = readAliasedNumber(rawParams, 'min_slot_duration_minutes', 'minSlotDurationMinutes') ?? 30;
290
+ // Resolve email - uses instance account if not provided, validates if provided
291
+ const email = await resolveEmail(params);
292
+ if (attendees) {
293
+ attendees.forEach(a => validateEmail(a));
294
+ }
295
+ return accountManager.withTokenRenewal(email, async () => {
296
+ try {
297
+ const tokenStatus = await accountManager.validateToken(email);
298
+ if (!tokenStatus.valid || !tokenStatus.token) {
299
+ throw new McpError(ErrorCode.InvalidRequest, 'Authentication required');
300
+ }
301
+ const oauth2Client = await accountManager.getAuthClient();
302
+ oauth2Client.setCredentials(tokenStatus.token);
303
+ const calendar = google.calendar({ version: 'v3', auth: oauth2Client });
304
+ // Get user's timezone from calendar settings (via shared helper)
305
+ const timezone = await getUserCalendarTimezone(email);
306
+ // Default to today → 7 days from now
307
+ const now = new Date();
308
+ const defaultTimeMin = now.toISOString();
309
+ const defaultTimeMax = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000).toISOString();
310
+ const queryTimeMin = timeMin || defaultTimeMin;
311
+ const queryTimeMax = timeMax || defaultTimeMax;
312
+ // Build items list (user + optional attendees)
313
+ const items = [{ id: email }];
314
+ if (attendees) {
315
+ attendees.forEach(a => items.push({ id: a }));
316
+ }
317
+ // Query freebusy
318
+ const response = await calendar.freebusy.query({
319
+ requestBody: {
320
+ timeMin: queryTimeMin,
321
+ timeMax: queryTimeMax,
322
+ timeZone: timezone,
323
+ items
324
+ }
325
+ });
326
+ const calendars = response.data.calendars || {};
327
+ const results = {};
328
+ for (const [calId, calData] of Object.entries(calendars)) {
329
+ const busyPeriods = calData.busy || [];
330
+ // Calculate free slots between busy periods
331
+ const freeSlots = [];
332
+ let previousEnd = new Date(queryTimeMin);
333
+ const sortedBusy = busyPeriods
334
+ .map((b) => ({ start: new Date(b.start), end: new Date(b.end) }))
335
+ .sort((a, b) => a.start.getTime() - b.start.getTime());
336
+ for (const busy of sortedBusy) {
337
+ const gapMinutes = (busy.start.getTime() - previousEnd.getTime()) / (1000 * 60);
338
+ if (gapMinutes >= minSlotDurationMinutes) {
339
+ freeSlots.push({
340
+ start: previousEnd.toISOString(),
341
+ end: busy.start.toISOString()
342
+ });
343
+ }
344
+ if (busy.end > previousEnd) {
345
+ previousEnd = busy.end;
346
+ }
347
+ }
348
+ // Check for free slot at the end
349
+ const endTime = new Date(queryTimeMax);
350
+ const finalGapMinutes = (endTime.getTime() - previousEnd.getTime()) / (1000 * 60);
351
+ if (finalGapMinutes >= minSlotDurationMinutes) {
352
+ freeSlots.push({
353
+ start: previousEnd.toISOString(),
354
+ end: queryTimeMax
355
+ });
356
+ }
357
+ results[calId] = {
358
+ busy: busyPeriods,
359
+ free: freeSlots
360
+ };
361
+ }
362
+ return wrapUntrustedJsonStrings({
363
+ timezone,
364
+ timeRange: { start: queryTimeMin, end: queryTimeMax },
365
+ calendars: results
366
+ }, 'google-workspace:calendar:freebusy');
367
+ }
368
+ catch (error) {
369
+ if (error instanceof McpError)
370
+ throw error;
371
+ throw new McpError(ErrorCode.InternalError, `Failed to find free slots: ${error instanceof Error ? error.message : 'Unknown error'}`);
372
+ }
373
+ });
374
+ }
375
+ /**
376
+ * List all calendars the user has access to (own + shared calendars)
377
+ */
378
+ export async function handleListWorkspaceCalendars(params) {
379
+ await initializeServices();
380
+ // Resolve email - uses instance account if not provided, validates if provided
381
+ const email = await resolveEmail(params);
382
+ return accountManager.withTokenRenewal(email, async () => {
383
+ try {
384
+ const calendars = await calendarService.listCalendars(email);
385
+ return wrapUntrustedJsonStrings(calendars, 'google-workspace:calendar:list');
386
+ }
387
+ catch (error) {
388
+ if (error instanceof McpError)
389
+ throw error;
390
+ throw new McpError(ErrorCode.InternalError, `Failed to list calendars: ${error instanceof Error ? error.message : 'Unknown error'}`);
391
+ }
392
+ });
393
+ }
394
+ export async function handleListWorkspaceCalendarEvents(params) {
395
+ await initializeServices();
396
+ // Support both snake_case (canonical per MCP convention) and camelCase (backwards compatible)
397
+ const maxResults = params.max_results ?? params.maxResults;
398
+ const query = params.query;
399
+ const timeMin = readAliasedString(params, 'time_min', 'timeMin');
400
+ const timeMax = readAliasedString(params, 'time_max', 'timeMax');
401
+ const pageToken = readAliasedString(params, 'page_token', 'pageToken');
402
+ const returnJson = readAliasedBoolean(params, 'return_json', 'returnJson') ?? false;
403
+ const calendarId = readAliasedString(params, 'calendar_id', 'calendarId');
404
+ const deviceTimezone = readAliasedString(params, 'device_timezone', 'deviceTimezone');
405
+ const unbounded = params.unbounded;
406
+ // Resolve email - uses instance account if not provided, validates if provided
407
+ const email = await resolveEmail(params);
408
+ // Catch common parameter mistakes
409
+ if ('start' in params || 'startDate' in params || 'startTime' in params) {
410
+ const paramName = 'start' in params ? 'start' : ('startDate' in params ? 'startDate' : 'startTime');
411
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: '${paramName}' is not supported. Use 'time_min' instead (ISO date string). ` +
412
+ `Example: { "email": "user@example.com", "time_min": "2024-01-01T00:00:00Z" }`);
413
+ }
414
+ if ('end' in params || 'endDate' in params || 'endTime' in params) {
415
+ const paramName = 'end' in params ? 'end' : ('endDate' in params ? 'endDate' : 'endTime');
416
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: '${paramName}' is not supported. Use 'time_max' instead (ISO date string). ` +
417
+ `Example: { "email": "user@example.com", "time_max": "2024-12-31T23:59:59Z" }`);
418
+ }
419
+ if ('limit' in params) {
420
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: 'limit' is not supported. Use 'max_results' instead. ` +
421
+ `Example: { "email": "user@example.com", "max_results": 10 }`);
422
+ }
423
+ return accountManager.withTokenRenewal(email, async () => {
424
+ try {
425
+ // Apply default time window unless explicitly unbounded
426
+ // Note: Google Calendar API requires timeMin when using orderBy: 'startTime'
427
+ const now = new Date();
428
+ let effectiveTimeMin = timeMin;
429
+ let effectiveTimeMax = timeMax;
430
+ // Always default timeMin to now (required for orderBy: 'startTime')
431
+ if (!effectiveTimeMin) {
432
+ effectiveTimeMin = now.toISOString();
433
+ }
434
+ // Only apply default timeMax if not unbounded
435
+ if (!unbounded && !effectiveTimeMax) {
436
+ effectiveTimeMax = new Date(now.getTime() + DEFAULT_TIME_WINDOW_DAYS * 24 * 60 * 60 * 1000).toISOString();
437
+ }
438
+ // When unbounded: true, timeMax stays undefined (all future events)
439
+ // Cap maxResults to prevent token explosions
440
+ const effectiveMaxResults = Math.min(maxResults || DEFAULT_MAX_RESULTS, MAX_RESULTS_CAP);
441
+ const events = await calendarService.getEvents({
442
+ email,
443
+ query,
444
+ maxResults: effectiveMaxResults,
445
+ timeMin: effectiveTimeMin,
446
+ timeMax: effectiveTimeMax,
447
+ pageToken,
448
+ calendarId
449
+ });
450
+ // Resolve timezone with full source transparency
451
+ const tzInfo = await resolveTimezone(email, events[0]?.start?.timeZone, deviceTimezone);
452
+ // Return JSON if requested, otherwise format as human-readable text
453
+ if (returnJson) {
454
+ return wrapUntrustedJsonStrings({
455
+ timezoneInfo: {
456
+ resolved: tzInfo.resolved,
457
+ source: tzInfo.source,
458
+ calendarTimezone: tzInfo.calendarTimezone,
459
+ deviceTimezone: tzInfo.deviceTimezone,
460
+ timezoneMismatch: tzInfo.timezoneMismatch,
461
+ },
462
+ referenceTimeUTC: new Date().toISOString(),
463
+ events
464
+ }, 'google-workspace:calendar:events');
465
+ }
466
+ return formatEventsAsText(events, tzInfo);
467
+ }
468
+ catch (error) {
469
+ throw new McpError(ErrorCode.InternalError, `Failed to list calendar events: ${error instanceof Error ? error.message : 'Unknown error'}`);
470
+ }
471
+ });
472
+ }
473
+ export async function handleGetWorkspaceCalendarEvent(params) {
474
+ await initializeServices();
475
+ const eventId = readAliasedString(params, 'event_id', 'eventId');
476
+ const calendarId = readAliasedString(params, 'calendar_id', 'calendarId');
477
+ // Resolve email - uses instance account if not provided, validates if provided
478
+ const email = await resolveEmail(params);
479
+ if (!eventId) {
480
+ throw new McpError(ErrorCode.InvalidParams, 'Event ID is required');
481
+ }
482
+ return accountManager.withTokenRenewal(email, async () => {
483
+ try {
484
+ return wrapUntrustedJsonStrings(await calendarService.getEvent(email, eventId, calendarId), `google-workspace:calendar:event/${eventId}`);
485
+ }
486
+ catch (error) {
487
+ throw new McpError(ErrorCode.InternalError, `Failed to get calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
488
+ }
489
+ });
490
+ }
491
+ export async function handleCreateWorkspaceCalendarEvent(params) {
492
+ await initializeServices();
493
+ const { summary, description, location, start, end, attendees, attachments, recurrence, reminders, transparency } = params;
494
+ const calendarId = readAliasedString(params, 'calendar_id', 'calendarId');
495
+ const colorId = readAliasedString(params, 'color_id', 'colorId');
496
+ // Resolve email - uses instance account if not provided, validates if provided
497
+ const email = await resolveEmail(params);
498
+ // Catch common parameter mistakes
499
+ if ('title' in params || 'name' in params) {
500
+ const paramName = 'title' in params ? 'title' : 'name';
501
+ const paramValue = params[paramName];
502
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: '${paramName}' is not supported. Use 'summary' instead. ` +
503
+ `Example: { "email": "user@example.com", "summary": "${paramValue}", "start": {...}, "end": {...} }`);
504
+ }
505
+ if ('startTime' in params || 'startDate' in params) {
506
+ const paramName = 'startTime' in params ? 'startTime' : 'startDate';
507
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: '${paramName}' is not supported. Use 'start' object instead. ` +
508
+ `Example: { "start": { "dateTime": "2024-01-15T09:00:00-06:00", "timeZone": "America/Chicago" } }`);
509
+ }
510
+ if ('endTime' in params || 'endDate' in params) {
511
+ const paramName = 'endTime' in params ? 'endTime' : 'endDate';
512
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: '${paramName}' is not supported. Use 'end' object instead. ` +
513
+ `Example: { "end": { "dateTime": "2024-01-15T10:00:00-06:00", "timeZone": "America/Chicago" } }`);
514
+ }
515
+ // Check if start/end are strings instead of objects
516
+ if (start && typeof start === 'string') {
517
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: 'start' must be an object, not a string. ` +
518
+ `Example: { "start": { "dateTime": "${start}", "timeZone": "America/Chicago" } }`);
519
+ }
520
+ if (end && typeof end === 'string') {
521
+ throw new McpError(ErrorCode.InvalidParams, `Invalid parameter: 'end' must be an object, not a string. ` +
522
+ `Example: { "end": { "dateTime": "${end}", "timeZone": "America/Chicago" } }`);
523
+ }
524
+ if (!summary) {
525
+ throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: "summary" (event title). ' +
526
+ 'Example: { "email": "...", "summary": "Team Meeting", "start": {...}, "end": {...} }');
527
+ }
528
+ // Validate start: must have either dateTime (timed) OR date (all-day), not both
529
+ if (!start || (!start.dateTime && !start.date)) {
530
+ throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: "start" with either "dateTime" (for timed events) or "date" (for all-day events). ' +
531
+ 'Timed: { "start": { "dateTime": "2024-01-15T09:00:00-06:00", "timeZone": "America/Chicago" } } ' +
532
+ 'All-day: { "start": { "date": "2024-01-15" } }');
533
+ }
534
+ if (start.dateTime && start.date) {
535
+ throw new McpError(ErrorCode.InvalidParams, 'Invalid parameter: "start" cannot have both "dateTime" and "date". Use "dateTime" for timed events or "date" for all-day events.');
536
+ }
537
+ // Validate end: must have either dateTime (timed) OR date (all-day), not both
538
+ if (!end || (!end.dateTime && !end.date)) {
539
+ throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: "end" with either "dateTime" (for timed events) or "date" (for all-day events). ' +
540
+ 'Timed: { "end": { "dateTime": "2024-01-15T10:00:00-06:00", "timeZone": "America/Chicago" } } ' +
541
+ 'All-day: { "end": { "date": "2024-01-16" } } (end date is EXCLUSIVE)');
542
+ }
543
+ if (end.dateTime && end.date) {
544
+ throw new McpError(ErrorCode.InvalidParams, 'Invalid parameter: "end" cannot have both "dateTime" and "date". Use "dateTime" for timed events or "date" for all-day events.');
545
+ }
546
+ // Validate consistency: both start and end must use same format
547
+ const startIsAllDay = !!start.date;
548
+ const endIsAllDay = !!end.date;
549
+ if (startIsAllDay !== endIsAllDay) {
550
+ throw new McpError(ErrorCode.InvalidParams, 'Inconsistent parameters: "start" and "end" must both use "dateTime" (timed events) or both use "date" (all-day events). Cannot mix formats.');
551
+ }
552
+ if (attendees) {
553
+ attendees.forEach((attendee) => validateEmail(attendee.email));
554
+ }
555
+ return accountManager.withTokenRenewal(email, async () => {
556
+ try {
557
+ const createdEvent = await calendarService.createEvent({
558
+ email,
559
+ summary,
560
+ description,
561
+ location,
562
+ start,
563
+ end,
564
+ attendees,
565
+ attachments: attachments?.map((attachment) => ({
566
+ driveFileId: attachment.driveFileId,
567
+ content: attachment.content,
568
+ name: attachment.name,
569
+ mimeType: attachment.mimeType,
570
+ size: attachment.size
571
+ })),
572
+ calendarId,
573
+ recurrence,
574
+ // Normalize reminders: if overrides provided but useDefault not set, default to false
575
+ reminders: reminders?.overrides && reminders.useDefault === undefined
576
+ ? { ...reminders, useDefault: false }
577
+ : reminders,
578
+ colorId,
579
+ transparency
580
+ });
581
+ return wrapUntrustedJsonStrings(createdEvent, 'google-workspace:calendar:event/create');
582
+ }
583
+ catch (error) {
584
+ // Check if this is a CalendarError with a specific code (e.g., PERMISSION_DENIED)
585
+ if (error instanceof CalendarError) {
586
+ throw new McpError(ErrorCode.InvalidParams, error.message, error.details);
587
+ }
588
+ throw new McpError(ErrorCode.InternalError, `Failed to create calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
589
+ }
590
+ });
591
+ }
592
+ export async function handleManageWorkspaceCalendarEvent(params) {
593
+ await initializeServices();
594
+ const { action, comment } = params;
595
+ const eventId = readAliasedString(params, 'event_id', 'eventId');
596
+ const newTimes = (params.new_times ?? params.newTimes);
597
+ const colorId = readAliasedString(params, 'color_id', 'colorId');
598
+ // Resolve email - uses instance account if not provided, validates if provided
599
+ const email = await resolveEmail(params);
600
+ if (!eventId) {
601
+ throw new McpError(ErrorCode.InvalidParams, 'Event ID is required');
602
+ }
603
+ if (!action) {
604
+ throw new McpError(ErrorCode.InvalidParams, 'Action is required');
605
+ }
606
+ return accountManager.withTokenRenewal(email, async () => {
607
+ try {
608
+ const managedEvent = await calendarService.manageEvent({
609
+ email,
610
+ eventId,
611
+ action,
612
+ comment,
613
+ newTimes,
614
+ colorId
615
+ });
616
+ return wrapUntrustedJsonStrings(managedEvent, `google-workspace:calendar:event/${eventId}`);
617
+ }
618
+ catch (error) {
619
+ throw new McpError(ErrorCode.InternalError, `Failed to manage calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
620
+ }
621
+ });
622
+ }
623
+ export async function handleDeleteWorkspaceCalendarEvent(params) {
624
+ await initializeServices();
625
+ const eventId = readAliasedString(params, 'event_id', 'eventId');
626
+ const sendUpdates = readAliasedString(params, 'send_updates', 'sendUpdates');
627
+ const deletionScope = readAliasedString(params, 'deletion_scope', 'deletionScope');
628
+ // Resolve email - uses instance account if not provided, validates if provided
629
+ const email = await resolveEmail(params);
630
+ if (!eventId) {
631
+ throw new McpError(ErrorCode.InvalidParams, 'Event ID is required');
632
+ }
633
+ // Validate deletionScope if provided
634
+ if (deletionScope && !['entire_series', 'this_and_following'].includes(deletionScope)) {
635
+ throw new McpError(ErrorCode.InvalidParams, 'Invalid deletion scope. Must be one of: entire_series, this_and_following');
636
+ }
637
+ return accountManager.withTokenRenewal(email, async () => {
638
+ try {
639
+ await calendarService.deleteEvent(email, eventId, sendUpdates, deletionScope);
640
+ // Return a success response object instead of void
641
+ return {
642
+ status: 'success',
643
+ message: 'Event deleted successfully',
644
+ details: deletionScope ?
645
+ `Event deleted with scope: ${deletionScope}` :
646
+ 'Event deleted completely'
647
+ };
648
+ }
649
+ catch (error) {
650
+ // Check if this is a CalendarError with a specific code
651
+ if (error instanceof CalendarError) {
652
+ throw new McpError(ErrorCode.InvalidParams, error.message, error.details);
653
+ }
654
+ throw new McpError(ErrorCode.InternalError, `Failed to delete calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
655
+ }
656
+ });
657
+ }
658
+ //# sourceMappingURL=calendar-handlers.js.map