@n24q02m/workspace 0.0.0-stage → 0.6.0-beta.1

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 (331) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +46 -0
  3. package/README.md +342 -2
  4. package/bin/cli.mjs +144 -0
  5. package/build/src/auth/account-context.d.ts +3 -0
  6. package/build/src/auth/account-context.d.ts.map +1 -0
  7. package/build/src/auth/account-context.js +17 -0
  8. package/build/src/auth/account-context.js.map +1 -0
  9. package/build/src/auth/account-context.test.d.ts +2 -0
  10. package/build/src/auth/account-context.test.d.ts.map +1 -0
  11. package/build/src/auth/account-context.test.js +30 -0
  12. package/build/src/auth/account-context.test.js.map +1 -0
  13. package/build/src/auth/account-store.d.ts +87 -0
  14. package/build/src/auth/account-store.d.ts.map +1 -0
  15. package/build/src/auth/account-store.js +187 -0
  16. package/build/src/auth/account-store.js.map +1 -0
  17. package/build/src/auth/account-store.test.d.ts +2 -0
  18. package/build/src/auth/account-store.test.d.ts.map +1 -0
  19. package/build/src/auth/account-store.test.js +264 -0
  20. package/build/src/auth/account-store.test.js.map +1 -0
  21. package/build/src/auth/add-account.d.ts +12 -0
  22. package/build/src/auth/add-account.d.ts.map +1 -0
  23. package/build/src/auth/add-account.js +95 -0
  24. package/build/src/auth/add-account.js.map +1 -0
  25. package/build/src/auth/add-account.test.d.ts +2 -0
  26. package/build/src/auth/add-account.test.d.ts.map +1 -0
  27. package/build/src/auth/add-account.test.js +155 -0
  28. package/build/src/auth/add-account.test.js.map +1 -0
  29. package/build/src/auth/cli-auth.d.ts +2 -0
  30. package/build/src/auth/cli-auth.d.ts.map +1 -0
  31. package/build/src/auth/cli-auth.js +47 -0
  32. package/build/src/auth/cli-auth.js.map +1 -0
  33. package/build/src/auth/cli-auth.test.d.ts +2 -0
  34. package/build/src/auth/cli-auth.test.d.ts.map +1 -0
  35. package/build/src/auth/cli-auth.test.js +78 -0
  36. package/build/src/auth/cli-auth.test.js.map +1 -0
  37. package/build/src/auth/consent-server.d.ts +43 -0
  38. package/build/src/auth/consent-server.d.ts.map +1 -0
  39. package/build/src/auth/consent-server.js +56 -0
  40. package/build/src/auth/consent-server.js.map +1 -0
  41. package/build/src/auth/credential-state.d.ts +7 -0
  42. package/build/src/auth/credential-state.d.ts.map +1 -0
  43. package/build/src/auth/credential-state.js +64 -0
  44. package/build/src/auth/credential-state.js.map +1 -0
  45. package/build/src/auth/credential-state.test.d.ts +2 -0
  46. package/build/src/auth/credential-state.test.d.ts.map +1 -0
  47. package/build/src/auth/credential-state.test.js +142 -0
  48. package/build/src/auth/credential-state.test.js.map +1 -0
  49. package/build/src/auth/loopback-consent.d.ts +23 -0
  50. package/build/src/auth/loopback-consent.d.ts.map +1 -0
  51. package/build/src/auth/loopback-consent.js +145 -0
  52. package/build/src/auth/loopback-consent.js.map +1 -0
  53. package/build/src/auth/loopback-consent.test.d.ts +2 -0
  54. package/build/src/auth/loopback-consent.test.d.ts.map +1 -0
  55. package/build/src/auth/loopback-consent.test.js +131 -0
  56. package/build/src/auth/loopback-consent.test.js.map +1 -0
  57. package/build/src/auth/oauth-setup.d.ts +10 -0
  58. package/build/src/auth/oauth-setup.d.ts.map +1 -0
  59. package/build/src/auth/oauth-setup.js +92 -0
  60. package/build/src/auth/oauth-setup.js.map +1 -0
  61. package/build/src/auth/oauth-setup.test.d.ts +2 -0
  62. package/build/src/auth/oauth-setup.test.d.ts.map +1 -0
  63. package/build/src/auth/oauth-setup.test.js +164 -0
  64. package/build/src/auth/oauth-setup.test.js.map +1 -0
  65. package/build/src/auth/subject-context.d.ts +2 -0
  66. package/build/src/auth/subject-context.d.ts.map +1 -0
  67. package/build/src/auth/subject-context.js +16 -0
  68. package/build/src/auth/subject-context.js.map +1 -0
  69. package/build/src/auth/subject-context.test.d.ts +2 -0
  70. package/build/src/auth/subject-context.test.d.ts.map +1 -0
  71. package/build/src/auth/subject-context.test.js +34 -0
  72. package/build/src/auth/subject-context.test.js.map +1 -0
  73. package/build/src/auth/workspace-auth.d.ts +47 -0
  74. package/build/src/auth/workspace-auth.d.ts.map +1 -0
  75. package/build/src/auth/workspace-auth.js +123 -0
  76. package/build/src/auth/workspace-auth.js.map +1 -0
  77. package/build/src/auth/workspace-auth.test.d.ts +2 -0
  78. package/build/src/auth/workspace-auth.test.d.ts.map +1 -0
  79. package/build/src/auth/workspace-auth.test.js +242 -0
  80. package/build/src/auth/workspace-auth.test.js.map +1 -0
  81. package/build/src/constants.d.ts +6 -0
  82. package/build/src/constants.d.ts.map +1 -0
  83. package/build/src/constants.js +11 -0
  84. package/build/src/constants.js.map +1 -0
  85. package/build/src/create-server.d.ts +13 -0
  86. package/build/src/create-server.d.ts.map +1 -0
  87. package/build/src/create-server.js +34 -0
  88. package/build/src/create-server.js.map +1 -0
  89. package/build/src/create-server.test.d.ts +2 -0
  90. package/build/src/create-server.test.d.ts.map +1 -0
  91. package/build/src/create-server.test.js +13 -0
  92. package/build/src/create-server.test.js.map +1 -0
  93. package/build/src/docs/calendar.md +15 -0
  94. package/build/src/docs/chat.md +15 -0
  95. package/build/src/docs/config.md +117 -0
  96. package/build/src/docs/docs.md +36 -0
  97. package/build/src/docs/drive.md +15 -0
  98. package/build/src/docs/forms.md +119 -0
  99. package/build/src/docs/gmail.md +18 -0
  100. package/build/src/docs/overview.md +52 -0
  101. package/build/src/docs/people.md +10 -0
  102. package/build/src/docs/sheets.md +10 -0
  103. package/build/src/docs/slides.md +26 -0
  104. package/build/src/docs/tasks.md +13 -0
  105. package/build/src/docs/time.md +11 -0
  106. package/build/src/init-server.d.ts +10 -0
  107. package/build/src/init-server.d.ts.map +1 -0
  108. package/build/src/init-server.js +13 -0
  109. package/build/src/init-server.js.map +1 -0
  110. package/build/src/init-server.test.d.ts +2 -0
  111. package/build/src/init-server.test.d.ts.map +1 -0
  112. package/build/src/init-server.test.js +15 -0
  113. package/build/src/init-server.test.js.map +1 -0
  114. package/build/src/main.d.ts +33 -0
  115. package/build/src/main.d.ts.map +1 -0
  116. package/build/src/main.js +120 -0
  117. package/build/src/main.js.map +1 -0
  118. package/build/src/main.test.d.ts +2 -0
  119. package/build/src/main.test.d.ts.map +1 -0
  120. package/build/src/main.test.js +204 -0
  121. package/build/src/main.test.js.map +1 -0
  122. package/build/src/services/FormsService.d.ts +89 -0
  123. package/build/src/services/FormsService.d.ts.map +1 -0
  124. package/build/src/services/FormsService.js +140 -0
  125. package/build/src/services/FormsService.js.map +1 -0
  126. package/build/src/services/FormsService.test.d.ts +2 -0
  127. package/build/src/services/FormsService.test.d.ts.map +1 -0
  128. package/build/src/services/FormsService.test.js +173 -0
  129. package/build/src/services/FormsService.test.js.map +1 -0
  130. package/build/src/tools/config.d.ts +19 -0
  131. package/build/src/tools/config.d.ts.map +1 -0
  132. package/build/src/tools/config.js +100 -0
  133. package/build/src/tools/config.js.map +1 -0
  134. package/build/src/tools/config.test.d.ts +2 -0
  135. package/build/src/tools/config.test.d.ts.map +1 -0
  136. package/build/src/tools/config.test.js +201 -0
  137. package/build/src/tools/config.test.js.map +1 -0
  138. package/build/src/tools/domains/calendar.d.ts +3 -0
  139. package/build/src/tools/domains/calendar.d.ts.map +1 -0
  140. package/build/src/tools/domains/calendar.js +14 -0
  141. package/build/src/tools/domains/calendar.js.map +1 -0
  142. package/build/src/tools/domains/chat.d.ts +3 -0
  143. package/build/src/tools/domains/chat.d.ts.map +1 -0
  144. package/build/src/tools/domains/chat.js +16 -0
  145. package/build/src/tools/domains/chat.js.map +1 -0
  146. package/build/src/tools/domains/docs.d.ts +8 -0
  147. package/build/src/tools/domains/docs.d.ts.map +1 -0
  148. package/build/src/tools/domains/docs.js +11 -0
  149. package/build/src/tools/domains/docs.js.map +1 -0
  150. package/build/src/tools/domains/docs.test.d.ts +2 -0
  151. package/build/src/tools/domains/docs.test.d.ts.map +1 -0
  152. package/build/src/tools/domains/docs.test.js +111 -0
  153. package/build/src/tools/domains/docs.test.js.map +1 -0
  154. package/build/src/tools/domains/drive.d.ts +3 -0
  155. package/build/src/tools/domains/drive.d.ts.map +1 -0
  156. package/build/src/tools/domains/drive.js +14 -0
  157. package/build/src/tools/domains/drive.js.map +1 -0
  158. package/build/src/tools/domains/factory.d.ts +24 -0
  159. package/build/src/tools/domains/factory.d.ts.map +1 -0
  160. package/build/src/tools/domains/factory.js +43 -0
  161. package/build/src/tools/domains/factory.js.map +1 -0
  162. package/build/src/tools/domains/factory.test.d.ts +2 -0
  163. package/build/src/tools/domains/factory.test.d.ts.map +1 -0
  164. package/build/src/tools/domains/factory.test.js +48 -0
  165. package/build/src/tools/domains/factory.test.js.map +1 -0
  166. package/build/src/tools/domains/forms.d.ts +9 -0
  167. package/build/src/tools/domains/forms.d.ts.map +1 -0
  168. package/build/src/tools/domains/forms.js +12 -0
  169. package/build/src/tools/domains/forms.js.map +1 -0
  170. package/build/src/tools/domains/forms.test.d.ts +2 -0
  171. package/build/src/tools/domains/forms.test.d.ts.map +1 -0
  172. package/build/src/tools/domains/forms.test.js +93 -0
  173. package/build/src/tools/domains/forms.test.js.map +1 -0
  174. package/build/src/tools/domains/gmail.d.ts +3 -0
  175. package/build/src/tools/domains/gmail.d.ts.map +1 -0
  176. package/build/src/tools/domains/gmail.js +17 -0
  177. package/build/src/tools/domains/gmail.js.map +1 -0
  178. package/build/src/tools/domains/index.d.ts +20 -0
  179. package/build/src/tools/domains/index.d.ts.map +1 -0
  180. package/build/src/tools/domains/index.js +230 -0
  181. package/build/src/tools/domains/index.js.map +1 -0
  182. package/build/src/tools/domains/people.d.ts +3 -0
  183. package/build/src/tools/domains/people.d.ts.map +1 -0
  184. package/build/src/tools/domains/people.js +5 -0
  185. package/build/src/tools/domains/people.js.map +1 -0
  186. package/build/src/tools/domains/sheets.d.ts +3 -0
  187. package/build/src/tools/domains/sheets.d.ts.map +1 -0
  188. package/build/src/tools/domains/sheets.js +5 -0
  189. package/build/src/tools/domains/sheets.js.map +1 -0
  190. package/build/src/tools/domains/slides.d.ts +3 -0
  191. package/build/src/tools/domains/slides.d.ts.map +1 -0
  192. package/build/src/tools/domains/slides.js +25 -0
  193. package/build/src/tools/domains/slides.js.map +1 -0
  194. package/build/src/tools/domains/tasks.d.ts +3 -0
  195. package/build/src/tools/domains/tasks.d.ts.map +1 -0
  196. package/build/src/tools/domains/tasks.js +14 -0
  197. package/build/src/tools/domains/tasks.js.map +1 -0
  198. package/build/src/tools/domains/time.d.ts +3 -0
  199. package/build/src/tools/domains/time.d.ts.map +1 -0
  200. package/build/src/tools/domains/time.js +6 -0
  201. package/build/src/tools/domains/time.js.map +1 -0
  202. package/build/src/tools/helpers/errors.d.ts +48 -0
  203. package/build/src/tools/helpers/errors.d.ts.map +1 -0
  204. package/build/src/tools/helpers/errors.js +290 -0
  205. package/build/src/tools/helpers/errors.js.map +1 -0
  206. package/build/src/tools/helpers/errors.test.d.ts +2 -0
  207. package/build/src/tools/helpers/errors.test.d.ts.map +1 -0
  208. package/build/src/tools/helpers/errors.test.js +220 -0
  209. package/build/src/tools/helpers/errors.test.js.map +1 -0
  210. package/build/src/tools/registry.d.ts +14 -0
  211. package/build/src/tools/registry.d.ts.map +1 -0
  212. package/build/src/tools/registry.js +276 -0
  213. package/build/src/tools/registry.js.map +1 -0
  214. package/build/src/tools/registry.test.d.ts +2 -0
  215. package/build/src/tools/registry.test.d.ts.map +1 -0
  216. package/build/src/tools/registry.test.js +321 -0
  217. package/build/src/tools/registry.test.js.map +1 -0
  218. package/build/src/transports/http.d.ts +7 -0
  219. package/build/src/transports/http.d.ts.map +1 -0
  220. package/build/src/transports/http.js +56 -0
  221. package/build/src/transports/http.js.map +1 -0
  222. package/build/src/transports/http.test.d.ts +2 -0
  223. package/build/src/transports/http.test.d.ts.map +1 -0
  224. package/build/src/transports/http.test.js +76 -0
  225. package/build/src/transports/http.test.js.map +1 -0
  226. package/build/src/vendored/auth/AuthManager.d.ts +7 -0
  227. package/build/src/vendored/auth/AuthManager.d.ts.map +1 -0
  228. package/build/src/vendored/auth/AuthManager.js +11 -0
  229. package/build/src/vendored/auth/AuthManager.js.map +1 -0
  230. package/build/src/vendored/services/CalendarService.d.ts +164 -0
  231. package/build/src/vendored/services/CalendarService.d.ts.map +1 -0
  232. package/build/src/vendored/services/CalendarService.js +726 -0
  233. package/build/src/vendored/services/CalendarService.js.map +1 -0
  234. package/build/src/vendored/services/CalendarValidation.d.ts +9 -0
  235. package/build/src/vendored/services/CalendarValidation.d.ts.map +1 -0
  236. package/build/src/vendored/services/CalendarValidation.js +125 -0
  237. package/build/src/vendored/services/CalendarValidation.js.map +1 -0
  238. package/build/src/vendored/services/ChatService.d.ts +90 -0
  239. package/build/src/vendored/services/ChatService.d.ts.map +1 -0
  240. package/build/src/vendored/services/ChatService.js +451 -0
  241. package/build/src/vendored/services/ChatService.js.map +1 -0
  242. package/build/src/vendored/services/DocsService.d.ts +109 -0
  243. package/build/src/vendored/services/DocsService.d.ts.map +1 -0
  244. package/build/src/vendored/services/DocsService.js +663 -0
  245. package/build/src/vendored/services/DocsService.js.map +1 -0
  246. package/build/src/vendored/services/DocsService.test.d.ts +2 -0
  247. package/build/src/vendored/services/DocsService.test.d.ts.map +1 -0
  248. package/build/src/vendored/services/DocsService.test.js +77 -0
  249. package/build/src/vendored/services/DocsService.test.js.map +1 -0
  250. package/build/src/vendored/services/DriveService.d.ts +117 -0
  251. package/build/src/vendored/services/DriveService.d.ts.map +1 -0
  252. package/build/src/vendored/services/DriveService.js +527 -0
  253. package/build/src/vendored/services/DriveService.js.map +1 -0
  254. package/build/src/vendored/services/DriveService.test.d.ts +2 -0
  255. package/build/src/vendored/services/DriveService.test.d.ts.map +1 -0
  256. package/build/src/vendored/services/DriveService.test.js +115 -0
  257. package/build/src/vendored/services/DriveService.test.js.map +1 -0
  258. package/build/src/vendored/services/GmailService.d.ts +137 -0
  259. package/build/src/vendored/services/GmailService.d.ts.map +1 -0
  260. package/build/src/vendored/services/GmailService.js +681 -0
  261. package/build/src/vendored/services/GmailService.js.map +1 -0
  262. package/build/src/vendored/services/PeopleService.d.ts +42 -0
  263. package/build/src/vendored/services/PeopleService.d.ts.map +1 -0
  264. package/build/src/vendored/services/PeopleService.js +168 -0
  265. package/build/src/vendored/services/PeopleService.js.map +1 -0
  266. package/build/src/vendored/services/SheetsService.d.ts +52 -0
  267. package/build/src/vendored/services/SheetsService.d.ts.map +1 -0
  268. package/build/src/vendored/services/SheetsService.js +262 -0
  269. package/build/src/vendored/services/SheetsService.js.map +1 -0
  270. package/build/src/vendored/services/SheetsService.test.d.ts +2 -0
  271. package/build/src/vendored/services/SheetsService.test.d.ts.map +1 -0
  272. package/build/src/vendored/services/SheetsService.test.js +104 -0
  273. package/build/src/vendored/services/SheetsService.test.js.map +1 -0
  274. package/build/src/vendored/services/SlidesService.d.ts +167 -0
  275. package/build/src/vendored/services/SlidesService.d.ts.map +1 -0
  276. package/build/src/vendored/services/SlidesService.js +887 -0
  277. package/build/src/vendored/services/SlidesService.js.map +1 -0
  278. package/build/src/vendored/services/TasksService.d.ts +97 -0
  279. package/build/src/vendored/services/TasksService.d.ts.map +1 -0
  280. package/build/src/vendored/services/TasksService.js +234 -0
  281. package/build/src/vendored/services/TasksService.js.map +1 -0
  282. package/build/src/vendored/services/TimeService.d.ts +29 -0
  283. package/build/src/vendored/services/TimeService.d.ts.map +1 -0
  284. package/build/src/vendored/services/TimeService.js +71 -0
  285. package/build/src/vendored/services/TimeService.js.map +1 -0
  286. package/build/src/vendored/utils/DriveQueryBuilder.d.ts +15 -0
  287. package/build/src/vendored/utils/DriveQueryBuilder.d.ts.map +1 -0
  288. package/build/src/vendored/utils/DriveQueryBuilder.js +17 -0
  289. package/build/src/vendored/utils/DriveQueryBuilder.js.map +1 -0
  290. package/build/src/vendored/utils/GaxiosConfig.d.ts +9 -0
  291. package/build/src/vendored/utils/GaxiosConfig.d.ts.map +1 -0
  292. package/build/src/vendored/utils/GaxiosConfig.js +30 -0
  293. package/build/src/vendored/utils/GaxiosConfig.js.map +1 -0
  294. package/build/src/vendored/utils/IdUtils.d.ts +13 -0
  295. package/build/src/vendored/utils/IdUtils.d.ts.map +1 -0
  296. package/build/src/vendored/utils/IdUtils.js +29 -0
  297. package/build/src/vendored/utils/IdUtils.js.map +1 -0
  298. package/build/src/vendored/utils/MimeHelper.d.ts +64 -0
  299. package/build/src/vendored/utils/MimeHelper.d.ts.map +1 -0
  300. package/build/src/vendored/utils/MimeHelper.js +174 -0
  301. package/build/src/vendored/utils/MimeHelper.js.map +1 -0
  302. package/build/src/vendored/utils/MimeHelper.test.d.ts +2 -0
  303. package/build/src/vendored/utils/MimeHelper.test.d.ts.map +1 -0
  304. package/build/src/vendored/utils/MimeHelper.test.js +47 -0
  305. package/build/src/vendored/utils/MimeHelper.test.js.map +1 -0
  306. package/build/src/vendored/utils/constants.d.ts +9 -0
  307. package/build/src/vendored/utils/constants.d.ts.map +1 -0
  308. package/build/src/vendored/utils/constants.js +9 -0
  309. package/build/src/vendored/utils/constants.js.map +1 -0
  310. package/build/src/vendored/utils/logger.d.ts +3 -0
  311. package/build/src/vendored/utils/logger.d.ts.map +1 -0
  312. package/build/src/vendored/utils/logger.js +15 -0
  313. package/build/src/vendored/utils/logger.js.map +1 -0
  314. package/build/src/vendored/utils/paths.d.ts +2 -0
  315. package/build/src/vendored/utils/paths.d.ts.map +1 -0
  316. package/build/src/vendored/utils/paths.js +19 -0
  317. package/build/src/vendored/utils/paths.js.map +1 -0
  318. package/build/src/vendored/utils/validation.d.ts +100 -0
  319. package/build/src/vendored/utils/validation.d.ts.map +1 -0
  320. package/build/src/vendored/utils/validation.js +161 -0
  321. package/build/src/vendored/utils/validation.js.map +1 -0
  322. package/build/src/version.d.ts +2 -0
  323. package/build/src/version.d.ts.map +1 -0
  324. package/build/src/version.js +29 -0
  325. package/build/src/version.js.map +1 -0
  326. package/build/src/version.test.d.ts +2 -0
  327. package/build/src/version.test.d.ts.map +1 -0
  328. package/build/src/version.test.js +19 -0
  329. package/build/src/version.test.js.map +1 -0
  330. package/build/tsconfig.tsbuildinfo +1 -0
  331. package/package.json +69 -4
@@ -0,0 +1,242 @@
1
+ import { mkdtempSync, rmSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { PerPluginStore, setHomeDirForTesting } from '@n24q02m/hull/storage';
5
+ import { google } from 'googleapis';
6
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
+ import { STORE_PLUGIN } from '../constants.js';
8
+ import { UNIDENTIFIED_ACCOUNT } from './account-store.js';
9
+ import { WorkspaceAuth } from './workspace-auth.js';
10
+ // id_token chỉ được đọc phần payload, không xác thực chữ ký -- JWT giả là đủ.
11
+ const b64 = (o) => Buffer.from(JSON.stringify(o), 'utf8').toString('base64url');
12
+ const fakeIdToken = (claims) => `${b64({ alg: 'none' })}.${b64(claims)}.sig`;
13
+ const probeOf = (auth) => auth;
14
+ describe('WorkspaceAuth', () => {
15
+ let testHomeDir;
16
+ beforeEach(() => {
17
+ process.env.GOOGLE_OAUTH_CLIENT_ID = 'cid';
18
+ process.env.GOOGLE_OAUTH_CLIENT_SECRET = 'sec';
19
+ // Isolate PerPluginStore's LocalFsBackend from the real ~/.better-workspace-mcp/config.json.
20
+ testHomeDir = mkdtempSync(join(tmpdir(), 'workspace-test-'));
21
+ setHomeDirForTesting(testHomeDir);
22
+ });
23
+ afterEach(() => {
24
+ vi.restoreAllMocks();
25
+ setHomeDirForTesting(null);
26
+ rmSync(testHomeDir, { recursive: true, force: true });
27
+ });
28
+ it('builds an OAuth2Client with stored credentials', async () => {
29
+ const auth = new WorkspaceAuth(['openid']);
30
+ await auth.saveTokens({ access_token: 'at', refresh_token: 'rt', expiry_date: Date.now() + 3600_000 }, { email: 'stored@example.com' });
31
+ const client = await auth.getAuthenticatedClient();
32
+ expect(client.credentials.access_token).toBe('at');
33
+ expect(client.credentials.refresh_token).toBe('rt');
34
+ await auth.clear();
35
+ });
36
+ it('throws a clear error when no token is stored', async () => {
37
+ const auth = new WorkspaceAuth(['openid']);
38
+ await auth.clear();
39
+ await expect(auth.getAuthenticatedClient()).rejects.toThrow(/not configured/i);
40
+ });
41
+ it('computes expiry_date from expires_in when absent', async () => {
42
+ const auth = new WorkspaceAuth(['openid']);
43
+ const before = Date.now();
44
+ // Google's raw token response: expires_in (relative seconds), no expiry_date.
45
+ await auth.saveTokens({ access_token: 'a', refresh_token: 'r', expires_in: 3600 }, { email: 'expiry@example.com' });
46
+ const client = await auth.getAuthenticatedClient();
47
+ expect(client.credentials.expiry_date).toBeGreaterThanOrEqual(before + 3600_000);
48
+ expect(client.credentials.expiry_date).toBeLessThanOrEqual(Date.now() + 3600_000);
49
+ await auth.clear();
50
+ });
51
+ it('uses a store plugin name without the -mcp suffix (avoids double -mcp on disk)', () => {
52
+ expect(STORE_PLUGIN).toBe('better-workspace');
53
+ expect(STORE_PLUGIN.endsWith('-mcp')).toBe(false);
54
+ });
55
+ it('persists an auto-refreshed access_token on the client "tokens" event, keeping the stored refresh_token', async () => {
56
+ const auth = new WorkspaceAuth(['openid']);
57
+ await auth.saveTokens({ access_token: 'at', refresh_token: 'rt', expiry_date: Date.now() + 3600_000 }, { email: 'refresh@example.com' });
58
+ const client = await auth.getAuthenticatedClient();
59
+ const saveTokensSpy = vi.spyOn(auth, 'saveTokens');
60
+ // google-auth-library emits 'tokens' with a fresh access_token but no
61
+ // refresh_token on a refresh grant -- simulate that here. EventEmitter
62
+ // invokes the listener (and thus the `void this.saveTokens(...)` call)
63
+ // synchronously, so the spy is already populated once emit() returns;
64
+ // await its captured promise instead of guessing a delay (the listener
65
+ // itself is deliberately fire-and-forget in production code).
66
+ client.emit('tokens', { access_token: 'new-at', expiry_date: Date.now() + 7200_000 });
67
+ expect(saveTokensSpy).toHaveBeenCalledTimes(1);
68
+ await saveTokensSpy.mock.results[0]?.value;
69
+ const refreshed = await auth.getAuthenticatedClient();
70
+ expect(refreshed.credentials.access_token).toBe('new-at');
71
+ expect(refreshed.credentials.refresh_token).toBe('rt'); // preserved from the original save
72
+ await auth.clear();
73
+ });
74
+ it('serves different credentials for two accounts', async () => {
75
+ const auth = new WorkspaceAuth(['openid']);
76
+ await auth.saveTokens({ access_token: 'at-one', refresh_token: 'rt-one' }, { email: 'one@example.com' });
77
+ await auth.saveTokens({ access_token: 'at-two', refresh_token: 'rt-two' }, { email: 'two@example.com' });
78
+ const one = await auth.getAuthenticatedClient('one@example.com');
79
+ const two = await auth.getAuthenticatedClient('two@example.com');
80
+ expect(one.credentials.access_token).toBe('at-one');
81
+ expect(two.credentials.access_token).toBe('at-two');
82
+ expect(one).not.toBe(two);
83
+ await auth.clear();
84
+ });
85
+ it('falls back to the primary account when no account is given', async () => {
86
+ const auth = new WorkspaceAuth(['openid']);
87
+ await auth.saveTokens({ access_token: 'at-one' }, { email: 'one@example.com' });
88
+ await auth.saveTokens({ access_token: 'at-two' }, { email: 'two@example.com' });
89
+ const client = await auth.getAuthenticatedClient();
90
+ expect(client.credentials.access_token).toBe('at-one');
91
+ await auth.clear();
92
+ });
93
+ it('names the unknown account in the error instead of silently using the primary', async () => {
94
+ const auth = new WorkspaceAuth(['openid']);
95
+ await auth.saveTokens({ access_token: 'at-one' }, { email: 'one@example.com' });
96
+ await expect(auth.getAuthenticatedClient('ghost@example.com')).rejects.toThrow(/ghost@example\.com/);
97
+ // the message also lists what IS configured, so the caller can self-correct
98
+ await expect(auth.getAuthenticatedClient('ghost@example.com')).rejects.toThrow(/one@example\.com/);
99
+ await auth.clear();
100
+ });
101
+ it('derives the account email from the id_token when none is passed', async () => {
102
+ const auth = new WorkspaceAuth(['openid']);
103
+ const email = await auth.saveTokens({
104
+ access_token: 'at',
105
+ id_token: fakeIdToken({ email: 'derived@example.com' })
106
+ });
107
+ expect(email).toBe('derived@example.com');
108
+ expect((await auth.listAccounts()).accounts).toEqual(['derived@example.com']);
109
+ await auth.clear();
110
+ });
111
+ it('refuses to store tokens it cannot name an account for', async () => {
112
+ const auth = new WorkspaceAuth(['openid']);
113
+ await expect(auth.saveTokens({ access_token: 'at' })).rejects.toThrow(/without an account email/i);
114
+ });
115
+ it('honours makePrimary when saving a second account', async () => {
116
+ const auth = new WorkspaceAuth(['openid']);
117
+ await auth.saveTokens({ access_token: 'a' }, { email: 'one@example.com' });
118
+ await auth.saveTokens({ access_token: 'b' }, { email: 'two@example.com' });
119
+ expect((await auth.listAccounts()).primary).toBe('one@example.com');
120
+ await auth.saveTokens({ access_token: 'c' }, { email: 'three@example.com', makePrimary: true });
121
+ expect((await auth.listAccounts()).primary).toBe('three@example.com');
122
+ await auth.clear();
123
+ });
124
+ it('lists, re-primaries and removes accounts', async () => {
125
+ const auth = new WorkspaceAuth(['openid']);
126
+ await auth.saveTokens({ access_token: 'a' }, { email: 'one@example.com' });
127
+ await auth.saveTokens({ access_token: 'b' }, { email: 'two@example.com' });
128
+ expect(await auth.listAccounts()).toEqual({
129
+ accounts: ['one@example.com', 'two@example.com'],
130
+ primary: 'one@example.com'
131
+ });
132
+ await auth.setPrimary('two@example.com');
133
+ expect((await auth.listAccounts()).primary).toBe('two@example.com');
134
+ expect(await auth.removeAccount('one@example.com')).toEqual({ removed: true, newPrimary: 'two@example.com' });
135
+ expect((await auth.listAccounts()).accounts).toEqual(['two@example.com']);
136
+ await auth.clear();
137
+ });
138
+ it('adopts a legacy M1 blob by asking Google for the account email', async () => {
139
+ // Blob phẳng M1 không có id_token -> chỉ còn cách hỏi userinfo.
140
+ await new PerPluginStore(STORE_PLUGIN).save({ access_token: 'legacy-at', refresh_token: 'legacy-rt' });
141
+ const auth = new WorkspaceAuth(['openid']);
142
+ const spy = vi.spyOn(probeOf(auth), 'fetchAccountEmail').mockResolvedValue('adopted@example.com');
143
+ const client = await auth.getAuthenticatedClient();
144
+ expect(spy).toHaveBeenCalledTimes(1);
145
+ expect(client.credentials.access_token).toBe('legacy-at');
146
+ // adoption phải giữ refresh_token -- đó là thứ duy nhất không lấy lại được
147
+ expect(client.credentials.refresh_token).toBe('legacy-rt');
148
+ expect((await auth.listAccounts()).accounts).toEqual(['adopted@example.com']);
149
+ await auth.clear();
150
+ });
151
+ it('adopts the legacy blob only once -- the next call reads the migrated v2 blob', async () => {
152
+ await new PerPluginStore(STORE_PLUGIN).save({ access_token: 'legacy-at', refresh_token: 'legacy-rt' });
153
+ const auth = new WorkspaceAuth(['openid']);
154
+ const spy = vi.spyOn(probeOf(auth), 'fetchAccountEmail').mockResolvedValue('adopted@example.com');
155
+ await auth.getAuthenticatedClient();
156
+ await auth.getAuthenticatedClient();
157
+ expect(spy).toHaveBeenCalledTimes(1); // second call no longer touches the network
158
+ await auth.clear();
159
+ });
160
+ it('never records the placeholder used while probing the legacy blob as an account', async () => {
161
+ // Probe client phải KHÔNG gắn listener 'tokens': nếu gắn, một lần refresh
162
+ // giữa lúc probe sẽ ghi một account tên '(legacy)' vào store.
163
+ await new PerPluginStore(STORE_PLUGIN).save({ access_token: 'legacy-at', refresh_token: 'legacy-rt' });
164
+ const auth = new WorkspaceAuth(['openid']);
165
+ vi.spyOn(probeOf(auth), 'fetchAccountEmail').mockImplementation(async (client) => {
166
+ // google-auth-library would emit this if it refreshed mid-probe
167
+ ;
168
+ client.emit('tokens', {
169
+ access_token: 'probe-refreshed'
170
+ });
171
+ return 'adopted@example.com';
172
+ });
173
+ await auth.getAuthenticatedClient();
174
+ expect((await auth.listAccounts()).accounts).toEqual(['adopted@example.com']);
175
+ await auth.clear();
176
+ });
177
+ it('keeps the legacy blob and explains what to do when the email cannot be resolved', async () => {
178
+ await new PerPluginStore(STORE_PLUGIN).save({ access_token: 'legacy-at' });
179
+ const auth = new WorkspaceAuth(['openid']);
180
+ vi.spyOn(probeOf(auth), 'fetchAccountEmail').mockResolvedValue(undefined);
181
+ await expect(auth.getAuthenticatedClient()).rejects.toThrow(/account_add|re-authorize/i);
182
+ // token cũ KHÔNG bị xoá
183
+ expect(await new PerPluginStore(STORE_PLUGIN).load()).not.toBeNull();
184
+ await auth.clear();
185
+ });
186
+ it('lets a fresh consent complete even while an unadoptable legacy blob is on disk', async () => {
187
+ // Chuỗi deadlock: adopt thất bại (cần mạng) -> state về awaiting_setup -> server
188
+ // mở OAuth -> người dùng consent xong -> lần ghi ĐÓ bị guard chặn -> startup fail,
189
+ // và setup_reset thì cần server đang chạy. saveTokens phải đi qua được trạng thái này.
190
+ await new PerPluginStore(STORE_PLUGIN).save({ access_token: 'legacy-at', refresh_token: 'legacy-rt' });
191
+ const auth = new WorkspaceAuth(['openid']);
192
+ const email = await auth.saveTokens({ access_token: 'fresh-at', refresh_token: 'fresh-rt' }, {
193
+ email: 'fresh@example.com'
194
+ });
195
+ expect(email).toBe('fresh@example.com');
196
+ const { accounts, primary } = await auth.listAccounts();
197
+ expect(accounts).toEqual([UNIDENTIFIED_ACCOUNT, 'fresh@example.com']);
198
+ expect(primary).toBe('fresh@example.com');
199
+ // Server dùng được ngay: client mặc định là account vừa consent.
200
+ const client = await auth.getAuthenticatedClient();
201
+ expect(client.credentials.access_token).toBe('fresh-at');
202
+ // Và blob cũ không bị mất -- xoá được bằng account_remove.
203
+ expect((await auth.removeAccount(UNIDENTIFIED_ACCOUNT)).removed).toBe(true);
204
+ await auth.clear();
205
+ });
206
+ it('does not try to adopt a legacy blob when a specific account was asked for', async () => {
207
+ await new PerPluginStore(STORE_PLUGIN).save({ access_token: 'legacy-at' });
208
+ const auth = new WorkspaceAuth(['openid']);
209
+ const spy = vi.spyOn(probeOf(auth), 'fetchAccountEmail').mockResolvedValue('adopted@example.com');
210
+ await expect(auth.getAuthenticatedClient('someone@example.com')).rejects.toThrow(/not configured/i);
211
+ expect(spy).not.toHaveBeenCalled();
212
+ await auth.clear();
213
+ });
214
+ describe('fetchAccountEmail', () => {
215
+ it('lowercases the email returned by the Google userinfo endpoint', async () => {
216
+ const auth = new WorkspaceAuth(['openid']);
217
+ vi.spyOn(google, 'oauth2').mockReturnValue({
218
+ userinfo: { get: async () => ({ data: { email: 'Probe@Example.com' } }) }
219
+ });
220
+ expect(await probeOf(auth).fetchAccountEmail({})).toBe('probe@example.com');
221
+ });
222
+ it('returns undefined when userinfo answers without an email', async () => {
223
+ const auth = new WorkspaceAuth(['openid']);
224
+ vi.spyOn(google, 'oauth2').mockReturnValue({
225
+ userinfo: { get: async () => ({ data: {} }) }
226
+ });
227
+ expect(await probeOf(auth).fetchAccountEmail({})).toBeUndefined();
228
+ });
229
+ it('returns undefined instead of throwing when the userinfo call fails', async () => {
230
+ const auth = new WorkspaceAuth(['openid']);
231
+ vi.spyOn(google, 'oauth2').mockReturnValue({
232
+ userinfo: {
233
+ get: async () => {
234
+ throw new Error('401 invalid_token');
235
+ }
236
+ }
237
+ });
238
+ expect(await probeOf(auth).fetchAccountEmail({})).toBeUndefined();
239
+ });
240
+ });
241
+ });
242
+ //# sourceMappingURL=workspace-auth.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-auth.test.js","sourceRoot":"","sources":["../../../src/auth/workspace-auth.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,8EAA8E;AAC9E,MAAM,GAAG,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,CA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AC,CAAA;oBACtC,CAAC;iBACF;aACO,CAAC,CAAA;YAEX,MAAM,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,CAAA;QACnE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare const SERVER_NAME = "workspace";
2
+ export declare const STORE_PLUGIN = "better-workspace";
3
+ export declare const GOOGLE_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/v2/auth";
4
+ export declare const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
5
+ export declare const BASE_SCOPES: string[];
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,cAAc,CAAA;AAMtC,eAAO,MAAM,YAAY,qBAAqB,CAAA;AAE9C,eAAO,MAAM,oBAAoB,iDAAiD,CAAA;AAClF,eAAO,MAAM,gBAAgB,wCAAwC,CAAA;AAGrE,eAAO,MAAM,WAAW,UAAiC,CAAA"}
@@ -0,0 +1,11 @@
1
+ export const SERVER_NAME = 'workspace';
2
+ // Credential namespace for hull PerPluginStore. Deliberately NOT renamed with SERVER_NAME:
3
+ // hull keys the on-disk directory off this slug (~/.better-workspace/). Earlier releases wrote
4
+ // to ~/.better-workspace-mcp/, which hull still reads as a read-only fallback (no writes there),
5
+ // so renaming the slug would move the store and orphan those credentials.
6
+ export const STORE_PLUGIN = 'better-workspace';
7
+ export const GOOGLE_AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/v2/auth';
8
+ export const GOOGLE_TOKEN_URL = 'https://oauth2.googleapis.com/token';
9
+ // openid+email → id_token with a stable `sub`. Workspace domains added per-service.
10
+ export const BASE_SCOPES = ['openid', 'email', 'profile'];
11
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAA;AAEtC,2FAA2F;AAC3F,+FAA+F;AAC/F,iGAAiG;AACjG,0EAA0E;AAC1E,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAA;AAE9C,MAAM,CAAC,MAAM,oBAAoB,GAAG,8CAA8C,CAAA;AAClF,MAAM,CAAC,MAAM,gBAAgB,GAAG,qCAAqC,CAAA;AAErE,oFAAoF;AACpF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Shared MCP Server Factory
3
+ * Creates a configured MCP server instance reusable across transports
4
+ */
5
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
6
+ /**
7
+ * Create a configured MCP server with all tools registered.
8
+ * Single-account M1 -- no client factory param (unlike better-notion-mcp);
9
+ * tools resolve the Google client from credential-state internally. Used
10
+ * later by HTTP (M3); created now for parity with the other servers.
11
+ */
12
+ export declare function createMCPServer(): Server;
13
+ //# sourceMappingURL=create-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-server.d.ts","sourceRoot":"","sources":["../../src/create-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAiBlE;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAOxC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shared MCP Server Factory
3
+ * Creates a configured MCP server instance reusable across transports
4
+ */
5
+ import { readFileSync } from 'node:fs';
6
+ import { dirname, join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
9
+ import { SERVER_NAME } from './constants.js';
10
+ import { registerTools } from './tools/registry.js';
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+ function getVersion() {
14
+ try {
15
+ const pkgPath = join(__dirname, '..', 'package.json');
16
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
17
+ return pkg.version ?? '0.0.0';
18
+ }
19
+ catch {
20
+ return '0.0.0';
21
+ }
22
+ }
23
+ /**
24
+ * Create a configured MCP server with all tools registered.
25
+ * Single-account M1 -- no client factory param (unlike better-notion-mcp);
26
+ * tools resolve the Google client from credential-state internally. Used
27
+ * later by HTTP (M3); created now for parity with the other servers.
28
+ */
29
+ export function createMCPServer() {
30
+ const server = new Server({ name: `@n24q02m/${SERVER_NAME}`, version: getVersion() }, { capabilities: { tools: {}, resources: {} } });
31
+ registerTools(server);
32
+ return server;
33
+ }
34
+ //# sourceMappingURL=create-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-server.js","sourceRoot":"","sources":["../../src/create-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAErC,SAAS,UAAU;IACjB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAA;QACrD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;QACtD,OAAO,GAAG,CAAC,OAAO,IAAI,OAAO,CAAA;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,YAAY,WAAW,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAC1D,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,CAC/C,CAAA;IACD,aAAa,CAAC,MAAM,CAAC,CAAA;IACrB,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=create-server.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-server.test.d.ts","sourceRoot":"","sources":["../../src/create-server.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+ vi.mock('./tools/registry.js', () => ({ registerTools: vi.fn() }));
4
+ import { createMCPServer } from './create-server.js';
5
+ import { registerTools } from './tools/registry.js';
6
+ describe('createMCPServer', () => {
7
+ it('returns a Server with tools registered', () => {
8
+ const server = createMCPServer();
9
+ expect(server).toBeInstanceOf(Server);
10
+ expect(registerTools).toHaveBeenCalledWith(server);
11
+ });
12
+ });
13
+ //# sourceMappingURL=create-server.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-server.test.js","sourceRoot":"","sources":["../../src/create-server.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,EAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;AAElE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;QAEhC,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QACrC,MAAM,CAAC,aAAa,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAA;IACpD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,15 @@
1
+ # Calendar Tool
2
+
3
+ ## Actions
4
+ - listCalendars
5
+ - createEvent
6
+ - listEvents
7
+ - getEvent
8
+ - deleteEvent
9
+ - updateEvent
10
+ - respondToEvent
11
+ - findFreeTime
12
+
13
+ ## Parameters
14
+
15
+ - account (optional): email of the Google account to use; defaults to the primary account.
@@ -0,0 +1,15 @@
1
+ # Chat Tool
2
+
3
+ ## Actions
4
+ - listSpaces
5
+ - sendMessage
6
+ - findSpaceByName
7
+ - getMessages
8
+ - sendDm
9
+ - findDmByEmail
10
+ - listThreads
11
+ - setUpSpace
12
+
13
+ ## Parameters
14
+
15
+ - account (optional): email of the Google account to use; defaults to the primary account.
@@ -0,0 +1,117 @@
1
+ # config
2
+
3
+ Manage server configuration, Google credential state, and the set of Google
4
+ accounts this server can act as. Does not require a configured Google account --
5
+ works independently of the domain tools.
6
+
7
+ ## Actions
8
+
9
+ | Action | Description |
10
+ | --- | --- |
11
+ | `status` | Returns `{state, configured, accounts, primary}` -- the credential state (`awaiting_setup` \| `configured`), the configured account emails, and which one is primary. |
12
+ | `setup_start` | Returns instructions to trigger the browser Google OAuth consent flow (stdio mode: restart the server). |
13
+ | `setup_reset` | Clears stored credentials for **every** account and returns to `awaiting_setup`. |
14
+ | `setup_complete` | Re-checks stored credentials after an external config change. |
15
+ | `set` | No mutable runtime settings -- returns an informational no-op. |
16
+ | `cache_clear` | No client-side cache -- returns an informational no-op. |
17
+ | `account_add` | Starts a browser consent flow for one more Google account. Returns `{open, next, default_account}`; open the `open` URL to complete the consent. Works in stdio and HTTP. |
18
+ | `account_list` | Returns `{accounts, primary}`. |
19
+ | `account_remove` | Forgets the account named in `account`. Returns `{removed, primary}`. |
20
+ | `account_set_default` | Makes the account named in `account` the primary one. Returns `{primary}`. |
21
+
22
+ ## Accounts
23
+
24
+ Every domain tool takes `account="<email>"`. Omit it and the call runs against
25
+ the primary account.
26
+
27
+ - The first account stored becomes the primary automatically.
28
+ - Removing the primary promotes one of the remaining accounts -- `account_remove`
29
+ reports which one in `primary`.
30
+ - Removing the last account clears the credential blob and puts the server back
31
+ in `awaiting_setup`; domain tools are refused again until an account is
32
+ configured.
33
+ - Naming an account that is not configured is an **error that names the
34
+ account**, and lists what is configured. The call is never silently rerouted to
35
+ the primary -- a silent fallback would act on the wrong mailbox.
36
+ - Emails are the account keys, matched case-insensitively and stored lowercased.
37
+ - `account_remove` and `account_set_default` require `account` and have no
38
+ default: falling back to the primary would remove or reshuffle the wrong
39
+ account. `account_set_default` on an unknown account is an error.
40
+
41
+ ### account_add
42
+
43
+ - Works in **both** transports, and picks the flow for you. In stdio it stands a
44
+ temporary consent server on a loopback port; over HTTP it hands you a URL that
45
+ comes back to a fixed `/accounts/callback` on the running server, because a
46
+ Web OAuth client's redirect URI has to be registered in advance.
47
+ - **What that means for an HTTP deployment**: `<PUBLIC_URL>/accounts/callback`
48
+ must be one of the redirect URIs registered on the Google **Web** OAuth client
49
+ the server runs with. It is a second URI, separate from the
50
+ `<PUBLIC_URL>/callback` used to sign in to the server itself -- registering only
51
+ the latter leaves `account_add` failing at Google with
52
+ `redirect_uri_mismatch`, after the consent screen rather than before it. Both
53
+ are built from `PUBLIC_URL`, so that value has to be the exact public origin;
54
+ Google compares redirect URIs as strings.
55
+ - The account that gets added is filed under **you**, not under whoever the
56
+ consent screen was signed in as. Those are two different identities: the caller
57
+ is identified by the `sub` in the token that authenticated this tool call, and
58
+ the account by the email in the tokens Google returns. The `sub` travels to the
59
+ callback in a signed, single-use state parameter, so nobody else's bucket can
60
+ receive the account -- and the state carries no authority to move your default
61
+ account, which is why `value="primary"` is stdio only.
62
+ - Requires `GOOGLE_OAUTH_CLIENT_ID` and `GOOGLE_OAUTH_CLIENT_SECRET` in the
63
+ environment. The HTTP flow also needs `PUBLIC_URL` and `CREDENTIAL_SECRET`.
64
+ - Returns the URL immediately rather than blocking on the consent. Open it, sign
65
+ in as the account you want to add, then call `account_list` to confirm the
66
+ outcome.
67
+ - Which account gets added is decided by whom you sign in as on the consent
68
+ screen. `account_add` does **not** read the `account` parameter.
69
+ - Pass `value="primary"` to make the newly added account the primary one. This
70
+ is **stdio only**: over HTTP the request would have to travel in the URL and
71
+ back through Google, where anyone who obtained it could point your default at
72
+ an account of theirs. Remote callers get told it was ignored and should use
73
+ `account_set_default` instead. (Either way, the very first account in an empty
74
+ store becomes primary -- a store of accounts with no working default would be
75
+ broken.)
76
+ - The link is good for 10 minutes and works once. In stdio the temporary consent
77
+ server also closes itself after that window, so an abandoned flow does not hold
78
+ its port open. Call `account_add` again if the URL has gone stale.
79
+
80
+ ## key / value
81
+
82
+ `key` is accepted on the schema but unused. `value` is read only by `account_add`
83
+ (`value="primary"`).
84
+
85
+ ## Upgrading from the single-account layout
86
+
87
+ Credentials written before multi-account support are a single flat blob of tokens.
88
+ The first run afterwards adopts that blob into the multi-account layout, keyed by
89
+ the account's email:
90
+
91
+ - The email comes from the stored `id_token` when it is there. That needs no
92
+ network and is the usual case.
93
+ - Otherwise the server asks Google's userinfo endpoint, which needs network
94
+ access and a token that is still valid or refreshable.
95
+
96
+ If neither works, the state falls back to `awaiting_setup` and the server starts the
97
+ browser OAuth flow even though the stored token may still be good. Completing that
98
+ consent does work, and nothing is discarded: the newly authorized account is stored
99
+ and becomes the primary, and the old blob is carried across under the key
100
+ `(unidentified)` rather than being overwritten. `account_list` then shows two
101
+ entries:
102
+
103
+ ```json
104
+ { "accounts": ["(unidentified)", "you@example.com"], "primary": "you@example.com" }
105
+ ```
106
+
107
+ `(unidentified)` holds the tokens whose owner could not be determined. Nothing
108
+ routes to it -- it is never promoted to primary while a real account remains, and
109
+ no call can select it unless you name it. Remove it once the re-authorized account
110
+ is working:
111
+
112
+ ```json
113
+ { "action": "account_remove", "account": "(unidentified)" }
114
+ ```
115
+
116
+ After a successful adoption -- the usual case -- `account_list` shows exactly one
117
+ account and it is the primary.
@@ -0,0 +1,36 @@
1
+ # docs
2
+
3
+ Google Docs operations, dispatched by `action` to the vendored `DocsService`.
4
+
5
+ ## account
6
+
7
+ `account` is the email address of the Google account the call should act as.
8
+ Omit it and the call runs against the primary account. List what is configured,
9
+ and which one is primary, with `config(action="account_list")`. Naming an account
10
+ that is not configured is an error -- the call is never silently rerouted to the
11
+ primary.
12
+
13
+ ## Actions
14
+
15
+ | Action | Required params | Optional params | Description |
16
+ | --- | --- | --- | --- |
17
+ | `getText` | `documentId` | `tabId`, `limit`, `preview` | Read the document's text. Returns plain text for a single-tab document, or JSON with all tabs when the doc has more than one tab. Output defaults to 20,000 characters; `preview` uses 2,000 unless `limit` is supplied. `limit` accepts 1–100,000, and truncated output includes an explicit marker. |
18
+ | `create` | `title` | `content` | Create a new Google Doc, optionally seeded with initial text content. |
19
+ | `writeText` | `documentId`, `text` | `position` (default `"end"`), `tabId` | Insert text at `"beginning"`, `"end"`, or a positive integer character index. |
20
+ | `getSuggestions` | `documentId` | -- | List pending suggested edits (insertions, deletions, style and paragraph-style changes). |
21
+ | `replaceText` | `documentId`, `findText`, `replaceText` | `tabId` | Find-and-replace all occurrences of `findText` with `replaceText`, across all tabs unless `tabId` is given. |
22
+ | `formatText` | `documentId`, `formats` | `tabId` | Apply one or more formatting operations. Each entry in `formats` is `{startIndex, endIndex, style, url?}`; `style` is a heading level (`heading1`..`heading6`, `normalText`), a text style (`bold`, `italic`, `underline`, `strikethrough`), `"code"`, or `"link"` (requires `url`). |
23
+
24
+ ## Result shape
25
+
26
+ Every action returns the MCP `CallTool` result shape directly from
27
+ `DocsService` (`{content: [{type: "text", text}], isError?: true}`) -- the
28
+ `docs` tool does not re-wrap or transform it.
29
+
30
+ ## Examples
31
+
32
+ ```json
33
+ { "action": "getText", "documentId": "1AbCdEf...", "preview": true }
34
+ { "action": "writeText", "documentId": "1AbCdEf...", "text": "Hello", "position": "end" }
35
+ { "action": "formatText", "documentId": "1AbCdEf...", "formats": [{ "startIndex": 1, "endIndex": 6, "style": "bold" }] }
36
+ ```
@@ -0,0 +1,15 @@
1
+ # Drive Tool
2
+
3
+ ## Actions
4
+ - findFolder
5
+ - createFolder
6
+ - search
7
+ - trashFile
8
+ - renameFile
9
+ - getComments
10
+ - moveFile
11
+ - downloadFile
12
+
13
+ ## Parameters
14
+
15
+ - account (optional): email of the Google account to use; defaults to the primary account.