palaryn 0.1.0 → 0.3.2

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 (344) hide show
  1. package/README.md +243 -588
  2. package/dist/sdk/typescript/src/client.js +2 -2
  3. package/dist/sdk/typescript/src/client.js.map +1 -1
  4. package/dist/src/anomaly/detector.d.ts +7 -4
  5. package/dist/src/anomaly/detector.d.ts.map +1 -1
  6. package/dist/src/anomaly/detector.js +22 -12
  7. package/dist/src/anomaly/detector.js.map +1 -1
  8. package/dist/src/audit/logger.d.ts +10 -0
  9. package/dist/src/audit/logger.d.ts.map +1 -1
  10. package/dist/src/audit/logger.js +52 -38
  11. package/dist/src/audit/logger.js.map +1 -1
  12. package/dist/src/auth/routes.d.ts.map +1 -1
  13. package/dist/src/auth/routes.js +35 -0
  14. package/dist/src/auth/routes.js.map +1 -1
  15. package/dist/src/budget/manager.d.ts +5 -0
  16. package/dist/src/budget/manager.d.ts.map +1 -1
  17. package/dist/src/budget/manager.js +32 -0
  18. package/dist/src/budget/manager.js.map +1 -1
  19. package/dist/src/budget/model-pricing.d.ts +20 -0
  20. package/dist/src/budget/model-pricing.d.ts.map +1 -0
  21. package/dist/src/budget/model-pricing.js +107 -0
  22. package/dist/src/budget/model-pricing.js.map +1 -0
  23. package/dist/src/budget/usage-extractor.d.ts +3 -1
  24. package/dist/src/budget/usage-extractor.d.ts.map +1 -1
  25. package/dist/src/budget/usage-extractor.js +47 -3
  26. package/dist/src/budget/usage-extractor.js.map +1 -1
  27. package/dist/src/config/defaults.d.ts.map +1 -1
  28. package/dist/src/config/defaults.js +65 -13
  29. package/dist/src/config/defaults.js.map +1 -1
  30. package/dist/src/dlp/tool-patterns.d.ts +7 -0
  31. package/dist/src/dlp/tool-patterns.d.ts.map +1 -0
  32. package/dist/src/dlp/tool-patterns.js +34 -0
  33. package/dist/src/dlp/tool-patterns.js.map +1 -0
  34. package/dist/src/executor/filesystem-executor.d.ts +28 -0
  35. package/dist/src/executor/filesystem-executor.d.ts.map +1 -0
  36. package/dist/src/executor/filesystem-executor.js +192 -0
  37. package/dist/src/executor/filesystem-executor.js.map +1 -0
  38. package/dist/src/executor/http-executor.d.ts.map +1 -1
  39. package/dist/src/executor/http-executor.js +22 -2
  40. package/dist/src/executor/http-executor.js.map +1 -1
  41. package/dist/src/executor/index.d.ts +4 -0
  42. package/dist/src/executor/index.d.ts.map +1 -1
  43. package/dist/src/executor/index.js +9 -1
  44. package/dist/src/executor/index.js.map +1 -1
  45. package/dist/src/executor/shell-executor.d.ts +22 -0
  46. package/dist/src/executor/shell-executor.d.ts.map +1 -0
  47. package/dist/src/executor/shell-executor.js +119 -0
  48. package/dist/src/executor/shell-executor.js.map +1 -0
  49. package/dist/src/executor/sql-executor.d.ts +29 -0
  50. package/dist/src/executor/sql-executor.d.ts.map +1 -0
  51. package/dist/src/executor/sql-executor.js +114 -0
  52. package/dist/src/executor/sql-executor.js.map +1 -0
  53. package/dist/src/executor/websocket-executor.d.ts +26 -0
  54. package/dist/src/executor/websocket-executor.d.ts.map +1 -0
  55. package/dist/src/executor/websocket-executor.js +205 -0
  56. package/dist/src/executor/websocket-executor.js.map +1 -0
  57. package/dist/src/interceptor/index.d.ts +2 -0
  58. package/dist/src/interceptor/index.d.ts.map +1 -0
  59. package/dist/src/interceptor/index.js +6 -0
  60. package/dist/src/interceptor/index.js.map +1 -0
  61. package/dist/src/interceptor/provider-interceptor.d.ts +36 -0
  62. package/dist/src/interceptor/provider-interceptor.d.ts.map +1 -0
  63. package/dist/src/interceptor/provider-interceptor.js +302 -0
  64. package/dist/src/interceptor/provider-interceptor.js.map +1 -0
  65. package/dist/src/mcp/auth-verifier.d.ts.map +1 -1
  66. package/dist/src/mcp/auth-verifier.js +3 -2
  67. package/dist/src/mcp/auth-verifier.js.map +1 -1
  68. package/dist/src/mcp/bridge.d.ts +14 -10
  69. package/dist/src/mcp/bridge.d.ts.map +1 -1
  70. package/dist/src/mcp/bridge.js +51 -227
  71. package/dist/src/mcp/bridge.js.map +1 -1
  72. package/dist/src/mcp/http-transport.d.ts +2 -0
  73. package/dist/src/mcp/http-transport.d.ts.map +1 -1
  74. package/dist/src/mcp/http-transport.js +117 -66
  75. package/dist/src/mcp/http-transport.js.map +1 -1
  76. package/dist/src/mcp/internal-auth.d.ts +13 -0
  77. package/dist/src/mcp/internal-auth.d.ts.map +1 -0
  78. package/dist/src/mcp/internal-auth.js +12 -0
  79. package/dist/src/mcp/internal-auth.js.map +1 -0
  80. package/dist/src/mcp/tool-definitions.d.ts +41 -0
  81. package/dist/src/mcp/tool-definitions.d.ts.map +1 -0
  82. package/dist/src/mcp/tool-definitions.js +491 -0
  83. package/dist/src/mcp/tool-definitions.js.map +1 -0
  84. package/dist/src/middleware/auth.js.map +1 -1
  85. package/dist/src/middleware/session.js.map +1 -1
  86. package/dist/src/middleware/validate.d.ts +8 -0
  87. package/dist/src/middleware/validate.d.ts.map +1 -1
  88. package/dist/src/middleware/validate.js +45 -0
  89. package/dist/src/middleware/validate.js.map +1 -1
  90. package/dist/src/policy/engine.d.ts +4 -0
  91. package/dist/src/policy/engine.d.ts.map +1 -1
  92. package/dist/src/policy/engine.js +117 -0
  93. package/dist/src/policy/engine.js.map +1 -1
  94. package/dist/src/saas/routes.d.ts.map +1 -1
  95. package/dist/src/saas/routes.js +355 -22
  96. package/dist/src/saas/routes.js.map +1 -1
  97. package/dist/src/server/app.d.ts.map +1 -1
  98. package/dist/src/server/app.js +24 -3
  99. package/dist/src/server/app.js.map +1 -1
  100. package/dist/src/server/gateway.d.ts.map +1 -1
  101. package/dist/src/server/gateway.js +17 -0
  102. package/dist/src/server/gateway.js.map +1 -1
  103. package/dist/src/server/index.d.ts.map +1 -1
  104. package/dist/src/server/index.js +18 -0
  105. package/dist/src/server/index.js.map +1 -1
  106. package/dist/src/storage/interfaces.d.ts +14 -3
  107. package/dist/src/storage/interfaces.d.ts.map +1 -1
  108. package/dist/src/storage/memory.d.ts +2 -0
  109. package/dist/src/storage/memory.d.ts.map +1 -1
  110. package/dist/src/storage/memory.js +6 -0
  111. package/dist/src/storage/memory.js.map +1 -1
  112. package/dist/src/storage/postgres.d.ts +5 -0
  113. package/dist/src/storage/postgres.d.ts.map +1 -1
  114. package/dist/src/storage/postgres.js +16 -0
  115. package/dist/src/storage/postgres.js.map +1 -1
  116. package/dist/src/storage/redis.d.ts +10 -0
  117. package/dist/src/storage/redis.d.ts.map +1 -1
  118. package/dist/src/storage/redis.js +65 -0
  119. package/dist/src/storage/redis.js.map +1 -1
  120. package/dist/src/types/budget.d.ts +4 -0
  121. package/dist/src/types/budget.d.ts.map +1 -1
  122. package/dist/src/types/config.d.ts +58 -0
  123. package/dist/src/types/config.d.ts.map +1 -1
  124. package/dist/src/types/events.d.ts +1 -0
  125. package/dist/src/types/events.d.ts.map +1 -1
  126. package/dist/src/types/policy.d.ts +11 -1
  127. package/dist/src/types/policy.d.ts.map +1 -1
  128. package/dist/src/types/tool-result.d.ts +11 -0
  129. package/dist/src/types/tool-result.d.ts.map +1 -1
  130. package/dist/tests/unit/app-routes.test.d.ts +2 -0
  131. package/dist/tests/unit/app-routes.test.d.ts.map +1 -0
  132. package/dist/tests/unit/app-routes.test.js +715 -0
  133. package/dist/tests/unit/app-routes.test.js.map +1 -0
  134. package/dist/tests/unit/audit-logger.test.js +105 -0
  135. package/dist/tests/unit/audit-logger.test.js.map +1 -1
  136. package/dist/tests/unit/auth-providers.test.d.ts +2 -0
  137. package/dist/tests/unit/auth-providers.test.d.ts.map +1 -0
  138. package/dist/tests/unit/auth-providers.test.js +279 -0
  139. package/dist/tests/unit/auth-providers.test.js.map +1 -0
  140. package/dist/tests/unit/auth-routes-extended.test.d.ts +2 -0
  141. package/dist/tests/unit/auth-routes-extended.test.d.ts.map +1 -0
  142. package/dist/tests/unit/auth-routes-extended.test.js +993 -0
  143. package/dist/tests/unit/auth-routes-extended.test.js.map +1 -0
  144. package/dist/tests/unit/auth-verifier.test.d.ts +2 -0
  145. package/dist/tests/unit/auth-verifier.test.d.ts.map +1 -0
  146. package/dist/tests/unit/auth-verifier.test.js +505 -0
  147. package/dist/tests/unit/auth-verifier.test.js.map +1 -0
  148. package/dist/tests/unit/billing-routes.test.d.ts +2 -0
  149. package/dist/tests/unit/billing-routes.test.d.ts.map +1 -0
  150. package/dist/tests/unit/billing-routes.test.js +432 -0
  151. package/dist/tests/unit/billing-routes.test.js.map +1 -0
  152. package/dist/tests/unit/config-defaults.test.d.ts +2 -0
  153. package/dist/tests/unit/config-defaults.test.d.ts.map +1 -0
  154. package/dist/tests/unit/config-defaults.test.js +119 -0
  155. package/dist/tests/unit/config-defaults.test.js.map +1 -0
  156. package/dist/tests/unit/defaults.test.js +0 -10
  157. package/dist/tests/unit/defaults.test.js.map +1 -1
  158. package/dist/tests/unit/filesystem-executor.test.d.ts +2 -0
  159. package/dist/tests/unit/filesystem-executor.test.d.ts.map +1 -0
  160. package/dist/tests/unit/filesystem-executor.test.js +280 -0
  161. package/dist/tests/unit/filesystem-executor.test.js.map +1 -0
  162. package/dist/tests/unit/gateway-branches.test.d.ts +2 -0
  163. package/dist/tests/unit/gateway-branches.test.d.ts.map +1 -0
  164. package/dist/tests/unit/gateway-branches.test.js +1039 -0
  165. package/dist/tests/unit/gateway-branches.test.js.map +1 -0
  166. package/dist/tests/unit/http-executor-branches.test.d.ts +2 -0
  167. package/dist/tests/unit/http-executor-branches.test.d.ts.map +1 -0
  168. package/dist/tests/unit/http-executor-branches.test.js +495 -0
  169. package/dist/tests/unit/http-executor-branches.test.js.map +1 -0
  170. package/dist/tests/unit/logger.test.d.ts +2 -0
  171. package/dist/tests/unit/logger.test.d.ts.map +1 -0
  172. package/dist/tests/unit/logger.test.js +97 -0
  173. package/dist/tests/unit/logger.test.js.map +1 -0
  174. package/dist/tests/unit/mcp-internal-auth.test.d.ts +2 -0
  175. package/dist/tests/unit/mcp-internal-auth.test.d.ts.map +1 -0
  176. package/dist/tests/unit/mcp-internal-auth.test.js +445 -0
  177. package/dist/tests/unit/mcp-internal-auth.test.js.map +1 -0
  178. package/dist/tests/unit/metrics.test.js +102 -0
  179. package/dist/tests/unit/metrics.test.js.map +1 -1
  180. package/dist/tests/unit/model-pricing.test.d.ts +2 -0
  181. package/dist/tests/unit/model-pricing.test.d.ts.map +1 -0
  182. package/dist/tests/unit/model-pricing.test.js +87 -0
  183. package/dist/tests/unit/model-pricing.test.js.map +1 -0
  184. package/dist/tests/unit/oauth-stores.test.d.ts +2 -0
  185. package/dist/tests/unit/oauth-stores.test.d.ts.map +1 -0
  186. package/dist/tests/unit/oauth-stores.test.js +260 -0
  187. package/dist/tests/unit/oauth-stores.test.js.map +1 -0
  188. package/dist/tests/unit/policy-engine.test.js +466 -0
  189. package/dist/tests/unit/policy-engine.test.js.map +1 -1
  190. package/dist/tests/unit/provider-interceptor.test.d.ts +2 -0
  191. package/dist/tests/unit/provider-interceptor.test.d.ts.map +1 -0
  192. package/dist/tests/unit/provider-interceptor.test.js +472 -0
  193. package/dist/tests/unit/provider-interceptor.test.js.map +1 -0
  194. package/dist/tests/unit/saas-routes-branches.test.d.ts +2 -0
  195. package/dist/tests/unit/saas-routes-branches.test.d.ts.map +1 -0
  196. package/dist/tests/unit/saas-routes-branches.test.js +2165 -0
  197. package/dist/tests/unit/saas-routes-branches.test.js.map +1 -0
  198. package/dist/tests/unit/saas-routes-crud.test.d.ts +2 -0
  199. package/dist/tests/unit/saas-routes-crud.test.d.ts.map +1 -0
  200. package/dist/tests/unit/saas-routes-crud.test.js +332 -0
  201. package/dist/tests/unit/saas-routes-crud.test.js.map +1 -0
  202. package/dist/tests/unit/saas-routes-data.test.d.ts +2 -0
  203. package/dist/tests/unit/saas-routes-data.test.d.ts.map +1 -0
  204. package/dist/tests/unit/saas-routes-data.test.js +405 -0
  205. package/dist/tests/unit/saas-routes-data.test.js.map +1 -0
  206. package/dist/tests/unit/saas-routes.test.js +3 -3
  207. package/dist/tests/unit/saas-routes.test.js.map +1 -1
  208. package/dist/tests/unit/shell-executor.test.d.ts +2 -0
  209. package/dist/tests/unit/shell-executor.test.d.ts.map +1 -0
  210. package/dist/tests/unit/shell-executor.test.js +145 -0
  211. package/dist/tests/unit/shell-executor.test.js.map +1 -0
  212. package/dist/tests/unit/sql-executor.test.d.ts +2 -0
  213. package/dist/tests/unit/sql-executor.test.d.ts.map +1 -0
  214. package/dist/tests/unit/sql-executor.test.js +177 -0
  215. package/dist/tests/unit/sql-executor.test.js.map +1 -0
  216. package/dist/tests/unit/stream-proxy.test.d.ts +2 -0
  217. package/dist/tests/unit/stream-proxy.test.d.ts.map +1 -0
  218. package/dist/tests/unit/stream-proxy.test.js +147 -0
  219. package/dist/tests/unit/stream-proxy.test.js.map +1 -0
  220. package/dist/tests/unit/tool-definitions.test.d.ts +2 -0
  221. package/dist/tests/unit/tool-definitions.test.d.ts.map +1 -0
  222. package/dist/tests/unit/tool-definitions.test.js +184 -0
  223. package/dist/tests/unit/tool-definitions.test.js.map +1 -0
  224. package/dist/tests/unit/usage-extractor.test.js +140 -0
  225. package/dist/tests/unit/usage-extractor.test.js.map +1 -1
  226. package/dist/tests/unit/webhook-handler.test.d.ts +2 -0
  227. package/dist/tests/unit/webhook-handler.test.d.ts.map +1 -0
  228. package/dist/tests/unit/webhook-handler.test.js +453 -0
  229. package/dist/tests/unit/webhook-handler.test.js.map +1 -0
  230. package/dist/tests/unit/webhook-routes.test.d.ts +2 -0
  231. package/dist/tests/unit/webhook-routes.test.d.ts.map +1 -0
  232. package/dist/tests/unit/webhook-routes.test.js +69 -0
  233. package/dist/tests/unit/webhook-routes.test.js.map +1 -0
  234. package/dist/tests/unit/websocket-executor.test.d.ts +2 -0
  235. package/dist/tests/unit/websocket-executor.test.d.ts.map +1 -0
  236. package/dist/tests/unit/websocket-executor.test.js +121 -0
  237. package/dist/tests/unit/websocket-executor.test.js.map +1 -0
  238. package/package.json +8 -2
  239. package/policy-packs/demo_fail.yaml +41 -0
  240. package/policy-packs/full_tools.yaml +136 -0
  241. package/src/admin/index.ts +1 -0
  242. package/src/admin/routes.ts +509 -0
  243. package/src/admin/templates.ts +572 -0
  244. package/src/anomaly/detector.ts +730 -0
  245. package/src/anomaly/index.ts +1 -0
  246. package/src/approval/manager.ts +569 -0
  247. package/src/approval/webhook.ts +133 -0
  248. package/src/audit/logger.ts +490 -0
  249. package/src/auth/index.ts +5 -0
  250. package/src/auth/password.ts +21 -0
  251. package/src/auth/pkce.ts +22 -0
  252. package/src/auth/providers.ts +208 -0
  253. package/src/auth/routes.ts +561 -0
  254. package/src/auth/session.ts +84 -0
  255. package/src/billing/index.ts +6 -0
  256. package/src/billing/plan-enforcer.ts +135 -0
  257. package/src/billing/routes.ts +229 -0
  258. package/src/billing/stripe-client.ts +58 -0
  259. package/src/billing/webhook-handler.ts +182 -0
  260. package/src/billing/webhook-routes.ts +28 -0
  261. package/src/budget/manager.ts +679 -0
  262. package/src/budget/model-pricing.ts +119 -0
  263. package/src/budget/usage-extractor.ts +214 -0
  264. package/src/cli.ts +91 -0
  265. package/src/config/defaults.ts +261 -0
  266. package/src/config/validate.ts +88 -0
  267. package/src/dlp/composite-scanner.ts +213 -0
  268. package/src/dlp/index.ts +9 -0
  269. package/src/dlp/interfaces.ts +34 -0
  270. package/src/dlp/patterns.ts +30 -0
  271. package/src/dlp/prompt-injection-backend.ts +181 -0
  272. package/src/dlp/prompt-injection-patterns.ts +302 -0
  273. package/src/dlp/regex-backend.ts +181 -0
  274. package/src/dlp/scanner.ts +502 -0
  275. package/src/dlp/text-normalizer.ts +225 -0
  276. package/src/dlp/tool-patterns.ts +35 -0
  277. package/src/dlp/trufflehog-backend.ts +190 -0
  278. package/src/executor/filesystem-executor.ts +196 -0
  279. package/src/executor/http-executor.ts +349 -0
  280. package/src/executor/index.ts +9 -0
  281. package/src/executor/interfaces.ts +11 -0
  282. package/src/executor/noop-executor.ts +23 -0
  283. package/src/executor/registry.ts +64 -0
  284. package/src/executor/shell-executor.ts +148 -0
  285. package/src/executor/slack-executor.ts +176 -0
  286. package/src/executor/sql-executor.ts +146 -0
  287. package/src/executor/websocket-executor.ts +211 -0
  288. package/src/index.ts +24 -0
  289. package/src/interceptor/index.ts +1 -0
  290. package/src/interceptor/provider-interceptor.ts +315 -0
  291. package/src/mcp/auth-verifier.ts +152 -0
  292. package/src/mcp/bridge.ts +703 -0
  293. package/src/mcp/http-transport.ts +698 -0
  294. package/src/mcp/index.ts +9 -0
  295. package/src/mcp/internal-auth.ts +14 -0
  296. package/src/mcp/oauth-pages.ts +139 -0
  297. package/src/mcp/oauth-postgres-stores.ts +278 -0
  298. package/src/mcp/oauth-provider.ts +536 -0
  299. package/src/mcp/oauth-stores.ts +202 -0
  300. package/src/mcp/server.ts +55 -0
  301. package/src/mcp/tool-definitions.ts +562 -0
  302. package/src/metrics/collector.ts +357 -0
  303. package/src/metrics/index.ts +1 -0
  304. package/src/middleware/auth.ts +814 -0
  305. package/src/middleware/session.ts +85 -0
  306. package/src/middleware/validate.ts +130 -0
  307. package/src/policy/engine.ts +815 -0
  308. package/src/policy/index.ts +2 -0
  309. package/src/policy/opa-engine.ts +829 -0
  310. package/src/proxy/forward-proxy.ts +649 -0
  311. package/src/proxy/index.ts +1 -0
  312. package/src/ratelimit/limiter.ts +196 -0
  313. package/src/replay/engine.ts +142 -0
  314. package/src/replay/index.ts +1 -0
  315. package/src/saas/index.ts +1 -0
  316. package/src/saas/routes.ts +2178 -0
  317. package/src/server/app.ts +985 -0
  318. package/src/server/errors.ts +49 -0
  319. package/src/server/gateway.ts +1130 -0
  320. package/src/server/index.ts +307 -0
  321. package/src/server/logger.ts +255 -0
  322. package/src/server/stream-proxy.ts +202 -0
  323. package/src/storage/file-persistence.ts +315 -0
  324. package/src/storage/index.ts +4 -0
  325. package/src/storage/interfaces.ts +287 -0
  326. package/src/storage/memory.ts +686 -0
  327. package/src/storage/postgres.ts +1831 -0
  328. package/src/storage/redis.ts +835 -0
  329. package/src/tracing/index.ts +1 -0
  330. package/src/tracing/provider.ts +100 -0
  331. package/src/trust/calculator.ts +141 -0
  332. package/src/trust/index.ts +7 -0
  333. package/src/types/budget.ts +36 -0
  334. package/src/types/config.ts +278 -0
  335. package/src/types/events.ts +41 -0
  336. package/src/types/express.d.ts +14 -0
  337. package/src/types/index.ts +7 -0
  338. package/src/types/policy.ts +83 -0
  339. package/src/types/stripe-config.ts +11 -0
  340. package/src/types/subscription.ts +59 -0
  341. package/src/types/tool-call.ts +47 -0
  342. package/src/types/tool-result.ts +82 -0
  343. package/src/types/user.ts +125 -0
  344. package/tsconfig.json +24 -0
package/README.md CHANGED
@@ -2,325 +2,167 @@
2
2
 
3
3
  **A model-agnostic infrastructure layer that gives AI agents safe, auditable, and cost-controlled access to the outside world.**
4
4
 
5
- ---
6
-
7
- ## Overview
8
-
9
- As AI agents increasingly interact with external services -- sending HTTP requests, posting to Slack, committing to Git, querying databases -- the central challenge shifts from model intelligence to **execution control**. Without guardrails, agents can leak secrets, overspend budgets, trigger unintended writes, and leave no trace of what happened. Enterprise procurement teams will not approve agent deployments that lack policy enforcement, cost controls, and auditable logs.
10
-
11
- Palaryn solves this by sitting as a single choke point between AI agents and the external world. Every tool call -- whether it targets a SaaS API, a database, a Git provider, Slack, or a headless browser -- is intercepted, evaluated against security policies, checked for sensitive data, metered against budgets, and logged immutably. The gateway is completely model-agnostic: it works with Claude, OpenAI, LangGraph, n8n, or any custom orchestrator. Integration requires nothing more than swapping an endpoint or embedding the SDK.
12
-
13
- The product is built around three pillars: **Security and DLP** to prevent data exfiltration and enforce least-privilege access; **Cost and Budget Controls** to stop runaway spending from agent loops and retries; and **Audit and Observability** to provide full traceability, replay capability, and compliance-ready export to SIEM and GRC platforms.
5
+ Palaryn sits as a single choke point between AI agents and external services. Every tool call is intercepted, evaluated against security policies, checked for sensitive data, metered against budgets, and logged immutably. Works with Claude, OpenAI, LangGraph, n8n, or any custom orchestrator.
14
6
 
15
7
  ---
16
8
 
17
- ## Quick Start
18
-
19
- ### Prerequisites
20
-
21
- - Node.js 20+
22
- - npm
23
-
24
- ### Install, Build, and Run
9
+ ## Install
25
10
 
26
11
  ```bash
27
- # Clone the repository
28
- git clone <repo-url> && cd palaryn
29
-
30
- # Install dependencies
31
- npm install
12
+ curl -fsSL https://app.palaryn.com/install.sh | sh
13
+ ```
32
14
 
33
- # Build the TypeScript project
34
- npm run build
15
+ Or install directly via npm:
35
16
 
36
- # Start the gateway
37
- npm start
17
+ ```bash
18
+ npm install -g palaryn
38
19
  ```
39
20
 
40
- The gateway starts on **port 3000** by default. Verify it is running:
21
+ Verify:
41
22
 
42
23
  ```bash
43
- curl http://localhost:3000/health
24
+ palaryn --version
25
+ palaryn --help
44
26
  ```
45
27
 
46
- ### Execute Your First Tool Call
28
+ ---
29
+
30
+ ## Quick Start
47
31
 
48
- Send a tool call through the gateway using the default API key (`dev-key-001`):
32
+ The fastest way to try Palaryn is a single curl call against the hosted gateway:
49
33
 
50
34
  ```bash
51
- curl -X POST http://localhost:3000/v1/tool/execute \
35
+ curl -X POST https://app.palaryn.com/v1/tool/execute \
52
36
  -H "Content-Type: application/json" \
53
- -H "X-API-Key: dev-key-001" \
37
+ -H "X-API-Key: YOUR_API_KEY" \
54
38
  -d '{
55
- "tool_call_id": "tc-001",
56
- "task_id": "task-001",
57
- "actor": { "type": "agent", "id": "agent-1" },
58
- "source": { "platform": "custom" },
59
- "tool": { "name": "http.request", "capability": "read" },
60
- "args": { "method": "GET", "url": "https://httpbin.org/get" }
39
+ "tool": "http.get",
40
+ "input": { "url": "https://api.github.com/repos/octocat/Hello-World" },
41
+ "taskId": "demo-task-1",
42
+ "actorId": "my-agent"
61
43
  }'
62
44
  ```
63
45
 
64
- The response includes the policy decision, DLP scan results, budget report, and the tool output -- all in a single `ToolResult` envelope.
46
+ The response includes the policy decision, DLP scan results, budget report, and the tool output:
65
47
 
66
- ---
67
-
68
- ## Project Structure
69
-
70
- ```
71
- /
72
- ├── src/
73
- │ ├── types/ # Canonical schemas (ToolCall, ToolResult, Policy, Events, Budget, Config)
74
- │ ├── policy/ # Policy engine (YAML DSL evaluation)
75
- │ ├── dlp/ # DLP scanner (secrets + PII detection, redaction)
76
- │ ├── budget/ # Budget manager (per-task/user/org budgets, hard stops)
77
- │ ├── audit/ # Audit logger (immutable event log, trace reconstruction)
78
- │ ├── executor/ # HTTP executor (retries, backoff, caching)
79
- │ ├── approval/ # Approval manager (JWT tokens, time-bound approvals)
80
- │ ├── server/ # Express gateway server + request orchestration
81
- │ ├── middleware/ # Auth and validation middleware
82
- │ ├── config/ # Default configuration + startup validation
83
- │ └── index.ts # Package exports
84
- ├── sdk/typescript/ # TypeScript SDK client
85
- │ └── src/
86
- │ ├── client.ts # PalarynClient class with full API coverage
87
- │ └── index.ts # SDK exports
88
- ├── policy-packs/ # Pre-built YAML policy configurations
89
- │ ├── default.yaml # Default safe (reads allowed, writes need approval)
90
- │ ├── dev_fast.yaml # Development (permissive reads + writes)
91
- │ └── prod_strict.yaml # Production strict (minimal permissions)
92
- ├── tests/
93
- │ ├── unit/ # 1551 unit tests across 37 suites
94
- │ └── integration/ # 123 integration tests (65 run + 58 auto-skip without Redis/Postgres)
95
- ├── examples/ # Usage examples
96
- ├── docs/ # Product documentation (13 markdown files)
97
- ├── Dockerfile # Multi-stage production Docker build
98
- ├── docker-compose.yaml # Docker Compose with dev and prod services
99
- ├── tsconfig.json # TypeScript configuration
100
- └── package.json
48
+ ```json
49
+ {
50
+ "status": "ok",
51
+ "policy": { "decision": "allow", "rule_id": "Allow read operations" },
52
+ "dlp": { "detected": ["email"], "severity": "medium" },
53
+ "budget": { "estimated_cost_usd": 0.001, "remaining_cost_usd_task": 1.999 },
54
+ "output": { "http_status": 200, "body": { "full_name": "octocat/Hello-World", ... } },
55
+ "timing": { "duration_ms": 142 }
56
+ }
101
57
  ```
102
58
 
103
59
  ---
104
60
 
105
- ## Development
106
-
107
- ### Commands
61
+ ## Integration Methods
108
62
 
109
- | Command | Description |
110
- |---|---|
111
- | `npm install` | Install dependencies |
112
- | `npm run build` | Compile TypeScript to `dist/` |
113
- | `npm start` | Start the gateway in production mode (requires build) |
114
- | `npm run dev` | Start the gateway in development mode (ts-node, no build needed) |
115
- | `npm test` | Run all 1616 tests (40 suites) |
116
- | `npm run test:unit` | Run 1551 unit tests (37 suites) |
117
- | `npm run test:integration` | Run 123 integration tests (65 + 58 auto-skip without services) |
118
- | `npm run lint` | Run ESLint on `src/` and `tests/` |
119
- | `npm run clean` | Remove `dist/` build output |
63
+ Palaryn has a single pipeline (auth → rate limit → policy → DLP → budget → execute → audit) with multiple entry points:
120
64
 
121
- ### Environment Variables
65
+ | Method | Protocol | Code Change | Best For |
66
+ |---|---|---|---|
67
+ | **MCP Remote (OAuth)** | Streamable HTTP | Zero — one command | Claude Code, Cursor, any MCP client |
68
+ | **MCP Local (stdio)** | JSON-RPC stdio | Zero — config only | Local development, offline |
69
+ | **REST API** | HTTP POST | Minimal — send JSON | Any HTTP-capable system |
70
+ | **SDK** (TypeScript / Python) | HTTP (wrapped) | Import + wrapper | Custom agents, orchestrators |
71
+ | **HTTP Proxy** (`:3128`) | `HTTP_PROXY` env var | Zero | Containers, K8s, sandbox |
122
72
 
123
- | Variable | Default | Description |
124
- |---|---|---|
125
- | `PORT` | `3000` | HTTP server port |
126
- | `HOST` | `0.0.0.0` | HTTP server bind address |
127
- | `NODE_ENV` | `development` | Environment (development / production) |
128
- | `AUTH_ENABLED` | `true` | Enable/disable API key authentication |
129
- | `POLICY_PACK_PATH` | `./policy-packs/default.yaml` | Path to the active policy pack |
130
- | `AUDIT_LOG_DIR` | `./logs` | Directory for immutable audit logs |
131
- | `JWT_SECRET` | -- | Secret for signing approval JWT tokens |
132
- | `APPROVAL_SECRET` | -- | Secret for signing approval workflow tokens |
133
- | `REDIS_URL` | -- | Redis connection URL (e.g. `redis://redis:6379`) |
134
- | `DATABASE_URL` | -- | PostgreSQL connection URL |
73
+ ### MCP Remote (OAuth) Recommended
135
74
 
136
- ### Running in Development
75
+ One command, OAuth login in the browser, done:
137
76
 
138
77
  ```bash
139
- # Start with hot-reload via ts-node
140
- npm run dev
78
+ # Claude Code
79
+ claude mcp add --transport http palaryn https://app.palaryn.com/mcp
141
80
 
142
- # Run tests in watch mode
143
- npx jest --watch
81
+ # Cursor add to .cursor/mcp.json
82
+ { "mcpServers": { "palaryn": { "url": "https://app.palaryn.com/mcp" } } }
144
83
  ```
145
84
 
146
- ---
85
+ Authentication is fully automatic via OAuth 2.0 (dynamic client registration → browser login → consent → token exchange).
147
86
 
148
- ## Testing
87
+ ### MCP Local (stdio)
149
88
 
150
- The test suite covers all core components with 1616 tests across 40 suites (unit + integration).
89
+ Run the gateway locally as an MCP stdio server no hosted service needed:
151
90
 
152
91
  ```bash
153
- # Run everything
154
- npm test
155
-
156
- # Run unit tests only (1551 tests across 37 suites)
157
- npm run test:unit
158
-
159
- # Run integration tests only (123 tests, 65 run + 58 auto-skip without Redis/Postgres)
160
- npm run test:integration
161
-
162
- # Run a specific test file
163
- npx jest tests/unit/policy.test.ts
92
+ # Install + register in one step
93
+ npm install -g palaryn
94
+ claude mcp add palaryn -- palaryn mcp
164
95
  ```
165
96
 
166
- Unit test suites cover the policy engine, DLP scanner (regex, TruffleHog, composite backends), budget manager, audit logger, executor registry (HTTP, Slack, no-op), approval manager, rate limiter, all storage backends (memory, PostgreSQL, Redis), Prometheus metrics, OpenTelemetry tracing, JWT/OIDC auth with RBAC, admin dashboard, MCP bridge, anomaly detector, OPA/Rego engine, TypeScript SDK, SaaS routes, and full gateway features. Integration tests exercise the full gateway server end-to-end through the HTTP API, plus Redis/Postgres storage integration tests that auto-skip without running services.
167
-
168
- ---
169
-
170
- ## Docker
171
-
172
- ### Production
97
+ Tools exposed: `http_request`, `http_get`, `http_post` all routed through the full pipeline.
173
98
 
174
- Build and run the gateway with the multi-stage Dockerfile (Node.js 20 Alpine, non-root user):
99
+ ### REST API
175
100
 
176
101
  ```bash
177
- # Build and start with Docker Compose
178
- docker compose up gateway
179
-
180
- # Or build the image directly
181
- docker build -t palaryn .
182
- docker run -p 3000:3000 palaryn
102
+ curl -X POST https://app.palaryn.com/v1/tool/execute \
103
+ -H "Content-Type: application/json" \
104
+ -H "X-API-Key: YOUR_API_KEY" \
105
+ -d '{
106
+ "tool": "http.post",
107
+ "input": { "url": "https://httpbin.org/post", "body": { "key": "value" } },
108
+ "taskId": "my-task",
109
+ "actorId": "my-agent"
110
+ }'
183
111
  ```
184
112
 
185
- The production image runs as a non-root `palaryn` user, includes a health check, and ships with the compiled JavaScript and policy packs only (no source or dev dependencies).
113
+ The API also accepts the full ToolCall schema for advanced use cases (explicit `tool_call_id`, `actor`, `source`, `tool`, `args`).
186
114
 
187
- ### Development
115
+ ### HTTP Forward Proxy
188
116
 
189
- The Compose file includes a `gateway-dev` service that mounts the source directory for live editing:
117
+ Zero-code integration set an environment variable and all outbound HTTP flows through Palaryn:
190
118
 
191
119
  ```bash
192
- docker compose --profile dev up gateway-dev
193
- ```
194
-
195
- ### Docker Compose Environment
196
-
197
- The `docker-compose.yaml` configures both services with sensible defaults. Policy packs are mounted as a read-only volume so you can edit them on the host and restart the gateway to pick up changes.
120
+ export HTTP_PROXY=http://WORKSPACE_ID:API_KEY@gateway:3128
121
+ export HTTPS_PROXY=http://WORKSPACE_ID:API_KEY@gateway:3128
198
122
 
199
- ```yaml
200
- # Key environment defaults (override as needed)
201
- NODE_ENV=production
202
- PORT=3000
203
- AUTH_ENABLED=true
204
- POLICY_PACK_PATH=./policy-packs/default.yaml
123
+ # All HTTP traffic now goes through Palaryn automatically
124
+ curl https://api.github.com/repos/octocat/Hello-World
205
125
  ```
206
126
 
207
- ---
208
-
209
- ## SDK
210
-
211
- ### TypeScript SDK
212
-
213
- The TypeScript SDK (`sdk/typescript/`) provides a `PalarynClient` class for programmatic access to the gateway from any Node.js application or agent orchestrator.
214
-
215
- ```typescript
216
- import { PalarynClient } from './sdk/typescript/src';
217
-
218
- // Set defaults once -- no need to repeat actor/platform on every call
219
- const client = new PalarynClient({
220
- gateway_url: 'http://localhost:3000',
221
- api_key: 'dev-key-001',
222
- timeout_ms: 30000,
223
- defaults: {
224
- actor: { type: 'agent', id: 'my-agent' },
225
- platform: 'langgraph',
226
- },
227
- });
228
-
229
- // Convenience methods use defaults automatically
230
- const getResult = await client.httpGet('task-001', 'https://httpbin.org/get');
231
- const postResult = await client.httpPost('task-002', 'https://httpbin.org/post', { key: 'value' });
232
-
233
- // Override defaults per-call when needed
234
- const customResult = await client.httpGet('task-003', 'https://httpbin.org/get',
235
- { type: 'user', id: 'admin-1' }, 'custom');
236
-
237
- // Execute a full tool call
238
- const result = await client.executeTool({
239
- task_id: 'task-004',
240
- actor: { type: 'agent', id: 'my-agent' },
241
- source: { platform: 'langgraph' },
242
- tool: { name: 'http.request', capability: 'read' },
243
- args: { method: 'GET', url: 'https://api.github.com/repos/owner/repo' },
244
- });
245
-
246
- // Approval workflows
247
- const pending = await client.getPendingApprovals();
248
- await client.approve(approvalToken, 'approver-1');
249
- await client.deny(approvalToken, 'approver-1', 'Not authorized');
250
-
251
- // Observability
252
- const trace = await client.getTaskTrace('task-001');
253
- const policy = await client.getCurrentPolicy();
254
- ```
255
-
256
- The client covers all gateway endpoints: `executeTool`, `approve`, `deny`, `getTaskTrace`, `getCurrentPolicy`, `validatePolicy`, `getPendingApprovals`, and `health`.
127
+ Requires `PROXY_ENABLED=true` on the gateway.
257
128
 
258
129
  ---
259
130
 
260
- ## Policy Packs
131
+ ## Self-Hosted Setup
261
132
 
262
- Policy packs are YAML files that define security rules, domain allowlists, and approval requirements. Three pre-built packs are included (see [`policy-packs/README.md`](policy-packs/README.md) for a detailed comparison):
133
+ ### Prerequisites
263
134
 
264
- | Pack | File | Description |
265
- |---|---|---|
266
- | **Default Safe** | `policy-packs/default.yaml` | SSRF protection, reads allowed, writes need approval, deny delete/admin |
267
- | **Dev Fast** | `policy-packs/dev_fast.yaml` | Permissive reads and writes for development |
268
- | **Prod Strict** | `policy-packs/prod_strict.yaml` | Minimal permissions for production workloads |
135
+ - Node.js 20+
136
+ - npm
269
137
 
270
- ### Example Policy Rule
138
+ ### From Source
271
139
 
272
- ```yaml
273
- rules:
274
- - name: "Require approval for write operations"
275
- description: "All write/delete/admin operations require human approval"
276
- effect: REQUIRE_APPROVAL
277
- priority: 20
278
- conditions:
279
- capabilities:
280
- - "write"
281
- - "delete"
282
- - "admin"
283
- approval:
284
- scope: "team_lead"
285
- ttl_seconds: 3600
286
- reason: "Write/delete/admin operations require approval"
140
+ ```bash
141
+ git clone https://github.com/palaryn-ai/palaryn.git && cd palaryn
142
+ npm install
143
+ npm run build
144
+ npm start
287
145
  ```
288
146
 
289
- Set the active policy pack with the `POLICY_PACK_PATH` environment variable or at startup.
290
-
291
- ---
292
-
293
- ## API Endpoints
147
+ The gateway starts on **port 3000**. Verify: `curl http://localhost:3000/health`
294
148
 
295
- | Method | Endpoint | Description |
296
- |---|---|---|
297
- | `GET` | `/health` | Health check (status, version, timestamp -- always returns 200) |
298
- | `GET` | `/ready` | Readiness probe (returns 503 when unhealthy, for K8s) |
299
- | `GET` | `/metrics` | Prometheus metrics (no auth required) |
300
- | `POST` | `/v1/tool/execute` | Execute a tool call through the gateway |
301
- | `POST` | `/v1/tool/approve` | Approve or deny a pending action |
302
- | `GET` | `/v1/tasks/{task_id}/trace` | Retrieve the full trace for a task |
303
- | `GET` | `/v1/policies/current` | Get the active policy configuration |
304
- | `POST` | `/v1/policies/validate` | Validate a policy configuration before deployment |
305
- | `GET` | `/v1/config/active` | Get active configuration (admin-only, secrets redacted) |
306
- | `GET` | `/v1/approvals/pending` | List pending approval requests |
149
+ ### Docker Compose (Full Stack)
307
150
 
308
- All endpoints (except `/health`, `/ready`, `/metrics`) require authentication via the `X-API-Key` header when `AUTH_ENABLED=true`.
309
-
310
- ### Error Responses
311
-
312
- All error responses follow a standardized format with machine-readable error codes and actionable hints:
151
+ ```bash
152
+ # Gateway + Redis + Postgres + Jaeger
153
+ docker compose up
313
154
 
314
- ```json
315
- {
316
- "error": "Rate limit exceeded for actor agent-1",
317
- "error_code": "RATE_LIMIT_EXCEEDED",
318
- "details": { "retry_after_ms": 5000 },
319
- "hint": "Retry after the reset time or increase rate_limit config"
320
- }
155
+ # With dev hot-reload
156
+ docker compose --profile dev up
321
157
  ```
322
158
 
323
- Error codes: `VALIDATION_FAILED`, `AUTH_REQUIRED`, `AUTH_INVALID_KEY`, `AUTH_KEY_EXPIRED`, `AUTH_KEY_REVOKED`, `AUTH_INSUFFICIENT_PERMS`, `RATE_LIMIT_EXCEEDED`, `POLICY_DENIED`, `BUDGET_EXCEEDED`, `APPROVAL_REQUIRED`, `TOOL_EXECUTION_ERROR`, `INTERNAL_ERROR`, `NOT_FOUND`, `REQUEST_TIMEOUT`.
159
+ ### CLI Commands
160
+
161
+ | Command | Description |
162
+ |---|---|
163
+ | `palaryn start` | Start the gateway server |
164
+ | `palaryn mcp` | Start MCP stdio server |
165
+ | `palaryn --help` | Show all options |
324
166
 
325
167
  ---
326
168
 
@@ -328,388 +170,201 @@ Error codes: `VALIDATION_FAILED`, `AUTH_REQUIRED`, `AUTH_INVALID_KEY`, `AUTH_KEY
328
170
 
329
171
  ### Security & DLP
330
172
 
331
- - **Least-privilege enforcement** -- Tools declare capabilities (read/write/delete/admin); policies gate access by capability level, with write operations requiring approval by default
332
- - **Destination allowlists** -- Domain-level allowlisting with no wildcards by default; IP literals blocked; optional path-level control
333
- - **DLP scanning** -- Entropy-based and pattern-based detection of secrets (API keys, JWTs, OAuth tokens) and PII (emails, phone numbers, addresses) in both request arguments and response outputs
334
- - **Redaction strategies** -- Mask (preserve shape), hash (stable for correlation), drop (remove entirely), or tokenize (replace with placeholders)
335
- - **Incident handling** -- Severity scoring based on destination, data type, and capability; automatic notifications via Slack or webhook; auto-quarantine of keys on severe exfiltration attempts
336
- - **Approval workflows** -- Asynchronous, signed, time-bound approvals for risky actions; approver scopes include team lead, security, and admin roles
337
- - **Compliance posture** -- SOC2-friendly logging, configurable data retention, encryption at rest and in transit
173
+ - **Policy engine** YAML DSL with allow/deny/require-approval rules, domain allowlists, capability-level gating (read/write/delete/admin)
174
+ - **DLP scanning** Entropy-based and pattern-based detection of secrets (API keys, JWTs, tokens) and PII (emails, phone numbers) in both requests and responses
175
+ - **Redaction** Mask, hash, drop, or tokenize sensitive data before it leaves the gateway
176
+ - **Approval workflows** Asynchronous, signed, time-bound approvals for risky operations
177
+ - **SSRF protection** DNS validation, IP pinning, private address blocking
178
+ - **RBAC** Role-based access control with per-workspace API keys and scoped permissions
338
179
 
339
180
  ### Cost & Budget Controls
340
181
 
341
- - **Granular budgets** -- Set spending limits per task, per user/agent, per workspace, and per tool type (e.g., higher limits for HTTP, tighter limits for browserless)
342
- - **Hard stops** -- Maximum steps per task, maximum retries per tool call, and maximum wall-clock time per task
343
- - **Response caching** -- Optional TTL-based caching of GET responses and deduplication of idempotent calls to reduce costs
344
- - **Anomaly detection** -- Rolling baselines per workspace and tool; alerts triggered when costs or retry rates exceed configurable thresholds
345
- - **Cost reporting** -- Dashboards showing top spenders, noisiest tools, and blocked actions; CSV/JSON export for finance teams
182
+ - **Granular budgets** Per-task, per-user, per-workspace, and per-tool spending limits with hard stops
183
+ - **Rate limiting** Configurable per-actor and per-workspace request rate limits
184
+ - **Response caching** TTL-based caching of GET responses and idempotent call deduplication
185
+ - **Anomaly detection** Rolling baselines with z-score anomaly flagging
346
186
 
347
187
  ### Audit & Observability
348
188
 
349
- - **Append-only event log** -- Immutable storage with optional WORM (Write Once Read Many) support for compliance
350
- - **Structured event schema** -- Events for every stage: `TOOL_CALL_RECEIVED`, `POLICY_DECIDED`, `DLP_SCANNED`, `BUDGET_CHECKED`, `TOOL_EXECUTED`, `TOOL_RESULT_RETURNED`, `APPROVAL_REQUESTED`, `INCIDENT_RAISED`, and more
351
- - **Correlation IDs** -- Full traceability via `task_id` and `tool_call_id` across the entire tool call lifecycle
352
- - **Replayable traces** -- Reconstruct any task timeline; optionally re-run tool calls in a sandbox environment (enterprise feature)
353
- - **OpenTelemetry integration** -- Spans per tool call; metrics for latency, error rate, block rate, approvals, and cost
354
- - **SIEM/GRC export** -- Webhook sinks, Splunk/Elastic format templates, and daily digest reports
355
-
356
- ## Architecture Summary
357
-
358
- ```
359
- Agents / Orchestrators
360
- (Claude Code, LangGraph, n8n, custom control rooms, vendor platforms)
361
- |
362
- | ToolCall: toolName + args + context
363
- v
364
- +------------------------------+
365
- | Palaryn |
366
- +------------------------------+
367
- | | | | |
368
- | | | | +--> Audit Store (immutable logs)
369
- | | | +---------> Metrics / Tracing (OpenTelemetry)
370
- | | +----------------> Policy Engine (OPA / custom YAML DSL)
371
- | +----------------------> DLP Engine (PII / secrets detection)
372
- +--------------------------> Tool Executors (HTTP, Slack, Git, DB, Browserless)
373
- |
374
- v
375
- External World / Internal Services
376
- (SaaS APIs, databases, Git providers, Slack/Teams, microservices)
377
- ```
378
-
379
- **Core principle: all agent I/O goes through a single choke point.** Even if an agent is highly capable, it never gets direct, unmediated access to external services.
380
-
381
- ### Runtime Path (per tool call)
382
-
383
- 1. **Authenticate** the request (API key, JWT, or mTLS)
384
- 2. **Normalize** the ToolCall into a canonical schema
385
- 3. **Evaluate policy** -- allow, deny, transform, or require approval
386
- 4. **Scan for DLP** -- detect secrets and PII in arguments and outputs; apply redaction
387
- 5. **Check budget** -- verify per-task/user/org limits; enforce rate limiting
388
- 6. **Execute** the tool call (with retries and backoff)
389
- 7. **Log** an immutable trace event
390
- 8. **Return** the ToolResult with metadata (cost, policy decision, warnings)
391
-
392
- ### Design Non-Negotiables
393
-
394
- - Deterministic behavior: policy decides, the model cannot override
395
- - No bypass path
396
- - Clear audit trail for every action
397
- - Safe defaults: deny-by-default for unknown tools and domains
398
-
399
- ## Integration Patterns
400
-
401
- Palaryn has a single pipeline (auth → rate limit → policy → DLP → budget → execute → audit) with **4 entry points**. Each environment picks the one that requires the least change.
402
-
403
- ### Entry Points
404
-
405
- | Entry Point | Protocol | Code Change | Best For |
406
- |---|---|---|---|
407
- | **Direct API** (`POST /v1/tool/execute`) | HTTP | Minimal — send JSON | Any HTTP-capable system |
408
- | **SDK** (TypeScript / Python) | HTTP (wrapped) | Import + wrapper | Custom agents, orchestrators |
409
- | **Forward Proxy** (`:3128`) | `HTTP_PROXY` env var | Zero | Containers, K8s, sandbox |
410
- | **MCP Bridge** | JSON-RPC over stdio | Zero — config only | Claude Code, Cursor, IDE agents |
411
- | **MCP HTTP** (`/mcp`) | Streamable HTTP | Zero — URL only | Hosted/remote MCP server |
412
-
413
- ### Agent Frameworks (LangGraph, CrewAI, custom)
414
-
415
- Use the Python or TypeScript SDK as a wrapper around tool calls:
416
-
417
- ```python
418
- from palaryn import PalarynClient, Actor
419
-
420
- palaryn = PalarynClient(
421
- gateway_url="http://palaryn:3000",
422
- api_key="key-001",
423
- default_actor=Actor(type="agent", id="research-agent"),
424
- default_platform="langgraph",
425
- )
426
-
427
- # Instead of direct requests.get():
428
- def safe_http_tool(url: str, task_id: str) -> dict:
429
- result = palaryn.http_get(task_id, url)
430
- if result.status == "blocked":
431
- return {"error": result.error}
432
- return result.output
433
- ```
434
-
435
- ### Workflow Engines (n8n, Temporal, Airflow)
189
+ - **Immutable audit log** Append-only event log for every stage of the pipeline
190
+ - **Full traceability** Correlation via `task_id` and `tool_call_id` across the tool call lifecycle
191
+ - **OpenTelemetry** Spans per tool call, Prometheus metrics (latency, error rate, cost, tokens)
192
+ - **Dashboard** React SPA with real-time pipeline visualization, traces, budget charts, and settings
436
193
 
437
- **Option A — HTTP Node:** Point the HTTP Request node at `http://palaryn:3000/v1/tool/execute` with a ToolCall JSON body. Route on the `status` field in the response.
438
-
439
- **Option B — Forward Proxy:** Set `HTTP_PROXY=http://palaryn:3128` on the workflow container. All outbound HTTP flows through Palaryn automatically — zero workflow changes.
440
-
441
- ### LLM Gateways (LiteLLM, Portkey)
442
-
443
- Palaryn **complements** LLM gateways — it does not replace them:
444
-
445
- ```
446
- Agent → LLM Gateway (model routing, token budget) → LLM returns tool_call
447
- → Orchestrator catches tool_call → Palaryn (policy, DLP, budget) → External API
448
- ```
449
-
450
- - **LLM Gateway** = control over models (routing, cost, rate limiting on tokens)
451
- - **Palaryn** = control over tools (policy, DLP, budget on real-world actions)
452
-
453
- ### Mobile & Web Apps (Android, iOS, React, Next.js)
454
-
455
- Client apps **never connect to Palaryn directly** — the backend mediates. The Palaryn API key stays server-side.
456
-
457
- ```
458
- ┌──────────────┐ HTTPS ┌─────────────────┐ Palaryn SDK ┌──────────┐ ┌──────────────┐
459
- │ Mobile / Web │ ────────→ │ Your Backend │ ────────────→ │ Palaryn │ ──→ │ External API │
460
- │ Client │ ←───────── │ (Node/Kotlin) │ ←──────────── │ │ ←── │ │
461
- └──────────────┘ └─────────────────┘ └──────────┘ └──────────────┘
462
- ```
463
-
464
- ### IDE Agents (Claude Code, Cursor)
194
+ ---
465
195
 
466
- Use the MCP Bridge — zero code changes, just configure the MCP server:
196
+ ## Project Structure
467
197
 
468
198
  ```
469
- ┌──────────────┐ stdio JSON-RPC ┌────────────────┐ ┌──────────────┐
470
- │ Claude Code │ ──────────────────→ │ MCP Bridge │ ──→│ External API │
471
- / Cursor │ ←───────────────── │ (Palaryn) │ ←──│ │
472
- └──────────────┘ └────────────────┘ └──────────────┘
473
- ```
474
-
475
- **Hosted (remote MCP server no local build required):**
476
-
477
- ```bash
478
- claude mcp add palaryn --url https://palaryn.com/mcp
199
+ /
200
+ ├── src/
201
+ ├── server/ # Express gateway server + request orchestration
202
+ │ ├── mcp/ # MCP bridge (stdio + HTTP Streamable + OAuth 2.0 provider)
203
+ │ ├── policy/ # Policy engine (YAML DSL evaluation)
204
+ │ ├── dlp/ # DLP scanner (secrets + PII detection, redaction)
205
+ │ ├── budget/ # Budget manager (per-task/user/org budgets, hard stops)
206
+ │ ├── audit/ # Audit logger (immutable event log, trace reconstruction)
207
+ │ ├── executor/ # HTTP executor (retries, backoff, caching, SSRF protection)
208
+ │ ├── approval/ # Approval manager (JWT tokens, time-bound approvals)
209
+ │ ├── auth/ # Authentication (login, session, OAuth providers)
210
+ │ ├── saas/ # SaaS routes (workspaces, API keys, dashboard, events)
211
+ │ ├── admin/ # Admin routes (config, API keys, policy management)
212
+ │ ├── billing/ # Stripe billing (subscriptions, plan enforcement)
213
+ │ ├── proxy/ # HTTP forward proxy (CONNECT tunneling)
214
+ │ ├── middleware/ # Auth, validation, rate limiting, RBAC middleware
215
+ │ ├── storage/ # Storage backends (memory, PostgreSQL, Redis)
216
+ │ ├── metrics/ # Prometheus metrics
217
+ │ ├── tracing/ # OpenTelemetry tracing
218
+ │ ├── config/ # Default configuration + startup validation
219
+ │ ├── types/ # Canonical schemas (ToolCall, ToolResult, Policy, Config)
220
+ │ └── index.ts # Package exports
221
+ ├── web/ # React SPA frontend (dashboard, docs, onboarding)
222
+ ├── sdk/typescript/ # TypeScript SDK client
223
+ ├── sdk/python/ # Python SDK (sync + async clients)
224
+ ├── policy-packs/ # Pre-built YAML policy configurations
225
+ ├── tests/
226
+ │ ├── unit/ # 2600+ unit tests across 67 test suites
227
+ │ └── integration/ # Integration tests (auto-skip without Redis/Postgres)
228
+ ├── Dockerfile # Multi-stage production Docker build
229
+ ├── docker-compose.yaml # Docker Compose (Gateway + Redis + Postgres + Jaeger)
230
+ └── package.json
479
231
  ```
480
232
 
481
- **Local (stdio MCP server):**
482
-
483
- ```bash
484
- # Build first
485
- npm run build
486
-
487
- # Add as MCP server
488
- claude mcp add palaryn -- node /absolute/path/to/dist/src/mcp/server.js
233
+ ---
489
234
 
490
- # Or with a custom policy pack
491
- claude mcp add palaryn -e POLICY_PACK_PATH=./policy-packs/prod_strict.yaml -- node /absolute/path/to/dist/src/mcp/server.js
492
- ```
235
+ ## Development
493
236
 
494
- **Project-level config (`.mcp.json` in project root):**
237
+ ### Commands
495
238
 
496
- ```json
497
- {
498
- "mcpServers": {
499
- "palaryn": {
500
- "type": "stdio",
501
- "command": "node",
502
- "args": ["dist/src/mcp/server.js"],
503
- "env": {
504
- "POLICY_PACK_PATH": "./policy-packs/default.yaml"
505
- }
506
- }
507
- }
508
- }
509
- ```
239
+ | Command | Description |
240
+ |---|---|
241
+ | `npm install` | Install dependencies |
242
+ | `npm run build` | Compile TypeScript to `dist/` |
243
+ | `npm start` | Start in production mode (requires build) |
244
+ | `npm run dev` | Start in development mode (ts-node, no build needed) |
245
+ | `npm test` | Run all tests |
246
+ | `npm run test:unit` | Run unit tests |
247
+ | `npm run test:integration` | Run integration tests |
510
248
 
511
- **Environment variables for MCP mode:**
249
+ ### Environment Variables
512
250
 
513
251
  | Variable | Default | Description |
514
252
  |---|---|---|
515
- | `PALARYN_MCP_WORKSPACE` | `ws-claude-code` | Workspace ID |
516
- | `PALARYN_MCP_ACTOR` | `claude-code` | Actor ID |
517
- | `PALARYN_MCP_PLATFORM` | `claude_code` | Platform identifier |
518
- | `POLICY_PACK_PATH` | `./policy-packs/default.yaml` | Policy pack to enforce |
519
-
520
- Tools exposed: `http_request`, `http_get`, `http_post` all routed through the full Palaryn pipeline (policy, DLP, budget, rate limiting).
521
-
522
- ### Kubernetes
253
+ | `PORT` | `3000` | Server listen port |
254
+ | `NODE_ENV` | `development` | Environment (development / production) |
255
+ | `AUTH_ENABLED` | `true` | Enable authentication |
256
+ | `POLICY_PACK_PATH` | `./policy-packs/default.yaml` | Active policy pack |
257
+ | `AUDIT_LOG_DIR` | `./logs` | Audit log directory |
258
+ | `JWT_SECRET` | (required in prod) | JWT signing secret |
259
+ | `APPROVAL_SECRET` | (required in prod) | Approval workflow secret |
260
+ | `OAUTH_SESSION_SECRET` | (required in prod) | Session cookie secret |
261
+ | `REDIS_URL` | -- | Redis connection URL |
262
+ | `DATABASE_URL` | -- | PostgreSQL connection URL |
263
+ | `PROXY_ENABLED` | `false` | Enable forward proxy on port 3128 |
264
+ | `FRONTEND_ENABLED` | `false` | Serve React SPA frontend |
265
+ | `MCP_OAUTH_ENABLED` | `false` | Enable MCP OAuth 2.0 provider |
266
+ | `MCP_OAUTH_BASE_URL` | -- | Base URL for MCP OAuth |
267
+ | `STRIPE_SECRET_KEY` | -- | Stripe API key for billing |
523
268
 
524
- Three deployment models:
269
+ ---
525
270
 
526
- **Sidecar proxy (per-pod):** One Palaryn container per agent pod. Agent sets `HTTP_PROXY=http://localhost:3128`. Implicit auth via `PALARYN_WORKSPACE_ID` / `PALARYN_ACTOR_ID` env vars. Zero code changes.
271
+ ## Policy Packs
527
272
 
528
- **Shared gateway (centralized):** One Palaryn instance, multiple agents with separate API keys and workspaces. Agents use the SDK or Direct API.
273
+ Policy packs are YAML files that define security rules, domain allowlists, and approval requirements:
529
274
 
530
- **Network-enforced:** K8s NetworkPolicy blocks direct egress from agent pods, forcing all traffic through the Palaryn proxy. Agents **cannot** bypass policy enforcement.
275
+ | Pack | File | Description |
276
+ |---|---|---|
277
+ | **Default Safe** | `policy-packs/default.yaml` | Reads allowed, writes need approval, deny delete/admin |
278
+ | **Dev Fast** | `policy-packs/dev_fast.yaml` | Permissive reads and writes for development |
279
+ | **Prod Strict** | `policy-packs/prod_strict.yaml` | Minimal permissions for production |
531
280
 
532
281
  ```yaml
533
- # Block direct egress — force proxy
534
- apiVersion: networking.k8s.io/v1
535
- kind: NetworkPolicy
536
- spec:
537
- podSelector:
538
- matchLabels: { role: agent }
539
- policyTypes: [Egress]
540
- egress:
541
- - to:
542
- - podSelector:
543
- matchLabels: { app: palaryn }
544
- ports:
545
- - port: 3128
282
+ rules:
283
+ - name: "Require approval for write operations"
284
+ effect: REQUIRE_APPROVAL
285
+ priority: 20
286
+ conditions:
287
+ capabilities: ["write", "delete", "admin"]
288
+ approval:
289
+ scope: "team_lead"
290
+ ttl_seconds: 3600
546
291
  ```
547
292
 
548
- ### Quick Reference
549
-
550
- | Environment | Method | Code Change |
551
- |---|---|---|
552
- | **LangGraph / CrewAI / custom agent** | Python/TS SDK | Minimal — wrapper on tool calls |
553
- | **n8n / Temporal / Airflow** | HTTP Node → API or `HTTP_PROXY` | Zero (proxy) or URL change (API) |
554
- | **Claude Code / Cursor** | MCP Bridge | Zero — configure MCP server |
555
- | **Android / iOS app** | Backend → SDK | Backend mediates |
556
- | **Web app (React / Next.js)** | API Route → SDK | Backend mediates |
557
- | **K8s microservices** | Sidecar proxy + NetworkPolicy | Zero — env var + NetworkPolicy |
558
- | **LLM Gateway (LiteLLM / Portkey)** | SDK in orchestrator | Orchestrator delegates tool calls |
559
- | **Bare metal / VM** | `HTTP_PROXY` env var | Zero — global env var |
560
- | **Serverless (Lambda)** | SDK in handler | Minimal — import + wrapper |
561
-
562
- ### Integration Kit
563
-
564
- | Component | Path | Status |
565
- |---|---|---|
566
- | TypeScript SDK | `sdk/typescript/` | Implemented |
567
- | Python SDK | `sdk/python/` | Implemented (sync + async clients, 102 tests) |
568
- | Policy Packs | `policy-packs/` | Implemented (3 packs: default, dev, prod) |
569
- | Usage Examples | `examples/` | Implemented |
570
- | MCP Bridge | `src/mcp/` | Implemented (stdio + HTTP Streamable transport) |
571
- | n8n Node | `n8n-node/` | Planned |
572
-
573
- ## Canonical Schemas
574
-
575
- ### ToolCall
293
+ ---
576
294
 
577
- Every tool call is normalized into a canonical format containing:
295
+ ## API Endpoints
578
296
 
579
- - **Actor** -- Agent, user, or system identity with display name
580
- - **Source** -- Platform identifier (e.g., `langgraph`, `claude_code`, `n8n`, `custom`) and session ID
581
- - **Tool** -- Name, version, and capability level (`read`, `write`, `delete`, `admin`)
582
- - **Args** -- Tool-specific arguments (method, URL, headers, body, query, etc.)
583
- - **Constraints** -- Per-call cost limit and timeout
584
- - **Context** -- Purpose description and classification labels
297
+ | Method | Endpoint | Description |
298
+ |---|---|---|
299
+ | `POST` | `/v1/tool/execute` | Execute a tool call through the gateway |
300
+ | `POST` | `/v1/tool/approve` | Approve or deny a pending action |
301
+ | `GET` | `/v1/tasks/{id}/trace` | Retrieve the full trace for a task |
302
+ | `GET` | `/v1/policies/current` | Get the active policy configuration |
303
+ | `POST` | `/v1/policies/validate` | Validate a policy before deployment |
304
+ | `GET` | `/v1/approvals/pending` | List pending approval requests |
305
+ | `POST` | `/mcp` | MCP Streamable HTTP endpoint (OAuth 2.0) |
306
+ | `GET` | `/health` | Health check |
307
+ | `GET` | `/ready` | Readiness probe (for K8s) |
308
+ | `GET` | `/metrics` | Prometheus metrics |
585
309
 
586
- ### ToolResult
310
+ All endpoints (except `/health`, `/ready`, `/metrics`) require authentication via `X-API-Key` header or Bearer token.
587
311
 
588
- Every response includes:
312
+ ---
589
313
 
590
- - **Policy decision** -- Allow/deny/transform/require_approval with the matched rule ID and reasons
591
- - **DLP report** -- Detected items, redactions applied, and severity
592
- - **Budget report** -- Estimated cost, spent-to-date for the task, and remaining budget
593
- - **Output** -- The actual tool response (with redactions applied)
594
- - **Timing** -- Start timestamp and duration in milliseconds
314
+ ## Architecture
595
315
 
596
- ### Authentication
316
+ ```
317
+ Agents / Orchestrators
318
+ (Claude Code, Cursor, LangGraph, n8n, custom)
319
+
320
+ │ MCP / REST API / HTTP Proxy
321
+
322
+ ┌──────────────────────────────────────┐
323
+ │ Palaryn Gateway │
324
+ │ ┌──────┬───────┬─────┬──────┬─────┐│
325
+ │ │ Auth │ Rate │ DLP │Policy│Budgt││
326
+ │ │ │ Limit │ │ │ ││
327
+ │ └──┬───┴───┬───┴──┬──┴───┬──┴──┬──┘│
328
+ │ │ │ │ │ │ │
329
+ │ ▼ ▼ ▼ ▼ ▼ │
330
+ │ Executor Audit Metrics Traces │
331
+ └──────────────┬───────────────────────┘
332
+
333
+
334
+ External World / Internal Services
335
+ (SaaS APIs, databases, Git, Slack)
336
+ ```
597
337
 
598
- - **API keys** for quick-start and development
599
- - **mTLS + JWT** for enterprise deployments
600
- - **Per-workspace keys** with scoped permissions
601
- - **Idempotency** via required `tool_call_id` (UUID) for safe retry deduplication
338
+ Every tool call flows through: **Auth Rate Limit → DLP (args) → Policy → Budget → Execute → DLP (output) → Audit → Return**.
602
339
 
603
- ## Deployment
340
+ ---
604
341
 
605
- ### Tech Stack
342
+ ## Tech Stack
606
343
 
607
344
  | Layer | Technology |
608
345
  |---|---|
609
- | **Gateway** | Node.js / TypeScript with Express 5 |
610
- | **Policy DSL** | YAML with JSON Schema validation + OPA/Rego engine (remote + local eval) |
611
- | **Immutable logs** | File-based append-only log + in-memory event store for trace queries |
612
- | **Storage** | In-memory (dev), PostgreSQL (production), Redis (rate limiting + caching) |
613
- | **Auth** | API keys + JWT/OIDC + RBAC with role-based permissions |
614
- | **Observability** | OpenTelemetry tracing (OTLP HTTP exporter) + Prometheus metrics (9 metric types) |
615
- | **Anomaly detection** | Rolling baseline statistics with z-score anomaly flagging |
616
- | **MCP** | JSON-RPC 2.0 over stdio bridge + HTTP Streamable transport (`/mcp`) |
617
- | **SDKs** | TypeScript SDK + Python SDK (sync + async) |
618
- | **Deployment** | Docker / Docker Compose (Gateway + Redis + Postgres + Jaeger) |
619
-
620
- ### Deployment Models
621
-
622
- **SaaS (Multi-Tenant)**
623
- - Kubernetes-based with per-tenant keys and logical isolation
624
- - Optional dedicated clusters for large customers
625
-
626
- **Enterprise (Single-Tenant)**
627
- - Helm chart deployment
628
- - Bring-your-own storage (PostgreSQL, S3)
629
- - Private networking with mTLS
630
-
631
- ### Security Hardening
632
-
633
- - Encryption at rest via KMS
634
- - mTLS for all executor communication
635
- - Secret-less deployments using OIDC federation to cloud providers
636
- - WAF and rate limiting at the edge
637
- - Configurable data retention policies
638
- - Non-root Docker container with minimal Alpine image
639
-
640
- ### SLOs
641
-
642
- - **Latency overhead**: p95 < 50 ms for policy + DLP evaluation (excluding downstream tool latency)
643
- - **Availability**: 99.9%+
644
-
645
- ### Rollout Strategy
346
+ | **Gateway** | Node.js / TypeScript, Express |
347
+ | **Frontend** | React SPA (Vite, Tailwind, Recharts) |
348
+ | **Policy DSL** | YAML with OPA/Rego engine |
349
+ | **Storage** | In-memory (dev), PostgreSQL (prod), Redis (rate limiting + caching) |
350
+ | **Auth** | API keys, JWT/OIDC, OAuth 2.0 (MCP), RBAC |
351
+ | **Observability** | OpenTelemetry (OTLP), Prometheus metrics |
352
+ | **MCP** | JSON-RPC 2.0 over stdio + HTTP Streamable transport |
353
+ | **SDKs** | TypeScript SDK, Python SDK (sync + async) |
354
+ | **Billing** | Stripe (subscriptions, usage metering) |
355
+ | **Deployment** | Docker Compose (Gateway + Redis + Postgres + Caddy) |
646
356
 
647
- 1. **Shadow mode** -- Log-only with no blocking for the first week
648
- 2. **Enforce mode** -- Start by denying only high-risk actions
649
- 3. **Full mode** -- Enable approvals, budgets, and transformations
650
-
651
- ## Pricing Tiers
652
-
653
- | | Free / Dev | Pro | Business | Enterprise |
654
- |---|---|---|---|---|
655
- | **Tool calls / month** | 50,000 | 1,000,000 | 10,000,000 | Unlimited / negotiated |
656
- | **Log retention** | 7 days | 30 days | 180 days | Custom + WORM |
657
- | **Security** | Basic allowlists + secrets scan | Approvals + budgets + basic anomaly | SIEM export + SSO (SAML/OIDC) + policy packs | Custom policy engine (OPA) + private deployment |
658
- | **Support** | Community | Standard | Priority | Dedicated + SLAs |
659
- | **Price** | Free | $99 -- $299 / mo | $999 -- $2,999 / mo | $25,000+ / year |
660
-
661
- ### Add-ons
662
-
663
- - ClickHouse analytics for high-volume event querying
664
- - Sandbox replay runner for post-incident investigation
665
- - Advanced DLP with NER and custom dictionaries
666
- - Browserless executor for headless browser automation
667
-
668
- Pricing is usage-based (per tool call) rather than seat-based, directly mapping to the real work agents perform.
669
-
670
- ## Roadmap Highlights
671
-
672
- ### MVP (2-3 weeks)
673
-
674
- - HTTP executor with domain allowlists and secrets detection
675
- - Structured audit log with immutable storage
676
- - Task and workspace budgets
677
- - Simple web-based approval workflow
678
- - MCP router and SDK adapters
679
-
680
- ### v1 (6-8 weeks)
681
-
682
- - PII detection with configurable redaction strategies
683
- - SIEM export (Splunk, Elastic)
684
- - Cost and governance dashboard (top spenders, blocked actions)
685
- - Pre-built policy packs for dev, prod, and ads workflows
686
-
687
- ### v2 (3-6 months)
688
-
689
- - Anomaly detection v2 with advanced baselines
690
- - Replay sandbox for post-mortem analysis
691
- - Additional executors: Git, read-only database, browserless
692
- - Policy simulator with diff and dry-run capabilities
357
+ ---
693
358
 
694
359
  ## Documentation
695
360
 
696
- The full product documentation is available in the [`docs/`](docs/) directory:
361
+ Full documentation is available at [app.palaryn.com/docs](https://app.palaryn.com/docs) and in the [`docs/`](docs/) directory.
697
362
 
698
363
  | Document | Description |
699
364
  |---|---|
700
- | [00_overview.md](docs/00_overview.md) | Product overview, value proposition, and adoption modes |
701
- | [01_market_problem.md](docs/01_market_problem.md) | Market problem analysis and target buyers |
702
- | [02_architecture.md](docs/02_architecture.md) | System architecture, runtime path, and deployment model |
703
- | [03_core_components.md](docs/03_core_components.md) | Core components: Policy Engine, DLP, Budgeting, Executors, Audit |
704
- | [04_api_contracts.md](docs/04_api_contracts.md) | Canonical ToolCall/ToolResult schemas and API endpoints |
705
- | [05_policy_engine.md](docs/05_policy_engine.md) | Policy engine design, decision model, and rule examples |
706
- | [06_security_dlp.md](docs/06_security_dlp.md) | Security threat model, DLP scanning, redaction, and compliance |
707
- | [07_cost_budgeting.md](docs/07_cost_budgeting.md) | Cost tracking, budgets, hard stops, and anomaly detection |
708
- | [08_audit_observability.md](docs/08_audit_observability.md) | Audit log schema, OpenTelemetry, replay, and SIEM export |
709
- | [09_adapters_integrations.md](docs/09_adapters_integrations.md) | Adapter types and integration kit deliverables |
710
- | [10_deployment_prod.md](docs/10_deployment_prod.md) | Tech stack, deployment models, security hardening, and SLOs |
711
- | [11_pricing_packaging.md](docs/11_pricing_packaging.md) | Pricing tiers, add-ons, and packaging strategy |
712
- | [12_roadmap_gtm.md](docs/12_roadmap_gtm.md) | Roadmap (MVP through v2), GTM strategy, and positioning |
365
+ | [ARCHITECTURE.md](docs/ARCHITECTURE.md) | Full technical architecture |
366
+ | [INDEX.md](docs/INDEX.md) | Product documentation index |
367
+ | [constraints.md](constraints.md) | Coding patterns and invariants |
713
368
 
714
369
  ---
715
370