@withpica/mcp-server 1.3.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 (347) hide show
  1. package/.claude/settings.local.json +5 -0
  2. package/CHANGELOG.md +1850 -0
  3. package/README.md +304 -0
  4. package/assets/fonts/GeistSans-Light.woff2 +0 -0
  5. package/assets/fonts/InstrumentSerif-Italic.woff2 +0 -0
  6. package/assets/fonts/InstrumentSerif-Regular.woff2 +0 -0
  7. package/dist/apps/download.d.ts +2 -0
  8. package/dist/apps/download.d.ts.map +1 -0
  9. package/dist/apps/download.js +125 -0
  10. package/dist/apps/download.js.map +1 -0
  11. package/dist/apps/generated/shared-bundle.d.ts +5 -0
  12. package/dist/apps/generated/shared-bundle.d.ts.map +1 -0
  13. package/dist/apps/generated/shared-bundle.js +7 -0
  14. package/dist/apps/generated/shared-bundle.js.map +1 -0
  15. package/dist/apps/release.d.ts +2 -0
  16. package/dist/apps/release.d.ts.map +1 -0
  17. package/dist/apps/release.js +69 -0
  18. package/dist/apps/release.js.map +1 -0
  19. package/dist/apps/shared.d.ts +15 -0
  20. package/dist/apps/shared.d.ts.map +1 -0
  21. package/dist/apps/shared.js +480 -0
  22. package/dist/apps/shared.js.map +1 -0
  23. package/dist/apps/upload.d.ts +2 -0
  24. package/dist/apps/upload.d.ts.map +1 -0
  25. package/dist/apps/upload.js +280 -0
  26. package/dist/apps/upload.js.map +1 -0
  27. package/dist/config.d.ts +14 -0
  28. package/dist/config.d.ts.map +1 -0
  29. package/dist/config.js +73 -0
  30. package/dist/config.js.map +1 -0
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +35 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/prompts/index.d.ts +86 -0
  36. package/dist/prompts/index.d.ts.map +1 -0
  37. package/dist/prompts/index.js +645 -0
  38. package/dist/prompts/index.js.map +1 -0
  39. package/dist/resources/agent-guide.d.ts +15 -0
  40. package/dist/resources/agent-guide.d.ts.map +1 -0
  41. package/dist/resources/agent-guide.js +284 -0
  42. package/dist/resources/agent-guide.js.map +1 -0
  43. package/dist/resources/index.d.ts +66 -0
  44. package/dist/resources/index.d.ts.map +1 -0
  45. package/dist/resources/index.js +510 -0
  46. package/dist/resources/index.js.map +1 -0
  47. package/dist/resources/llms-primer.d.ts +2 -0
  48. package/dist/resources/llms-primer.d.ts.map +1 -0
  49. package/dist/resources/llms-primer.js +68 -0
  50. package/dist/resources/llms-primer.js.map +1 -0
  51. package/dist/resources/required-schemas.generated.d.ts +455 -0
  52. package/dist/resources/required-schemas.generated.d.ts.map +1 -0
  53. package/dist/resources/required-schemas.generated.js +1041 -0
  54. package/dist/resources/required-schemas.generated.js.map +1 -0
  55. package/dist/resources/required-schemas.source.d.ts +53 -0
  56. package/dist/resources/required-schemas.source.d.ts.map +1 -0
  57. package/dist/resources/required-schemas.source.js +493 -0
  58. package/dist/resources/required-schemas.source.js.map +1 -0
  59. package/dist/resources/welcome.d.ts +14 -0
  60. package/dist/resources/welcome.d.ts.map +1 -0
  61. package/dist/resources/welcome.js +26 -0
  62. package/dist/resources/welcome.js.map +1 -0
  63. package/dist/server-instructions.d.ts +60 -0
  64. package/dist/server-instructions.d.ts.map +1 -0
  65. package/dist/server-instructions.js +93 -0
  66. package/dist/server-instructions.js.map +1 -0
  67. package/dist/server.d.ts +52 -0
  68. package/dist/server.d.ts.map +1 -0
  69. package/dist/server.js +334 -0
  70. package/dist/server.js.map +1 -0
  71. package/dist/tools/access-simulate.d.ts +23 -0
  72. package/dist/tools/access-simulate.d.ts.map +1 -0
  73. package/dist/tools/access-simulate.js +162 -0
  74. package/dist/tools/access-simulate.js.map +1 -0
  75. package/dist/tools/agent-identity.d.ts +36 -0
  76. package/dist/tools/agent-identity.d.ts.map +1 -0
  77. package/dist/tools/agent-identity.js +274 -0
  78. package/dist/tools/agent-identity.js.map +1 -0
  79. package/dist/tools/agreement-types.d.ts +27 -0
  80. package/dist/tools/agreement-types.d.ts.map +1 -0
  81. package/dist/tools/agreement-types.js +281 -0
  82. package/dist/tools/agreement-types.js.map +1 -0
  83. package/dist/tools/agreements.d.ts +20 -0
  84. package/dist/tools/agreements.d.ts.map +1 -0
  85. package/dist/tools/agreements.js +282 -0
  86. package/dist/tools/agreements.js.map +1 -0
  87. package/dist/tools/analytics.d.ts +20 -0
  88. package/dist/tools/analytics.d.ts.map +1 -0
  89. package/dist/tools/analytics.js +130 -0
  90. package/dist/tools/analytics.js.map +1 -0
  91. package/dist/tools/app-tools.d.ts +15 -0
  92. package/dist/tools/app-tools.d.ts.map +1 -0
  93. package/dist/tools/app-tools.js +388 -0
  94. package/dist/tools/app-tools.js.map +1 -0
  95. package/dist/tools/assets.d.ts +25 -0
  96. package/dist/tools/assets.d.ts.map +1 -0
  97. package/dist/tools/assets.js +454 -0
  98. package/dist/tools/assets.js.map +1 -0
  99. package/dist/tools/audio-files.d.ts +20 -0
  100. package/dist/tools/audio-files.d.ts.map +1 -0
  101. package/dist/tools/audio-files.js +409 -0
  102. package/dist/tools/audio-files.js.map +1 -0
  103. package/dist/tools/audit.d.ts +19 -0
  104. package/dist/tools/audit.d.ts.map +1 -0
  105. package/dist/tools/audit.js +58 -0
  106. package/dist/tools/audit.js.map +1 -0
  107. package/dist/tools/auth.d.ts +22 -0
  108. package/dist/tools/auth.d.ts.map +1 -0
  109. package/dist/tools/auth.js +212 -0
  110. package/dist/tools/auth.js.map +1 -0
  111. package/dist/tools/bulk.d.ts +22 -0
  112. package/dist/tools/bulk.d.ts.map +1 -0
  113. package/dist/tools/bulk.js +164 -0
  114. package/dist/tools/bulk.js.map +1 -0
  115. package/dist/tools/calendar.d.ts +15 -0
  116. package/dist/tools/calendar.d.ts.map +1 -0
  117. package/dist/tools/calendar.js +68 -0
  118. package/dist/tools/calendar.js.map +1 -0
  119. package/dist/tools/collaborators.d.ts +21 -0
  120. package/dist/tools/collaborators.d.ts.map +1 -0
  121. package/dist/tools/collaborators.js +381 -0
  122. package/dist/tools/collaborators.js.map +1 -0
  123. package/dist/tools/comparisons.d.ts +22 -0
  124. package/dist/tools/comparisons.d.ts.map +1 -0
  125. package/dist/tools/comparisons.js +80 -0
  126. package/dist/tools/comparisons.js.map +1 -0
  127. package/dist/tools/credits.d.ts +39 -0
  128. package/dist/tools/credits.d.ts.map +1 -0
  129. package/dist/tools/credits.js +541 -0
  130. package/dist/tools/credits.js.map +1 -0
  131. package/dist/tools/custody-hints.d.ts +16 -0
  132. package/dist/tools/custody-hints.d.ts.map +1 -0
  133. package/dist/tools/custody-hints.js +27 -0
  134. package/dist/tools/custody-hints.js.map +1 -0
  135. package/dist/tools/custody.d.ts +38 -0
  136. package/dist/tools/custody.d.ts.map +1 -0
  137. package/dist/tools/custody.js +281 -0
  138. package/dist/tools/custody.js.map +1 -0
  139. package/dist/tools/dashboard.d.ts +22 -0
  140. package/dist/tools/dashboard.d.ts.map +1 -0
  141. package/dist/tools/dashboard.js +258 -0
  142. package/dist/tools/dashboard.js.map +1 -0
  143. package/dist/tools/directory.d.ts +15 -0
  144. package/dist/tools/directory.d.ts.map +1 -0
  145. package/dist/tools/directory.js +107 -0
  146. package/dist/tools/directory.js.map +1 -0
  147. package/dist/tools/discovery.d.ts +49 -0
  148. package/dist/tools/discovery.d.ts.map +1 -0
  149. package/dist/tools/discovery.js +851 -0
  150. package/dist/tools/discovery.js.map +1 -0
  151. package/dist/tools/disputes.d.ts +18 -0
  152. package/dist/tools/disputes.d.ts.map +1 -0
  153. package/dist/tools/disputes.js +62 -0
  154. package/dist/tools/disputes.js.map +1 -0
  155. package/dist/tools/documents.d.ts +15 -0
  156. package/dist/tools/documents.d.ts.map +1 -0
  157. package/dist/tools/documents.js +37 -0
  158. package/dist/tools/documents.js.map +1 -0
  159. package/dist/tools/duplicates.d.ts +25 -0
  160. package/dist/tools/duplicates.d.ts.map +1 -0
  161. package/dist/tools/duplicates.js +108 -0
  162. package/dist/tools/duplicates.js.map +1 -0
  163. package/dist/tools/enrichment.d.ts +56 -0
  164. package/dist/tools/enrichment.d.ts.map +1 -0
  165. package/dist/tools/enrichment.js +616 -0
  166. package/dist/tools/enrichment.js.map +1 -0
  167. package/dist/tools/exports.d.ts +19 -0
  168. package/dist/tools/exports.d.ts.map +1 -0
  169. package/dist/tools/exports.js +184 -0
  170. package/dist/tools/exports.js.map +1 -0
  171. package/dist/tools/feedback.d.ts +22 -0
  172. package/dist/tools/feedback.d.ts.map +1 -0
  173. package/dist/tools/feedback.js +100 -0
  174. package/dist/tools/feedback.js.map +1 -0
  175. package/dist/tools/forbidden-keywords.d.ts +62 -0
  176. package/dist/tools/forbidden-keywords.d.ts.map +1 -0
  177. package/dist/tools/forbidden-keywords.js +99 -0
  178. package/dist/tools/forbidden-keywords.js.map +1 -0
  179. package/dist/tools/gap-hints.d.ts +53 -0
  180. package/dist/tools/gap-hints.d.ts.map +1 -0
  181. package/dist/tools/gap-hints.js +245 -0
  182. package/dist/tools/gap-hints.js.map +1 -0
  183. package/dist/tools/groups.d.ts +29 -0
  184. package/dist/tools/groups.d.ts.map +1 -0
  185. package/dist/tools/groups.js +186 -0
  186. package/dist/tools/groups.js.map +1 -0
  187. package/dist/tools/import-documents.d.ts +21 -0
  188. package/dist/tools/import-documents.d.ts.map +1 -0
  189. package/dist/tools/import-documents.js +206 -0
  190. package/dist/tools/import-documents.js.map +1 -0
  191. package/dist/tools/import.d.ts +31 -0
  192. package/dist/tools/import.d.ts.map +1 -0
  193. package/dist/tools/import.js +610 -0
  194. package/dist/tools/import.js.map +1 -0
  195. package/dist/tools/index.d.ts +293 -0
  196. package/dist/tools/index.d.ts.map +1 -0
  197. package/dist/tools/index.js +1182 -0
  198. package/dist/tools/index.js.map +1 -0
  199. package/dist/tools/integrations.d.ts +19 -0
  200. package/dist/tools/integrations.d.ts.map +1 -0
  201. package/dist/tools/integrations.js +120 -0
  202. package/dist/tools/integrations.js.map +1 -0
  203. package/dist/tools/labels.d.ts +20 -0
  204. package/dist/tools/labels.d.ts.map +1 -0
  205. package/dist/tools/labels.js +48 -0
  206. package/dist/tools/labels.js.map +1 -0
  207. package/dist/tools/licensing.d.ts +40 -0
  208. package/dist/tools/licensing.d.ts.map +1 -0
  209. package/dist/tools/licensing.js +436 -0
  210. package/dist/tools/licensing.js.map +1 -0
  211. package/dist/tools/memory.d.ts +21 -0
  212. package/dist/tools/memory.d.ts.map +1 -0
  213. package/dist/tools/memory.js +120 -0
  214. package/dist/tools/memory.js.map +1 -0
  215. package/dist/tools/metadata.d.ts +15 -0
  216. package/dist/tools/metadata.d.ts.map +1 -0
  217. package/dist/tools/metadata.js +1532 -0
  218. package/dist/tools/metadata.js.map +1 -0
  219. package/dist/tools/multimedia.d.ts +19 -0
  220. package/dist/tools/multimedia.d.ts.map +1 -0
  221. package/dist/tools/multimedia.js +371 -0
  222. package/dist/tools/multimedia.js.map +1 -0
  223. package/dist/tools/my-reported-issues.d.ts +32 -0
  224. package/dist/tools/my-reported-issues.d.ts.map +1 -0
  225. package/dist/tools/my-reported-issues.js +123 -0
  226. package/dist/tools/my-reported-issues.js.map +1 -0
  227. package/dist/tools/notes.d.ts +21 -0
  228. package/dist/tools/notes.d.ts.map +1 -0
  229. package/dist/tools/notes.js +115 -0
  230. package/dist/tools/notes.js.map +1 -0
  231. package/dist/tools/notifications.d.ts +28 -0
  232. package/dist/tools/notifications.d.ts.map +1 -0
  233. package/dist/tools/notifications.js +417 -0
  234. package/dist/tools/notifications.js.map +1 -0
  235. package/dist/tools/onboarding.d.ts +24 -0
  236. package/dist/tools/onboarding.d.ts.map +1 -0
  237. package/dist/tools/onboarding.js +81 -0
  238. package/dist/tools/onboarding.js.map +1 -0
  239. package/dist/tools/people.d.ts +254 -0
  240. package/dist/tools/people.d.ts.map +1 -0
  241. package/dist/tools/people.js +481 -0
  242. package/dist/tools/people.js.map +1 -0
  243. package/dist/tools/projects.d.ts +20 -0
  244. package/dist/tools/projects.d.ts.map +1 -0
  245. package/dist/tools/projects.js +316 -0
  246. package/dist/tools/projects.js.map +1 -0
  247. package/dist/tools/public-filter.d.ts +43 -0
  248. package/dist/tools/public-filter.d.ts.map +1 -0
  249. package/dist/tools/public-filter.js +356 -0
  250. package/dist/tools/public-filter.js.map +1 -0
  251. package/dist/tools/publishers.d.ts +30 -0
  252. package/dist/tools/publishers.d.ts.map +1 -0
  253. package/dist/tools/publishers.js +105 -0
  254. package/dist/tools/publishers.js.map +1 -0
  255. package/dist/tools/purchases.d.ts +27 -0
  256. package/dist/tools/purchases.d.ts.map +1 -0
  257. package/dist/tools/purchases.js +9 -0
  258. package/dist/tools/purchases.js.map +1 -0
  259. package/dist/tools/recording-attribution-hints.d.ts +24 -0
  260. package/dist/tools/recording-attribution-hints.d.ts.map +1 -0
  261. package/dist/tools/recording-attribution-hints.js +27 -0
  262. package/dist/tools/recording-attribution-hints.js.map +1 -0
  263. package/dist/tools/recordings.d.ts +96 -0
  264. package/dist/tools/recordings.d.ts.map +1 -0
  265. package/dist/tools/recordings.js +564 -0
  266. package/dist/tools/recordings.js.map +1 -0
  267. package/dist/tools/recovery-hints.d.ts +40 -0
  268. package/dist/tools/recovery-hints.d.ts.map +1 -0
  269. package/dist/tools/recovery-hints.js +827 -0
  270. package/dist/tools/recovery-hints.js.map +1 -0
  271. package/dist/tools/release-rich.d.ts +31 -0
  272. package/dist/tools/release-rich.d.ts.map +1 -0
  273. package/dist/tools/release-rich.js +245 -0
  274. package/dist/tools/release-rich.js.map +1 -0
  275. package/dist/tools/releases.d.ts +36 -0
  276. package/dist/tools/releases.d.ts.map +1 -0
  277. package/dist/tools/releases.js +649 -0
  278. package/dist/tools/releases.js.map +1 -0
  279. package/dist/tools/report-issue.d.ts +21 -0
  280. package/dist/tools/report-issue.d.ts.map +1 -0
  281. package/dist/tools/report-issue.js +101 -0
  282. package/dist/tools/report-issue.js.map +1 -0
  283. package/dist/tools/royalties.d.ts +23 -0
  284. package/dist/tools/royalties.d.ts.map +1 -0
  285. package/dist/tools/royalties.js +262 -0
  286. package/dist/tools/royalties.js.map +1 -0
  287. package/dist/tools/search.d.ts +30 -0
  288. package/dist/tools/search.d.ts.map +1 -0
  289. package/dist/tools/search.js +115 -0
  290. package/dist/tools/search.js.map +1 -0
  291. package/dist/tools/send.d.ts +17 -0
  292. package/dist/tools/send.d.ts.map +1 -0
  293. package/dist/tools/send.js +188 -0
  294. package/dist/tools/send.js.map +1 -0
  295. package/dist/tools/sessions.d.ts +18 -0
  296. package/dist/tools/sessions.d.ts.map +1 -0
  297. package/dist/tools/sessions.js +153 -0
  298. package/dist/tools/sessions.js.map +1 -0
  299. package/dist/tools/settings.d.ts +23 -0
  300. package/dist/tools/settings.d.ts.map +1 -0
  301. package/dist/tools/settings.js +365 -0
  302. package/dist/tools/settings.js.map +1 -0
  303. package/dist/tools/share-links.d.ts +22 -0
  304. package/dist/tools/share-links.d.ts.map +1 -0
  305. package/dist/tools/share-links.js +188 -0
  306. package/dist/tools/share-links.js.map +1 -0
  307. package/dist/tools/signup.d.ts +26 -0
  308. package/dist/tools/signup.d.ts.map +1 -0
  309. package/dist/tools/signup.js +266 -0
  310. package/dist/tools/signup.js.map +1 -0
  311. package/dist/tools/split-sheets.d.ts +25 -0
  312. package/dist/tools/split-sheets.d.ts.map +1 -0
  313. package/dist/tools/split-sheets.js +309 -0
  314. package/dist/tools/split-sheets.js.map +1 -0
  315. package/dist/tools/storage-config.d.ts +13 -0
  316. package/dist/tools/storage-config.d.ts.map +1 -0
  317. package/dist/tools/storage-config.js +245 -0
  318. package/dist/tools/storage-config.js.map +1 -0
  319. package/dist/tools/subscription.d.ts +60 -0
  320. package/dist/tools/subscription.d.ts.map +1 -0
  321. package/dist/tools/subscription.js +440 -0
  322. package/dist/tools/subscription.js.map +1 -0
  323. package/dist/tools/sync-placements.d.ts +31 -0
  324. package/dist/tools/sync-placements.d.ts.map +1 -0
  325. package/dist/tools/sync-placements.js +431 -0
  326. package/dist/tools/sync-placements.js.map +1 -0
  327. package/dist/tools/team.d.ts +22 -0
  328. package/dist/tools/team.d.ts.map +1 -0
  329. package/dist/tools/team.js +144 -0
  330. package/dist/tools/team.js.map +1 -0
  331. package/dist/tools/telegram.d.ts +21 -0
  332. package/dist/tools/telegram.d.ts.map +1 -0
  333. package/dist/tools/telegram.js +144 -0
  334. package/dist/tools/telegram.js.map +1 -0
  335. package/dist/tools/uploads.d.ts +17 -0
  336. package/dist/tools/uploads.d.ts.map +1 -0
  337. package/dist/tools/uploads.js +165 -0
  338. package/dist/tools/uploads.js.map +1 -0
  339. package/dist/tools/works.d.ts +71 -0
  340. package/dist/tools/works.d.ts.map +1 -0
  341. package/dist/tools/works.js +694 -0
  342. package/dist/tools/works.js.map +1 -0
  343. package/package.json +54 -0
  344. package/scripts/build-required-schemas.ts +233 -0
  345. package/scripts/bundle-apps.ts +61 -0
  346. package/scripts/refresh-schema-mirror.ts +182 -0
  347. package/server.json +20 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"welcome.js","sourceRoot":"","sources":["../../src/resources/welcome.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,uBAAuB;IACvB,yFAAyF;IACzF,oBAAoB;IACpB,uDAAuD;IACvD,iFAAiF;IACjF,oDAAoD;IACpD,yCAAyC;IACzC,mDAAmD;IACnD,8DAA8D;IAC9D,8CAA8C;IAC9C,iCAAiC;IACjC,gDAAgD,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Server-level instructions sent to agents on MCP handshake.
3
+ * Keep under 2000 chars — this is context budget, not documentation.
4
+ *
5
+ * Two variants per ADR-211 Phase 1 Primitive C:
6
+ * - SERVER_INSTRUCTIONS / SERVER_INSTRUCTIONS_AUTHENTICATED: full surface
7
+ * guidance. Selected when the binary has a connection key (PICA_API_KEY).
8
+ * - SERVER_INSTRUCTIONS_UNAUTHENTICATED: short lobby guidance pointing the
9
+ * agent at pica_signup_start (or pica_sign_in for existing users).
10
+ * Selected when the binary boots without PICA_API_KEY. The lobby
11
+ * surface is the 3 tools {pica_signup_start, pica_sign_in,
12
+ * pica_sign_out} — none of the catalog tools are reachable, so we
13
+ * skip the catalog-tool guidance.
14
+ *
15
+ * Block playbook: "document the high level of your server"
16
+ * Lowin: "instructions are context — design them as context"
17
+ */
18
+ export declare const SERVER_INSTRUCTIONS = "withPICA manages music catalog metadata \u2014 works, recordings, people, credits, agreements, rights. Tools are pica_<domain>_<verb>, 200+ of them, from npm as @withpica/mcp-server. If you see pica_execute, Execute Pica Action, or Search Platform Actions \u2014 that's @picahq/mcp (picaos.com), a different product with the same short name; don't route withPICA work there.\n\nStart here:\n- pica_dashboard_briefing \u2014 daily summary of what needs attention\n- pica_search_all \u2014 find any entity by name, ISWC, ISRC, or IPI\n- pica_works_query / pica_people_query \u2014 browse the catalog\n\nThe catalog is ALWAYS accessible via the tools above \u2014 zero setup, no integration required. If pica_integrations_status shows \"0 connected\" that refers to optional peer connectors (Google/Notion/Airtable/Telegram), NOT the catalog; call pica_works_query to check what's there.\n\nSpotify/YouTube URLs: call pica_import_streaming_link (Spotify/Deezer) or pica_import_youtube_link directly.\n\nAfter 3-5 catalog mutations or major state changes, call pica_dashboard_briefing and surface the delta to the user.\n\nKey patterns:\n- Read tools are safe to call freely (readOnlyHint=true)\n- _inspect tools take sections (e.g., pica_works_inspect sections: [\"health\", \"completeness\"])\n- Write tools confirm what changed; destructive tools (delete/merge) need two-step confirmation with a token\n- Errors include \"suggestion\" and \"next_tool\" for recovery\n- Enrichment: use pica_resolve_work / pica_resolve_person / pica_resolve_recording \u2014 fan out over Spotify, MusicBrainz, MLC, ISNI, Discogs, YouTube\n\nQuery endpoints accept \"limit\" (default 50) and paginate. IDs are UUIDs \u2014 use a _query tool first when unsure.\n\nPeer connectors (email, drive, notes, calendar, DAW MCPs): when PICA shows missing data, check peer MCPs before asking the user. Cite via pica_enrichment_propose sources[].url with URI schemes \u2014 gmail:// gdrive:// notion:// file:// telegram:// calendar:// daw:// user:// web://. See docs/mcp-source-uri-conventions.md.";
19
+ /** Alias for the authenticated default — names the variant explicitly when paired with the unauthenticated one. */
20
+ export declare const SERVER_INSTRUCTIONS_AUTHENTICATED = "withPICA manages music catalog metadata \u2014 works, recordings, people, credits, agreements, rights. Tools are pica_<domain>_<verb>, 200+ of them, from npm as @withpica/mcp-server. If you see pica_execute, Execute Pica Action, or Search Platform Actions \u2014 that's @picahq/mcp (picaos.com), a different product with the same short name; don't route withPICA work there.\n\nStart here:\n- pica_dashboard_briefing \u2014 daily summary of what needs attention\n- pica_search_all \u2014 find any entity by name, ISWC, ISRC, or IPI\n- pica_works_query / pica_people_query \u2014 browse the catalog\n\nThe catalog is ALWAYS accessible via the tools above \u2014 zero setup, no integration required. If pica_integrations_status shows \"0 connected\" that refers to optional peer connectors (Google/Notion/Airtable/Telegram), NOT the catalog; call pica_works_query to check what's there.\n\nSpotify/YouTube URLs: call pica_import_streaming_link (Spotify/Deezer) or pica_import_youtube_link directly.\n\nAfter 3-5 catalog mutations or major state changes, call pica_dashboard_briefing and surface the delta to the user.\n\nKey patterns:\n- Read tools are safe to call freely (readOnlyHint=true)\n- _inspect tools take sections (e.g., pica_works_inspect sections: [\"health\", \"completeness\"])\n- Write tools confirm what changed; destructive tools (delete/merge) need two-step confirmation with a token\n- Errors include \"suggestion\" and \"next_tool\" for recovery\n- Enrichment: use pica_resolve_work / pica_resolve_person / pica_resolve_recording \u2014 fan out over Spotify, MusicBrainz, MLC, ISNI, Discogs, YouTube\n\nQuery endpoints accept \"limit\" (default 50) and paginate. IDs are UUIDs \u2014 use a _query tool first when unsure.\n\nPeer connectors (email, drive, notes, calendar, DAW MCPs): when PICA shows missing data, check peer MCPs before asking the user. Cite via pica_enrichment_propose sources[].url with URI schemes \u2014 gmail:// gdrive:// notion:// file:// telegram:// calendar:// daw:// user:// web://. See docs/mcp-source-uri-conventions.md.";
21
+ /** Minimal billing-slice shape consumed by the trial-ending clause. Structurally
22
+ * compatible with `OrgBillingSlice` from lib/services/subscription so callers
23
+ * can pass either. Local declaration keeps mcp-server's copy self-contained
24
+ * (the mcp-server npm artefact cannot import from @/lib paths). */
25
+ export interface TrialNudgeSlice {
26
+ billing_state: string;
27
+ trial_days_remaining: number | null;
28
+ }
29
+ /**
30
+ * Returns the authenticated handshake instructions, optionally appended with a
31
+ * state-conditional trial-ending nudge (ADR-210 Phase 3 / coordinator D3).
32
+ *
33
+ * Pass `null` when slice is unavailable (stdio binary at boot, or any path
34
+ * where the org context isn't resolvable); the function returns the base
35
+ * const unchanged in that case. Slice-less callers fail safe.
36
+ *
37
+ * Trial nudge fires only when `billing_state === 'trial'` AND
38
+ * `trial_days_remaining <= 3` AND remaining is not null. All other states
39
+ * (active / hibernated / paused / unclassified) and longer windows return
40
+ * the empty clause.
41
+ */
42
+ export declare function getAuthenticatedInstructions(slice: TrialNudgeSlice | null): string;
43
+ export declare function getTrialEndingClause(slice: TrialNudgeSlice | null): string;
44
+ /**
45
+ * Lobby instructions sent on handshake when the server has no connection key
46
+ * (stdio without PICA_API_KEY) or no Bearer token (HTTP /api/mcp anonymous mode).
47
+ *
48
+ * Lobby tool surface is exactly three tools:
49
+ * - pica_signup_start — for new users (mints a 15-min JWT-bound /onboard URL)
50
+ * - pica_sign_in — for existing users (sends a magic link)
51
+ * - pica_sign_out — for clearing stale credentials
52
+ *
53
+ * Authority: ADR-211 Phase 1 § Primitive C. Catalog-tool guidance omitted
54
+ * because none of the catalog tools are reachable in lobby mode.
55
+ *
56
+ * Kept byte-for-byte identical to lib/mcp/server-instructions.ts —
57
+ * `__tests__/mcp-server-instructions-unauth-parity.test.ts` enforces.
58
+ */
59
+ export declare const SERVER_INSTRUCTIONS_UNAUTHENTICATED = "You are connected to withPICA but no user is authenticated yet. Three tools are available:\n\n- pica_signup_start \u2014 for users new to withPICA. Ask for the user's email, then call this tool. It returns a single-use 15-minute signup link the user clicks to verify email, name their catalog, and start a 14-day free trial.\n- pica_sign_in \u2014 for users who already have a withPICA account. Sends a magic link to their inbox (device-code flow on stdio).\n- pica_sign_out \u2014 clears saved credentials.\n\nDo not promise catalog data, exports, or analyses until the user is signed in \u2014 none of those tools are reachable from this lobby. After signup or sign-in, the connection's tool surface refreshes automatically; ask the user what they want to do next.";
60
+ //# sourceMappingURL=server-instructions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-instructions.d.ts","sourceRoot":"","sources":["../src/server-instructions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,uhEAsB+R,CAAC;AAEhU,mHAAmH;AACnH,eAAO,MAAM,iCAAiC,uhEAAsB,CAAC;AAErE;;;oEAGoE;AACpE,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,eAAe,GAAG,IAAI,GAC5B,MAAM,CAER;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,CAO1E;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mCAAmC,mwBAM2M,CAAC"}
@@ -0,0 +1,93 @@
1
+ // Copyright (c) 2024-2026 Withpica Ltd. All rights reserved.
2
+ /**
3
+ * Server-level instructions sent to agents on MCP handshake.
4
+ * Keep under 2000 chars — this is context budget, not documentation.
5
+ *
6
+ * Two variants per ADR-211 Phase 1 Primitive C:
7
+ * - SERVER_INSTRUCTIONS / SERVER_INSTRUCTIONS_AUTHENTICATED: full surface
8
+ * guidance. Selected when the binary has a connection key (PICA_API_KEY).
9
+ * - SERVER_INSTRUCTIONS_UNAUTHENTICATED: short lobby guidance pointing the
10
+ * agent at pica_signup_start (or pica_sign_in for existing users).
11
+ * Selected when the binary boots without PICA_API_KEY. The lobby
12
+ * surface is the 3 tools {pica_signup_start, pica_sign_in,
13
+ * pica_sign_out} — none of the catalog tools are reachable, so we
14
+ * skip the catalog-tool guidance.
15
+ *
16
+ * Block playbook: "document the high level of your server"
17
+ * Lowin: "instructions are context — design them as context"
18
+ */
19
+ export const SERVER_INSTRUCTIONS = `withPICA manages music catalog metadata — works, recordings, people, credits, agreements, rights. Tools are pica_<domain>_<verb>, 200+ of them, from npm as @withpica/mcp-server. If you see pica_execute, Execute Pica Action, or Search Platform Actions — that's @picahq/mcp (picaos.com), a different product with the same short name; don't route withPICA work there.
20
+
21
+ Start here:
22
+ - pica_dashboard_briefing — daily summary of what needs attention
23
+ - pica_search_all — find any entity by name, ISWC, ISRC, or IPI
24
+ - pica_works_query / pica_people_query — browse the catalog
25
+
26
+ The catalog is ALWAYS accessible via the tools above — zero setup, no integration required. If pica_integrations_status shows "0 connected" that refers to optional peer connectors (Google/Notion/Airtable/Telegram), NOT the catalog; call pica_works_query to check what's there.
27
+
28
+ Spotify/YouTube URLs: call pica_import_streaming_link (Spotify/Deezer) or pica_import_youtube_link directly.
29
+
30
+ After 3-5 catalog mutations or major state changes, call pica_dashboard_briefing and surface the delta to the user.
31
+
32
+ Key patterns:
33
+ - Read tools are safe to call freely (readOnlyHint=true)
34
+ - _inspect tools take sections (e.g., pica_works_inspect sections: ["health", "completeness"])
35
+ - Write tools confirm what changed; destructive tools (delete/merge) need two-step confirmation with a token
36
+ - Errors include "suggestion" and "next_tool" for recovery
37
+ - Enrichment: use pica_resolve_work / pica_resolve_person / pica_resolve_recording — fan out over Spotify, MusicBrainz, MLC, ISNI, Discogs, YouTube
38
+
39
+ Query endpoints accept "limit" (default 50) and paginate. IDs are UUIDs — use a _query tool first when unsure.
40
+
41
+ Peer connectors (email, drive, notes, calendar, DAW MCPs): when PICA shows missing data, check peer MCPs before asking the user. Cite via pica_enrichment_propose sources[].url with URI schemes — gmail:// gdrive:// notion:// file:// telegram:// calendar:// daw:// user:// web://. See docs/mcp-source-uri-conventions.md.`;
42
+ /** Alias for the authenticated default — names the variant explicitly when paired with the unauthenticated one. */
43
+ export const SERVER_INSTRUCTIONS_AUTHENTICATED = SERVER_INSTRUCTIONS;
44
+ /**
45
+ * Returns the authenticated handshake instructions, optionally appended with a
46
+ * state-conditional trial-ending nudge (ADR-210 Phase 3 / coordinator D3).
47
+ *
48
+ * Pass `null` when slice is unavailable (stdio binary at boot, or any path
49
+ * where the org context isn't resolvable); the function returns the base
50
+ * const unchanged in that case. Slice-less callers fail safe.
51
+ *
52
+ * Trial nudge fires only when `billing_state === 'trial'` AND
53
+ * `trial_days_remaining <= 3` AND remaining is not null. All other states
54
+ * (active / hibernated / paused / unclassified) and longer windows return
55
+ * the empty clause.
56
+ */
57
+ export function getAuthenticatedInstructions(slice) {
58
+ return SERVER_INSTRUCTIONS_AUTHENTICATED + getTrialEndingClause(slice);
59
+ }
60
+ export function getTrialEndingClause(slice) {
61
+ if (!slice)
62
+ return "";
63
+ if (slice.billing_state !== "trial")
64
+ return "";
65
+ const days = slice.trial_days_remaining;
66
+ if (days === null || days > 3)
67
+ return "";
68
+ const dayWord = days === 1 ? "day" : "days";
69
+ return `\n\nThe user's trial ends in ${days} ${dayWord}. If they ask about pricing, plans, or upgrading, call pica_subscription_manage to mint a checkout URL.`;
70
+ }
71
+ /**
72
+ * Lobby instructions sent on handshake when the server has no connection key
73
+ * (stdio without PICA_API_KEY) or no Bearer token (HTTP /api/mcp anonymous mode).
74
+ *
75
+ * Lobby tool surface is exactly three tools:
76
+ * - pica_signup_start — for new users (mints a 15-min JWT-bound /onboard URL)
77
+ * - pica_sign_in — for existing users (sends a magic link)
78
+ * - pica_sign_out — for clearing stale credentials
79
+ *
80
+ * Authority: ADR-211 Phase 1 § Primitive C. Catalog-tool guidance omitted
81
+ * because none of the catalog tools are reachable in lobby mode.
82
+ *
83
+ * Kept byte-for-byte identical to lib/mcp/server-instructions.ts —
84
+ * `__tests__/mcp-server-instructions-unauth-parity.test.ts` enforces.
85
+ */
86
+ export const SERVER_INSTRUCTIONS_UNAUTHENTICATED = `You are connected to withPICA but no user is authenticated yet. Three tools are available:
87
+
88
+ - pica_signup_start — for users new to withPICA. Ask for the user's email, then call this tool. It returns a single-use 15-minute signup link the user clicks to verify email, name their catalog, and start a 14-day free trial.
89
+ - pica_sign_in — for users who already have a withPICA account. Sends a magic link to their inbox (device-code flow on stdio).
90
+ - pica_sign_out — clears saved credentials.
91
+
92
+ Do not promise catalog data, exports, or analyses until the user is signed in — none of those tools are reachable from this lobby. After signup or sign-in, the connection's tool surface refreshes automatically; ask the user what they want to do next.`;
93
+ //# sourceMappingURL=server-instructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-instructions.js","sourceRoot":"","sources":["../src/server-instructions.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;+TAsB4R,CAAC;AAEhU,mHAAmH;AACnH,MAAM,CAAC,MAAM,iCAAiC,GAAG,mBAAmB,CAAC;AAWrE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAA6B;IAE7B,OAAO,iCAAiC,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAA6B;IAChE,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,IAAI,KAAK,CAAC,aAAa,KAAK,OAAO;QAAE,OAAO,EAAE,CAAC;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,oBAAoB,CAAC;IACxC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,gCAAgC,IAAI,IAAI,OAAO,yGAAyG,CAAC;AAClK,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG;;;;;;2PAMwM,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { ServerConfig } from "./config.js";
2
+ export declare class PicaMcpServer {
3
+ private server;
4
+ private pica;
5
+ private toolRegistry;
6
+ private resourceRegistry;
7
+ private promptRegistry;
8
+ private config;
9
+ private httpServer?;
10
+ constructor(config: ServerConfig);
11
+ /**
12
+ * Reinitialize server with new credentials (called after successful auth)
13
+ */
14
+ reinitialize(apiKey: string): void;
15
+ /**
16
+ * Reset the server back to lobby mode (called after sign_out).
17
+ * Mirrors reinitialize() but in reverse: clears the PicaClient,
18
+ * sets lobbyMode=true, and rebuilds the tool/resource registries so
19
+ * the next tools/list call returns only [pica_sign_in, pica_sign_out].
20
+ *
21
+ * Without this the server would keep advertising the full authenticated
22
+ * tool surface after sign_out until the process is restarted, which
23
+ * lies about what's actually available — every privileged tool call
24
+ * would still fail at the API layer (no PicaClient), but the surface
25
+ * itself shouldn't pretend the catalog is reachable.
26
+ */
27
+ signOut(): void;
28
+ /**
29
+ * Set up MCP protocol handlers on the main server instance (for stdio)
30
+ */
31
+ private setupHandlers;
32
+ /**
33
+ * Start the MCP server.
34
+ *
35
+ * Transport is selected by environment:
36
+ * - MCP_TRANSPORT=http → HTTP server on MCP_PORT (default 3100)
37
+ * - Otherwise → stdio (default, for Claude Code / Cursor / VS Code)
38
+ */
39
+ start(): Promise<void>;
40
+ private startStdio;
41
+ private startHttp;
42
+ /**
43
+ * Register protocol handlers on a server instance.
44
+ * Used by both the main server (stdio) and per-request servers (HTTP).
45
+ */
46
+ private registerHandlers;
47
+ /**
48
+ * Stop the MCP server
49
+ */
50
+ stop(): Promise<void>;
51
+ }
52
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAe3C,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,IAAI,CAAoB;IAChC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAkC;gBAEzC,MAAM,EAAE,YAAY;IAqEhC;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAgDlC;;;;;;;;;;;OAWG;IACH,OAAO,IAAI,IAAI;IAqCf;;OAEG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;;;OAMG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAqBd,UAAU;YAKV,SAAS;IA6HvB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAkDxB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAS5B"}
package/dist/server.js ADDED
@@ -0,0 +1,334 @@
1
+ // Copyright (c) 2024-2026 Withpica Ltd. All rights reserved.
2
+ /**
3
+ * MCP Server for PICA Platform
4
+ * Enables AI assistants to interact with PICA via the Model Context Protocol
5
+ */
6
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
7
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
8
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
9
+ import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
10
+ import { createServer } from "node:http";
11
+ import { timingSafeEqual } from "node:crypto";
12
+ import { PicaClient } from "@withpica/mcp-sdk";
13
+ import { ToolRegistry } from "./tools/index.js";
14
+ import { ResourceRegistry } from "./resources/index.js";
15
+ import { PromptRegistry } from "./prompts/index.js";
16
+ import { logError } from "@withpica/mcp-utils";
17
+ import { makeStdioCallerContext, makeHttpAuditFn, McpAuditLogger, } from "@withpica/mcp-utils";
18
+ import { SERVER_INSTRUCTIONS_AUTHENTICATED, SERVER_INSTRUCTIONS_UNAUTHENTICATED, } from "./server-instructions.js";
19
+ export class PicaMcpServer {
20
+ server;
21
+ pica;
22
+ toolRegistry;
23
+ resourceRegistry;
24
+ promptRegistry;
25
+ config;
26
+ httpServer;
27
+ constructor(config) {
28
+ this.config = config;
29
+ // Initialize PICA SDK client (null in lobby mode)
30
+ if (config.picaApiKey) {
31
+ this.pica = new PicaClient({
32
+ apiKey: config.picaApiKey,
33
+ baseUrl: config.picaApiUrl,
34
+ debug: config.debug,
35
+ });
36
+ }
37
+ else {
38
+ this.pica = null;
39
+ }
40
+ // Initialize MCP server
41
+ // ADR-211 Phase 1 Primitive C: select the lobby variant of
42
+ // server-instructions when the binary boots without a connection key.
43
+ // The authenticated variant covers 200+ catalog tools; the lobby
44
+ // variant points at the 3 lobby tools (pica_signup_start +
45
+ // pica_sign_in + pica_sign_out) since none of the catalog surface
46
+ // is reachable yet.
47
+ const handshakeInstructions = config.lobbyMode
48
+ ? SERVER_INSTRUCTIONS_UNAUTHENTICATED
49
+ : SERVER_INSTRUCTIONS_AUTHENTICATED;
50
+ this.server = new Server({
51
+ name: config.serverName,
52
+ version: config.version,
53
+ }, {
54
+ capabilities: {
55
+ // listChanged: true on tools + resources tells the client we
56
+ // may emit `notifications/tools/list_changed` and
57
+ // `notifications/resources/list_changed` after sign-in or
58
+ // sign-out hot-swaps the registries. Without this declaration
59
+ // the client won't subscribe to those notifications, and the
60
+ // tool surface stays frozen at the lobby pair forever.
61
+ tools: { listChanged: true },
62
+ resources: { listChanged: true },
63
+ prompts: {},
64
+ },
65
+ instructions: handshakeInstructions,
66
+ });
67
+ // Initialize registries with stdio caller context (api key hash)
68
+ this.toolRegistry = new ToolRegistry(this.pica, config, (apiKey) => this.reinitialize(apiKey), makeStdioCallerContext(config.picaApiKey), () => this.signOut());
69
+ this.resourceRegistry = new ResourceRegistry(this.pica, config);
70
+ this.promptRegistry = new PromptRegistry();
71
+ // Wire audit logger — fire-and-forget POST to /api/mcp/audit
72
+ this.toolRegistry.setAuditLogger(new McpAuditLogger(makeHttpAuditFn({
73
+ baseUrl: config.picaApiUrl,
74
+ apiKey: config.picaApiKey,
75
+ })));
76
+ this.setupHandlers();
77
+ }
78
+ /**
79
+ * Reinitialize server with new credentials (called after successful auth)
80
+ */
81
+ reinitialize(apiKey) {
82
+ this.pica = new PicaClient({
83
+ apiKey,
84
+ baseUrl: this.config.picaApiUrl,
85
+ debug: this.config.debug,
86
+ });
87
+ this.config = { ...this.config, picaApiKey: apiKey, lobbyMode: false };
88
+ this.toolRegistry = new ToolRegistry(this.pica, this.config, (key) => this.reinitialize(key), makeStdioCallerContext(apiKey), () => this.signOut());
89
+ this.toolRegistry.setAuditLogger(new McpAuditLogger(makeHttpAuditFn({ baseUrl: this.config.picaApiUrl, apiKey })));
90
+ this.resourceRegistry = new ResourceRegistry(this.pica, this.config);
91
+ console.error("[MCP Server] Reinitialized with new credentials");
92
+ // Tell the client the tool + resource lists have changed so it
93
+ // re-fetches and discovers the full authenticated surface. Without
94
+ // these notifications the client keeps showing the lobby pair
95
+ // (sign_in/sign_out) even though sign-in succeeded — the in-memory
96
+ // registries on the server know about the 168 catalog tools but
97
+ // the client never asks for them again.
98
+ //
99
+ // Fire-and-forget: a failure to notify is a soft error (the user
100
+ // can manually trigger another tool call which will work since the
101
+ // server's internal state is correct), so we log and continue
102
+ // rather than throwing inside the callback path that just rebuilt
103
+ // the registries.
104
+ this.server.sendToolListChanged().catch((err) => {
105
+ console.error("[MCP Server] Failed to send tools/list_changed notification:", err);
106
+ });
107
+ this.server.sendResourceListChanged().catch((err) => {
108
+ console.error("[MCP Server] Failed to send resources/list_changed notification:", err);
109
+ });
110
+ }
111
+ /**
112
+ * Reset the server back to lobby mode (called after sign_out).
113
+ * Mirrors reinitialize() but in reverse: clears the PicaClient,
114
+ * sets lobbyMode=true, and rebuilds the tool/resource registries so
115
+ * the next tools/list call returns only [pica_sign_in, pica_sign_out].
116
+ *
117
+ * Without this the server would keep advertising the full authenticated
118
+ * tool surface after sign_out until the process is restarted, which
119
+ * lies about what's actually available — every privileged tool call
120
+ * would still fail at the API layer (no PicaClient), but the surface
121
+ * itself shouldn't pretend the catalog is reachable.
122
+ */
123
+ signOut() {
124
+ this.pica = null;
125
+ this.config = { ...this.config, picaApiKey: "", lobbyMode: true };
126
+ this.toolRegistry = new ToolRegistry(this.pica, this.config, (key) => this.reinitialize(key), makeStdioCallerContext(""), () => this.signOut());
127
+ this.toolRegistry.setAuditLogger(new McpAuditLogger(makeHttpAuditFn({ baseUrl: this.config.picaApiUrl, apiKey: "" })));
128
+ this.resourceRegistry = new ResourceRegistry(this.pica, this.config);
129
+ console.error("[MCP Server] Reset to lobby mode after sign_out");
130
+ // Same listChanged story as reinitialize() — without these the
131
+ // client keeps advertising the full authenticated surface to the
132
+ // model after sign-out, and any tool call would fail at the API
133
+ // layer with a confusing "no credentials" error instead of the
134
+ // model saying "you need to sign in first."
135
+ this.server.sendToolListChanged().catch((err) => {
136
+ console.error("[MCP Server] Failed to send tools/list_changed notification (signOut):", err);
137
+ });
138
+ this.server.sendResourceListChanged().catch((err) => {
139
+ console.error("[MCP Server] Failed to send resources/list_changed notification (signOut):", err);
140
+ });
141
+ }
142
+ /**
143
+ * Set up MCP protocol handlers on the main server instance (for stdio)
144
+ */
145
+ setupHandlers() {
146
+ this.registerHandlers(this.server);
147
+ }
148
+ /**
149
+ * Start the MCP server.
150
+ *
151
+ * Transport is selected by environment:
152
+ * - MCP_TRANSPORT=http → HTTP server on MCP_PORT (default 3100)
153
+ * - Otherwise → stdio (default, for Claude Code / Cursor / VS Code)
154
+ */
155
+ async start() {
156
+ const mode = process.env.MCP_TRANSPORT;
157
+ if (mode === "http") {
158
+ await this.startHttp();
159
+ }
160
+ else {
161
+ await this.startStdio();
162
+ }
163
+ console.error("[MCP Server] PICA MCP Server started");
164
+ console.error(`[MCP Server] Version: ${this.config.version}`);
165
+ console.error(`[MCP Server] Transport: ${mode === "http" ? "HTTP" : "stdio"}`);
166
+ console.error(`[MCP Server] Mode: ${this.config.lobbyMode ? "lobby (sign in to connect)" : "authenticated"}`);
167
+ console.error(`[MCP Server] API URL: ${this.config.picaApiUrl}`);
168
+ console.error("[MCP Server] Ready to accept connections");
169
+ }
170
+ async startStdio() {
171
+ const transport = new StdioServerTransport();
172
+ await this.server.connect(transport);
173
+ }
174
+ async startHttp() {
175
+ const port = parseInt(process.env.MCP_PORT || "3100", 10);
176
+ // Each HTTP request gets its own transport instance (stateless sessions)
177
+ const httpServer = createServer(async (req, res) => {
178
+ // CORS headers for browser-based clients
179
+ res.setHeader("Access-Control-Allow-Origin", "*");
180
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, DELETE");
181
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Mcp-Session-Id");
182
+ res.setHeader("Access-Control-Expose-Headers", "Mcp-Session-Id");
183
+ if (req.method === "OPTIONS") {
184
+ res.writeHead(204);
185
+ res.end();
186
+ return;
187
+ }
188
+ // Auth check — require MCP_HTTP_SECRET or PICA_API_KEY as Bearer token
189
+ const httpSecret = process.env.MCP_HTTP_SECRET || process.env.PICA_API_KEY;
190
+ if (httpSecret) {
191
+ const authHeader = req.headers["authorization"] ?? "";
192
+ const token = authHeader.startsWith("Bearer ")
193
+ ? authHeader.slice(7)
194
+ : "";
195
+ const tokenBuf = Buffer.from(token);
196
+ const secretBuf = Buffer.from(httpSecret);
197
+ const isValid = tokenBuf.length === secretBuf.length &&
198
+ timingSafeEqual(tokenBuf, secretBuf);
199
+ if (!isValid) {
200
+ res.writeHead(401, { "Content-Type": "application/json" });
201
+ res.end(JSON.stringify({ error: "Unauthorized" }));
202
+ return;
203
+ }
204
+ }
205
+ // Health check
206
+ if (req.method === "GET" && req.url === "/health") {
207
+ res.writeHead(200, { "Content-Type": "application/json" });
208
+ res.end(JSON.stringify({
209
+ status: "ok",
210
+ server: this.config.serverName,
211
+ version: this.config.version,
212
+ tools: this.toolRegistry.listTools().length,
213
+ }));
214
+ return;
215
+ }
216
+ // MCP endpoint — create per-request transport
217
+ if (req.url === "/mcp" || req.url === "/") {
218
+ try {
219
+ // Read body
220
+ const chunks = [];
221
+ for await (const chunk of req) {
222
+ chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
223
+ }
224
+ const body = Buffer.concat(chunks).toString("utf-8");
225
+ const parsedBody = body ? JSON.parse(body) : undefined;
226
+ const transport = new StreamableHTTPServerTransport({
227
+ sessionIdGenerator: undefined, // stateless
228
+ });
229
+ // Connect a fresh server instance for this request
230
+ const requestServer = new Server({
231
+ name: this.config.serverName,
232
+ version: this.config.version,
233
+ }, {
234
+ capabilities: {
235
+ tools: {},
236
+ resources: {},
237
+ prompts: {},
238
+ },
239
+ });
240
+ // Re-register handlers on the request-scoped server
241
+ this.registerHandlers(requestServer);
242
+ await requestServer.connect(transport);
243
+ await transport.handleRequest(req, res, parsedBody);
244
+ }
245
+ catch (err) {
246
+ if (this.config.debug) {
247
+ console.error("[MCP Server] HTTP request error:", err);
248
+ }
249
+ if (!res.headersSent) {
250
+ res.writeHead(500, { "Content-Type": "application/json" });
251
+ res.end(JSON.stringify({ error: "Internal server error" }));
252
+ }
253
+ }
254
+ return;
255
+ }
256
+ // 404
257
+ res.writeHead(404, { "Content-Type": "application/json" });
258
+ res.end(JSON.stringify({ error: "Not found" }));
259
+ });
260
+ this.httpServer = httpServer;
261
+ await new Promise((resolve) => {
262
+ httpServer.listen(port, () => {
263
+ console.error(`[MCP Server] HTTP listening on port ${port}`);
264
+ console.error(`[MCP Server] Endpoint: http://localhost:${port}/mcp`);
265
+ console.error(`[MCP Server] Health: http://localhost:${port}/health`);
266
+ resolve();
267
+ });
268
+ });
269
+ }
270
+ /**
271
+ * Register protocol handlers on a server instance.
272
+ * Used by both the main server (stdio) and per-request servers (HTTP).
273
+ */
274
+ registerHandlers(server) {
275
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
276
+ tools: this.toolRegistry.listTools(),
277
+ }));
278
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
279
+ const { name, arguments: args, _meta } = request.params;
280
+ const toolArgs = _meta ? { ...(args || {}), _meta } : args || {};
281
+ try {
282
+ // ADR-200 Phase 1: pass the per-request `Server` so executors can
283
+ // call `server.elicitInput()` / `server.getClientCapabilities()`
284
+ // when issuing an elicitation/create request. Each per-request
285
+ // HTTP server is a different instance; positional context
286
+ // avoids registry-level state that would race across calls.
287
+ return await this.toolRegistry.executeTool(name, toolArgs, { server });
288
+ }
289
+ catch (error) {
290
+ logError(`Tool execution: ${name}`, error);
291
+ throw error;
292
+ }
293
+ });
294
+ server.setRequestHandler(ListResourcesRequestSchema, async () => ({
295
+ resources: this.resourceRegistry.listResources(),
296
+ }));
297
+ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
298
+ const { uri } = request.params;
299
+ try {
300
+ return await this.resourceRegistry.readResource(uri);
301
+ }
302
+ catch (error) {
303
+ logError(`Resource read: ${uri}`, error);
304
+ throw error;
305
+ }
306
+ });
307
+ server.setRequestHandler(ListPromptsRequestSchema, async () => ({
308
+ prompts: this.promptRegistry.listPrompts(),
309
+ }));
310
+ server.setRequestHandler(GetPromptRequestSchema, async (request) => {
311
+ const { name, arguments: args } = request.params;
312
+ try {
313
+ return await this.promptRegistry.getPrompt(name, args);
314
+ }
315
+ catch (error) {
316
+ logError(`Prompt get: ${name}`, error);
317
+ throw error;
318
+ }
319
+ });
320
+ }
321
+ /**
322
+ * Stop the MCP server
323
+ */
324
+ async stop() {
325
+ if (this.httpServer) {
326
+ await new Promise((resolve) => {
327
+ this.httpServer.close(() => resolve());
328
+ });
329
+ }
330
+ await this.server.close();
331
+ console.error("[MCP Server] Server stopped");
332
+ }
333
+ }
334
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts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AM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACjE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;YACjD,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACzD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,QAAQ,CAAC,eAAe,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;gBACvC,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAClC,IAAI,CAAC,UAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC1B,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Access Simulate MCP Tool
3
+ *
4
+ * Read-only "who would see what?" simulator. Given an entity + an
5
+ * action + a hypothetical recipient, returns the field-level
6
+ * visibility matrix and the chain of rules that produced the answer.
7
+ *
8
+ * v1 implements share_link_preview for works with real logic; other
9
+ * actions and entity types return a structured `not_yet_supported`
10
+ * scaffold so agents can iterate against the stable shape.
11
+ */
12
+ import { PicaClient } from "@withpica/mcp-sdk";
13
+ import type { ToolDefinition, ToolExecutor } from "./index.js";
14
+ export declare class AccessSimulateTools {
15
+ private pica;
16
+ constructor(pica: PicaClient);
17
+ getTools(): Array<{
18
+ definition: ToolDefinition;
19
+ executor: ToolExecutor;
20
+ }>;
21
+ private simulate;
22
+ }
23
+ //# sourceMappingURL=access-simulate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access-simulate.d.ts","sourceRoot":"","sources":["../../src/tools/access-simulate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAc,MAAM,YAAY,CAAC;AAO3E,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,IAAI,CAAa;gBAEb,IAAI,EAAE,UAAU;IAI5B,QAAQ,IAAI,KAAK,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE,CAAC;YA+I3D,QAAQ;CAoCvB"}