@zivis/mcp 0.1.8 → 0.1.10

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 (330) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +19 -0
  3. package/dist/api-client.d.ts +2 -24
  4. package/dist/api-client.js +32 -52
  5. package/dist/auth/index.d.ts +1 -22
  6. package/dist/auth/index.js +17 -38
  7. package/dist/auth/jwt.d.ts +0 -16
  8. package/dist/auth/jwt.js +0 -13
  9. package/dist/auth/keychain.d.ts +6 -32
  10. package/dist/auth/keychain.js +83 -114
  11. package/dist/auth/oauth.d.ts +3 -32
  12. package/dist/auth/oauth.js +67 -61
  13. package/dist/auth/sessions.d.ts +5 -25
  14. package/dist/auth/sessions.js +20 -39
  15. package/dist/auth/token-refresh.d.ts +2 -22
  16. package/dist/auth/token-refresh.js +33 -36
  17. package/dist/cli.d.ts +1 -18
  18. package/dist/cli.js +30 -908
  19. package/dist/index.d.ts +0 -6
  20. package/dist/index.js +0 -7
  21. package/dist/lib/inspect-cache.d.ts +10 -0
  22. package/dist/lib/inspect-cache.js +75 -0
  23. package/dist/lib/next-steps.d.ts +27 -0
  24. package/dist/lib/next-steps.js +21 -0
  25. package/dist/matcher/ast-eval.d.ts +8 -0
  26. package/dist/matcher/ast-eval.js +95 -0
  27. package/dist/matcher/finding.d.ts +55 -0
  28. package/dist/matcher/finding.js +1 -0
  29. package/dist/matcher/index.d.ts +8 -0
  30. package/dist/matcher/index.js +202 -0
  31. package/dist/matcher/inference-candidates.d.ts +26 -0
  32. package/dist/matcher/inference-candidates.js +81 -0
  33. package/dist/matcher/walker.d.ts +7 -0
  34. package/dist/matcher/walker.js +71 -0
  35. package/dist/pattern-pack/index.d.ts +125 -0
  36. package/dist/pattern-pack/index.js +189 -0
  37. package/dist/pattern-packs/zivis-public-0.2.0/capsules/agents/privilege-separation.yaml +224 -0
  38. package/dist/pattern-packs/zivis-public-0.2.0/capsules/prompting/self-consistency-no-isolation.yaml +237 -0
  39. package/dist/pattern-packs/zivis-public-0.2.0/capsules/retrieval/context-injection-no-validator.yaml +348 -0
  40. package/dist/pattern-packs/zivis-public-0.2.0/capsules/security/late-org-filter.yaml +266 -0
  41. package/dist/pattern-packs/zivis-public-0.2.0/controls/external_validator_on_facts.yaml +37 -0
  42. package/dist/pattern-packs/zivis-public-0.2.0/controls/fact_validator_present.yaml +68 -0
  43. package/dist/pattern-packs/zivis-public-0.2.0/controls/human_approval_gate.yaml +44 -0
  44. package/dist/pattern-packs/zivis-public-0.2.0/controls/langgraph_state_machine_with_per_node_tools.yaml +35 -0
  45. package/dist/pattern-packs/zivis-public-0.2.0/controls/per_sample_retrieval_diversification.yaml +38 -0
  46. package/dist/pattern-packs/zivis-public-0.2.0/controls/prisma_extension_or_middleware_attaching_org_filter.yaml +31 -0
  47. package/dist/pattern-packs/zivis-public-0.2.0/controls/row_level_security_policy.yaml +37 -0
  48. package/dist/pattern-packs/zivis-public-0.2.0/controls/source_attribution_present.yaml +58 -0
  49. package/dist/pattern-packs/zivis-public-0.2.0/manifest.json +167 -0
  50. package/dist/pattern-packs/zivis-public-0.2.0/prompts/agents/privilege-separation/identify.md +54 -0
  51. package/dist/pattern-packs/zivis-public-0.2.0/prompts/prompting/self-consistency-no-isolation/identify.md +60 -0
  52. package/dist/pattern-packs/zivis-public-0.2.0/prompts/retrieval/context-injection-no-validator/identify.md +109 -0
  53. package/dist/pattern-packs/zivis-public-0.2.0/prompts/security/late-org-filter/identify.md +78 -0
  54. package/dist/project-binding.d.ts +2 -19
  55. package/dist/project-binding.js +38 -21
  56. package/dist/prompts/audit-dependencies.d.ts +2 -0
  57. package/dist/prompts/audit-dependencies.js +47 -0
  58. package/dist/prompts/getting-started.d.ts +2 -0
  59. package/dist/prompts/getting-started.js +37 -0
  60. package/dist/prompts/index.d.ts +2 -0
  61. package/dist/prompts/index.js +6 -0
  62. package/dist/resolve-application-id.d.ts +0 -4
  63. package/dist/resolve-application-id.js +0 -5
  64. package/dist/sanitize.d.ts +1 -21
  65. package/dist/sanitize.js +7 -41
  66. package/dist/server.d.ts +1 -13
  67. package/dist/server.js +142 -265
  68. package/dist/tools/artifacts.d.ts +76 -0
  69. package/dist/tools/artifacts.js +178 -0
  70. package/dist/tools/check-project.d.ts +5 -18
  71. package/dist/tools/check-project.js +122 -110
  72. package/dist/tools/check-repo-trust.d.ts +4 -19
  73. package/dist/tools/check-repo-trust.js +56 -47
  74. package/dist/tools/create-diagram.d.ts +0 -5
  75. package/dist/tools/create-diagram.js +0 -10
  76. package/dist/tools/create-document.d.ts +0 -5
  77. package/dist/tools/create-document.js +3 -9
  78. package/dist/tools/create-finding.d.ts +85 -0
  79. package/dist/tools/create-finding.js +136 -0
  80. package/dist/tools/delete-finding.d.ts +19 -0
  81. package/dist/tools/delete-finding.js +36 -0
  82. package/dist/tools/devx-run.d.ts +88 -0
  83. package/dist/tools/devx-run.js +175 -0
  84. package/dist/tools/discover-local-infra.d.ts +0 -10
  85. package/dist/tools/discover-local-infra.js +3 -73
  86. package/dist/tools/enterprise/get-org-zat.d.ts +0 -5
  87. package/dist/tools/enterprise/get-org-zat.js +0 -6
  88. package/dist/tools/explain-signal-for-diff.d.ts +34 -0
  89. package/dist/tools/explain-signal-for-diff.js +75 -0
  90. package/dist/tools/generate-diagram.d.ts +0 -6
  91. package/dist/tools/generate-diagram.js +21 -13
  92. package/dist/tools/get-application-overview.d.ts +0 -5
  93. package/dist/tools/get-application-overview.js +0 -6
  94. package/dist/tools/get-application.d.ts +0 -5
  95. package/dist/tools/get-application.js +0 -6
  96. package/dist/tools/get-diagram.d.ts +0 -5
  97. package/dist/tools/get-diagram.js +1 -11
  98. package/dist/tools/get-document.d.ts +0 -5
  99. package/dist/tools/get-document.js +0 -6
  100. package/dist/tools/get-oss-zat.d.ts +0 -5
  101. package/dist/tools/get-oss-zat.js +0 -7
  102. package/dist/tools/get-signal.d.ts +24 -0
  103. package/dist/tools/get-signal.js +75 -0
  104. package/dist/tools/get-started.d.ts +18 -0
  105. package/dist/tools/get-started.js +470 -0
  106. package/dist/tools/get-trust-keys.d.ts +0 -5
  107. package/dist/tools/get-trust-keys.js +0 -6
  108. package/dist/tools/import-openapi-endpoints.d.ts +0 -5
  109. package/dist/tools/import-openapi-endpoints.js +0 -6
  110. package/dist/tools/inspect-zat.d.ts +0 -5
  111. package/dist/tools/inspect-zat.js +0 -19
  112. package/dist/tools/inspect.d.ts +21 -0
  113. package/dist/tools/inspect.js +222 -0
  114. package/dist/tools/list-applications.d.ts +1 -6
  115. package/dist/tools/list-applications.js +0 -6
  116. package/dist/tools/list-diagrams.d.ts +0 -5
  117. package/dist/tools/list-diagrams.js +0 -6
  118. package/dist/tools/list-documents.d.ts +0 -5
  119. package/dist/tools/list-documents.js +0 -6
  120. package/dist/tools/list-endpoints.d.ts +1 -6
  121. package/dist/tools/list-endpoints.js +0 -6
  122. package/dist/tools/list-signals.d.ts +37 -0
  123. package/dist/tools/list-signals.js +83 -0
  124. package/dist/tools/manage-application.d.ts +64 -0
  125. package/dist/tools/manage-application.js +129 -0
  126. package/dist/tools/manage-diagram.d.ts +0 -5
  127. package/dist/tools/manage-diagram.js +0 -16
  128. package/dist/tools/manage-endpoint-lifecycle.d.ts +80 -0
  129. package/dist/tools/manage-endpoint-lifecycle.js +180 -0
  130. package/dist/tools/open-in-ide.d.ts +2 -14
  131. package/dist/tools/open-in-ide.js +0 -13
  132. package/dist/tools/review-change.d.ts +34 -0
  133. package/dist/tools/review-change.js +93 -0
  134. package/dist/tools/security-memory.d.ts +76 -0
  135. package/dist/tools/security-memory.js +202 -0
  136. package/dist/tools/security-review.d.ts +1 -21
  137. package/dist/tools/security-review.js +8 -108
  138. package/dist/tools/threat-get-capsule.d.ts +15 -0
  139. package/dist/tools/threat-get-capsule.js +53 -0
  140. package/dist/tools/threat-get-inference-prompt.d.ts +15 -0
  141. package/dist/tools/threat-get-inference-prompt.js +73 -0
  142. package/dist/tools/threat-list-relevant-capsules.d.ts +17 -0
  143. package/dist/tools/threat-list-relevant-capsules.js +158 -0
  144. package/dist/tools/threat-run-matcher.d.ts +17 -0
  145. package/dist/tools/threat-run-matcher.js +145 -0
  146. package/dist/tools/update-document.d.ts +0 -5
  147. package/dist/tools/update-document.js +3 -9
  148. package/dist/tools/update-endpoint.d.ts +1 -6
  149. package/dist/tools/update-endpoint.js +0 -7
  150. package/dist/tools/update-finding.d.ts +61 -0
  151. package/dist/tools/update-finding.js +80 -0
  152. package/dist/tools/update-mermaid-source.d.ts +0 -13
  153. package/dist/tools/update-mermaid-source.js +0 -14
  154. package/dist/tools/verify-trust-mark.d.ts +0 -5
  155. package/dist/tools/verify-trust-mark.js +0 -6
  156. package/dist/types.d.ts +14 -14
  157. package/dist/types.js +22 -28
  158. package/package.json +38 -15
  159. package/dist/api-client.js.map +0 -1
  160. package/dist/auth/index.js.map +0 -1
  161. package/dist/auth/jwt.js.map +0 -1
  162. package/dist/auth/keychain.js.map +0 -1
  163. package/dist/auth/oauth.js.map +0 -1
  164. package/dist/auth/sessions.js.map +0 -1
  165. package/dist/auth/token-refresh.js.map +0 -1
  166. package/dist/cli.js.map +0 -1
  167. package/dist/index.js.map +0 -1
  168. package/dist/project-binding.js.map +0 -1
  169. package/dist/resolve-application-id.js.map +0 -1
  170. package/dist/sanitize.js.map +0 -1
  171. package/dist/server.js.map +0 -1
  172. package/dist/tools/check-project.js.map +0 -1
  173. package/dist/tools/check-repo-trust.js.map +0 -1
  174. package/dist/tools/create-diagram.js.map +0 -1
  175. package/dist/tools/create-document.js.map +0 -1
  176. package/dist/tools/discover-local-infra.js.map +0 -1
  177. package/dist/tools/enterprise/capture-evidence.d.ts +0 -54
  178. package/dist/tools/enterprise/capture-evidence.js +0 -72
  179. package/dist/tools/enterprise/capture-evidence.js.map +0 -1
  180. package/dist/tools/enterprise/create-report-ticket.d.ts +0 -34
  181. package/dist/tools/enterprise/create-report-ticket.js +0 -44
  182. package/dist/tools/enterprise/create-report-ticket.js.map +0 -1
  183. package/dist/tools/enterprise/end-pentest-session.d.ts +0 -33
  184. package/dist/tools/enterprise/end-pentest-session.js +0 -42
  185. package/dist/tools/enterprise/end-pentest-session.js.map +0 -1
  186. package/dist/tools/enterprise/generate-report.d.ts +0 -55
  187. package/dist/tools/enterprise/generate-report.js +0 -111
  188. package/dist/tools/enterprise/generate-report.js.map +0 -1
  189. package/dist/tools/enterprise/get-org-zat.js.map +0 -1
  190. package/dist/tools/enterprise/get-report-status.d.ts +0 -27
  191. package/dist/tools/enterprise/get-report-status.js +0 -38
  192. package/dist/tools/enterprise/get-report-status.js.map +0 -1
  193. package/dist/tools/enterprise/get-threat-model.d.ts +0 -29
  194. package/dist/tools/enterprise/get-threat-model.js +0 -83
  195. package/dist/tools/enterprise/get-threat-model.js.map +0 -1
  196. package/dist/tools/enterprise/list-agents.d.ts +0 -42
  197. package/dist/tools/enterprise/list-agents.js +0 -95
  198. package/dist/tools/enterprise/list-agents.js.map +0 -1
  199. package/dist/tools/enterprise/list-report-issues.d.ts +0 -36
  200. package/dist/tools/enterprise/list-report-issues.js +0 -50
  201. package/dist/tools/enterprise/list-report-issues.js.map +0 -1
  202. package/dist/tools/enterprise/list-threat-models.d.ts +0 -36
  203. package/dist/tools/enterprise/list-threat-models.js +0 -82
  204. package/dist/tools/enterprise/list-threat-models.js.map +0 -1
  205. package/dist/tools/enterprise/manage-actor.d.ts +0 -58
  206. package/dist/tools/enterprise/manage-actor.js +0 -99
  207. package/dist/tools/enterprise/manage-actor.js.map +0 -1
  208. package/dist/tools/enterprise/manage-attack-scenario.d.ts +0 -70
  209. package/dist/tools/enterprise/manage-attack-scenario.js +0 -89
  210. package/dist/tools/enterprise/manage-attack-scenario.js.map +0 -1
  211. package/dist/tools/enterprise/manage-component.d.ts +0 -58
  212. package/dist/tools/enterprise/manage-component.js +0 -90
  213. package/dist/tools/enterprise/manage-component.js.map +0 -1
  214. package/dist/tools/enterprise/manage-data-asset.d.ts +0 -53
  215. package/dist/tools/enterprise/manage-data-asset.js +0 -90
  216. package/dist/tools/enterprise/manage-data-asset.js.map +0 -1
  217. package/dist/tools/enterprise/manage-data-flow.d.ts +0 -57
  218. package/dist/tools/enterprise/manage-data-flow.js +0 -98
  219. package/dist/tools/enterprise/manage-data-flow.js.map +0 -1
  220. package/dist/tools/enterprise/manage-finding.d.ts +0 -69
  221. package/dist/tools/enterprise/manage-finding.js +0 -106
  222. package/dist/tools/enterprise/manage-finding.js.map +0 -1
  223. package/dist/tools/enterprise/manage-security-control.d.ts +0 -59
  224. package/dist/tools/enterprise/manage-security-control.js +0 -96
  225. package/dist/tools/enterprise/manage-security-control.js.map +0 -1
  226. package/dist/tools/enterprise/manage-test-case.d.ts +0 -88
  227. package/dist/tools/enterprise/manage-test-case.js +0 -119
  228. package/dist/tools/enterprise/manage-test-case.js.map +0 -1
  229. package/dist/tools/enterprise/promote-finding-to-issue.d.ts +0 -36
  230. package/dist/tools/enterprise/promote-finding-to-issue.js +0 -65
  231. package/dist/tools/enterprise/promote-finding-to-issue.js.map +0 -1
  232. package/dist/tools/enterprise/publish-report-version.d.ts +0 -34
  233. package/dist/tools/enterprise/publish-report-version.js +0 -75
  234. package/dist/tools/enterprise/publish-report-version.js.map +0 -1
  235. package/dist/tools/enterprise/publish-test-to-library.d.ts +0 -31
  236. package/dist/tools/enterprise/publish-test-to-library.js +0 -40
  237. package/dist/tools/enterprise/publish-test-to-library.js.map +0 -1
  238. package/dist/tools/enterprise/record-test-result.d.ts +0 -67
  239. package/dist/tools/enterprise/record-test-result.js +0 -75
  240. package/dist/tools/enterprise/record-test-result.js.map +0 -1
  241. package/dist/tools/enterprise/start-pentest-session.d.ts +0 -35
  242. package/dist/tools/enterprise/start-pentest-session.js +0 -50
  243. package/dist/tools/enterprise/start-pentest-session.js.map +0 -1
  244. package/dist/tools/enterprise/sync-report-section.d.ts +0 -41
  245. package/dist/tools/enterprise/sync-report-section.js +0 -79
  246. package/dist/tools/enterprise/sync-report-section.js.map +0 -1
  247. package/dist/tools/enterprise/update-report-issue.d.ts +0 -55
  248. package/dist/tools/enterprise/update-report-issue.js +0 -69
  249. package/dist/tools/enterprise/update-report-issue.js.map +0 -1
  250. package/dist/tools/generate-diagram.js.map +0 -1
  251. package/dist/tools/get-agent-test-results.d.ts +0 -41
  252. package/dist/tools/get-agent-test-results.js +0 -86
  253. package/dist/tools/get-agent-test-results.js.map +0 -1
  254. package/dist/tools/get-application-overview.js.map +0 -1
  255. package/dist/tools/get-application.js.map +0 -1
  256. package/dist/tools/get-artifact-content.d.ts +0 -29
  257. package/dist/tools/get-artifact-content.js +0 -86
  258. package/dist/tools/get-artifact-content.js.map +0 -1
  259. package/dist/tools/get-diagram.js.map +0 -1
  260. package/dist/tools/get-document.js.map +0 -1
  261. package/dist/tools/get-finding-details.d.ts +0 -28
  262. package/dist/tools/get-finding-details.js +0 -43
  263. package/dist/tools/get-finding-details.js.map +0 -1
  264. package/dist/tools/get-findings.d.ts +0 -57
  265. package/dist/tools/get-findings.js +0 -103
  266. package/dist/tools/get-findings.js.map +0 -1
  267. package/dist/tools/get-oss-zat.js.map +0 -1
  268. package/dist/tools/get-recon-scan.d.ts +0 -27
  269. package/dist/tools/get-recon-scan.js +0 -46
  270. package/dist/tools/get-recon-scan.js.map +0 -1
  271. package/dist/tools/get-scan-output.d.ts +0 -27
  272. package/dist/tools/get-scan-output.js +0 -64
  273. package/dist/tools/get-scan-output.js.map +0 -1
  274. package/dist/tools/get-scenario-details.d.ts +0 -27
  275. package/dist/tools/get-scenario-details.js +0 -46
  276. package/dist/tools/get-scenario-details.js.map +0 -1
  277. package/dist/tools/get-test-case-results.d.ts +0 -37
  278. package/dist/tools/get-test-case-results.js +0 -66
  279. package/dist/tools/get-test-case-results.js.map +0 -1
  280. package/dist/tools/get-test-details.d.ts +0 -29
  281. package/dist/tools/get-test-details.js +0 -49
  282. package/dist/tools/get-test-details.js.map +0 -1
  283. package/dist/tools/get-trust-keys.js.map +0 -1
  284. package/dist/tools/import-openapi-endpoints.js.map +0 -1
  285. package/dist/tools/inspect-zat.js.map +0 -1
  286. package/dist/tools/list-agent-test-cases.d.ts +0 -41
  287. package/dist/tools/list-agent-test-cases.js +0 -73
  288. package/dist/tools/list-agent-test-cases.js.map +0 -1
  289. package/dist/tools/list-applications.js.map +0 -1
  290. package/dist/tools/list-diagrams.js.map +0 -1
  291. package/dist/tools/list-documents.js.map +0 -1
  292. package/dist/tools/list-endpoints.js.map +0 -1
  293. package/dist/tools/list-recon-scans.d.ts +0 -36
  294. package/dist/tools/list-recon-scans.js +0 -74
  295. package/dist/tools/list-recon-scans.js.map +0 -1
  296. package/dist/tools/list-scan-artifacts.d.ts +0 -41
  297. package/dist/tools/list-scan-artifacts.js +0 -63
  298. package/dist/tools/list-scan-artifacts.js.map +0 -1
  299. package/dist/tools/list-scans.d.ts +0 -44
  300. package/dist/tools/list-scans.js +0 -91
  301. package/dist/tools/list-scans.js.map +0 -1
  302. package/dist/tools/list-test-library.d.ts +0 -44
  303. package/dist/tools/list-test-library.js +0 -83
  304. package/dist/tools/list-test-library.js.map +0 -1
  305. package/dist/tools/list-test-scenarios.d.ts +0 -31
  306. package/dist/tools/list-test-scenarios.js +0 -66
  307. package/dist/tools/list-test-scenarios.js.map +0 -1
  308. package/dist/tools/local-scan.d.ts +0 -40
  309. package/dist/tools/local-scan.js +0 -261
  310. package/dist/tools/local-scan.js.map +0 -1
  311. package/dist/tools/manage-diagram.js.map +0 -1
  312. package/dist/tools/open-in-ide.js.map +0 -1
  313. package/dist/tools/run-test-scenario.d.ts +0 -37
  314. package/dist/tools/run-test-scenario.js +0 -70
  315. package/dist/tools/run-test-scenario.js.map +0 -1
  316. package/dist/tools/scan-pr.d.ts +0 -27
  317. package/dist/tools/scan-pr.js +0 -51
  318. package/dist/tools/scan-pr.js.map +0 -1
  319. package/dist/tools/security-review.js.map +0 -1
  320. package/dist/tools/setup-red-team-target.d.ts +0 -79
  321. package/dist/tools/setup-red-team-target.js +0 -430
  322. package/dist/tools/setup-red-team-target.js.map +0 -1
  323. package/dist/tools/triage-finding.d.ts +0 -47
  324. package/dist/tools/triage-finding.js +0 -116
  325. package/dist/tools/triage-finding.js.map +0 -1
  326. package/dist/tools/update-document.js.map +0 -1
  327. package/dist/tools/update-endpoint.js.map +0 -1
  328. package/dist/tools/update-mermaid-source.js.map +0 -1
  329. package/dist/tools/verify-trust-mark.js.map +0 -1
  330. package/dist/types.js.map +0 -1
@@ -0,0 +1,222 @@
1
+ import { z } from "zod";
2
+ import * as fs from "node:fs/promises";
3
+ import * as fssync from "node:fs";
4
+ import * as path from "node:path";
5
+ import { spawn } from "node:child_process";
6
+ import { fileURLToPath } from "node:url";
7
+ import { detectProjectBinding } from "../project-binding.js";
8
+ import { runMatcher } from "../matcher/index.js";
9
+ import { buildInferenceBundle } from "../matcher/inference-candidates.js";
10
+ import { withNextSteps, withNextStepsError } from "../lib/next-steps.js";
11
+ export const INSPECT_NAME = "zivis_inspect";
12
+ export const INSPECT_DESCRIPTION = `Build a local repo graph and run the local pattern matcher to emit threat-model findings. The threat-model-first conversion event.
13
+
14
+ Prefer zivis_get_started first — it reads the local inspect cache and only calls this tool when a fresh artifact is missing. Calling zivis_inspect directly always re-runs (no idempotency at this layer); reach for it when the user explicitly says "re-inspect" / "rebuild the graph" / "/inspect" or when an entry tool tells you to.
15
+
16
+ Use this when the user says any of:
17
+ - "model this app" / "threat model this repo"
18
+ - "what should we be worried about in this code"
19
+ - "set up security for this project" (after auth/binding is done)
20
+ - "/inspect"
21
+
22
+ What it does, all locally (no source code leaves the machine):
23
+ 1. Spawns 'zivis inspect' to walk the repo and produce a typed graph artifact
24
+ (services, endpoints, external dependencies; auth boundaries + dataflow are Phase 1.5)
25
+ 2. Runs the local matcher against the public pattern pack:
26
+ - AST strategies fire via @ast-grep/napi for TS/JS/Python/Go
27
+ - META strategies fire via the controls library (when no defending control is present)
28
+ - INFER strategies emit candidates the host LLM picks up via zivis_threat_get_inference_prompt
29
+ 3. Returns normalized findings with lane (trusted/inferred), confidence, and evidence spans
30
+
31
+ Trusted-lane findings are evidence-backed (deterministic strategies fired) and ready for the threat model. Inferred-lane findings need host-LLM confirmation via zivis_threat_get_inference_prompt before promotion. Proprietary platform-side eval (Phase 4 cloud upload) and trust-promoted aggregation are separate steps.
32
+
33
+ This is the conversion moment for the threat-model-first sidekick — the user sees specific patterns naming specific files in their repo, in their IDE, in under 30 seconds.`;
34
+ export const INSPECT_SCHEMA = {
35
+ cwd: z
36
+ .string()
37
+ .optional()
38
+ .describe("Working directory to inspect (defaults to server working directory)."),
39
+ application_id: z
40
+ .string()
41
+ .optional()
42
+ .describe("Target application id. If omitted, /inspect resolves it from the project binding. " +
43
+ "Required if the binding is ambiguous or maps to multiple applications."),
44
+ skip_matcher: z
45
+ .boolean()
46
+ .optional()
47
+ .describe("If true, only build the graph artifact; do not run the matcher. Default: false (matcher runs)."),
48
+ };
49
+ export function createInspectHandler(_apiClient, _config) {
50
+ return async (params) => {
51
+ const cwd = params.cwd || process.cwd();
52
+ const detected = detectProjectBinding(cwd);
53
+ if (!detected) {
54
+ return withNextStepsError("No .zivis/project.json found for this directory. /inspect needs a project binding so the resulting threat model attaches to the correct application and org.", [
55
+ {
56
+ id: "run_auth_init",
57
+ label: "Connect this project to your ZIVIS org",
58
+ tool: "zivis_check_project",
59
+ why: "Run 'zivis auth init' or 'zivis auth login' to create the binding, then re-run /inspect.",
60
+ },
61
+ ], "Project not bound — run zivis auth login then re-run /inspect.");
62
+ }
63
+ let inspectStderr = "";
64
+ let artifactPath;
65
+ try {
66
+ const result = await spawnInspect(cwd, params.application_id ?? detected.binding.applicationId);
67
+ inspectStderr = result.stderr;
68
+ artifactPath = parseArtifactPath(result.stderr);
69
+ }
70
+ catch (err) {
71
+ return withNextStepsError(`Could not run 'zivis inspect': ${err.message}`, [
72
+ {
73
+ id: "install_cli",
74
+ label: "Install the ZIVIS CLI globally",
75
+ tool: "zivis_inspect",
76
+ why: "Inspect needs the 'zivis' CLI on PATH (or set ZIVIS_CLI_BIN). pnpm add -g @zivis/cli.",
77
+ },
78
+ ], "Install or surface the ZIVIS CLI binary, then retry.");
79
+ }
80
+ if (!artifactPath) {
81
+ return withNextStepsError(`'zivis inspect' completed but no artifact path was reported. stderr tail:\n${inspectStderr.slice(-500)}`, [], "Inspect ran but produced no artifact path; check the CLI output.");
82
+ }
83
+ if (params.skip_matcher) {
84
+ return withNextSteps({
85
+ status: "graph_only",
86
+ binding: {
87
+ orgName: detected.binding.orgName,
88
+ workosOrgId: detected.binding.workosOrgId,
89
+ applicationId: params.application_id ?? detected.binding.applicationId ?? null,
90
+ },
91
+ artifact_path: artifactPath,
92
+ inspect_stderr_tail: inspectStderr.split("\n").slice(-6).join("\n"),
93
+ }, [
94
+ {
95
+ id: "run_matcher_now",
96
+ label: "Run the matcher against this artifact",
97
+ tool: "zivis_threat_run_matcher",
98
+ why: "Emit the threat findings deterministic + inference strategies produce.",
99
+ },
100
+ ], "Graph artifact built; matcher skipped per request.");
101
+ }
102
+ const matcherResult = await runMatcher({ artifactPath, cwd });
103
+ const inferenceBundle = await buildInferenceBundle(matcherResult.findings);
104
+ const headline = matcherResult.summary.total === 0
105
+ ? `Inspected ${matcherResult.ast_files_scanned} files. No public-pack threat patterns fired against this repo.`
106
+ : `Inspected ${matcherResult.ast_files_scanned} files. Found ${matcherResult.summary.total} threat${matcherResult.summary.total === 1 ? "" : "s"} (${matcherResult.summary.trusted_count} trusted, ${matcherResult.summary.inferred_count} inferred). ` +
107
+ (inferenceBundle.inference_candidates.length > 0
108
+ ? `IMPORTANT: ${inferenceBundle.inference_candidates.length} inference_candidate${inferenceBundle.inference_candidates.length === 1 ? "" : "s"} require host-side execution before findings are presented to the user — see host_required_action.`
109
+ : "");
110
+ return withNextSteps({
111
+ status: "complete",
112
+ binding: {
113
+ orgName: detected.binding.orgName,
114
+ workosOrgId: detected.binding.workosOrgId,
115
+ applicationId: params.application_id ?? detected.binding.applicationId ?? null,
116
+ },
117
+ artifact_path: artifactPath,
118
+ matcher: matcherResult,
119
+ host_required_action: inferenceBundle.host_required_action,
120
+ inference_candidates: inferenceBundle.inference_candidates,
121
+ boundary: {
122
+ local_only: "Repo walk, graph IR construction, public-pack matching, and inference candidate emission all run on this machine. Inference EXECUTION is by your IDE host model (Mode A); no LLM is invoked by ZIVIS itself.",
123
+ sent_to_platform: "Nothing yet — proprietary platform-side evaluation (Phase 4) ships graph features + match candidates, not raw source.",
124
+ stays_on_platform: "Proprietary pattern definitions and final scoring logic.",
125
+ },
126
+ }, matcherResult.summary.trusted_count > 0
127
+ ? [
128
+ {
129
+ id: "review_trusted_findings",
130
+ label: `Review the ${matcherResult.summary.trusted_count} trusted-lane finding${matcherResult.summary.trusted_count === 1 ? "" : "s"}`,
131
+ tool: "zivis_threat_get_capsule",
132
+ why: "Trusted findings are evidence-backed and ready to land in the threat model. Pull each capsule for the full threat narrative + repair contract.",
133
+ },
134
+ ...(matcherResult.summary.inferred_count > 0
135
+ ? [
136
+ {
137
+ id: "host_runs_inference",
138
+ label: `Confirm the ${matcherResult.summary.inferred_count} inferred-lane finding${matcherResult.summary.inferred_count === 1 ? "" : "s"} via your model`,
139
+ tool: "zivis_threat_get_inference_prompt",
140
+ why: "Inferred findings need host-LLM confirmation. Pull the prompt bundle, run inference, and the JSON output enters the inferred lane until promotion.",
141
+ },
142
+ ]
143
+ : []),
144
+ ]
145
+ : matcherResult.summary.inferred_count > 0
146
+ ? [
147
+ {
148
+ id: "host_runs_inference",
149
+ label: `Confirm the ${matcherResult.summary.inferred_count} inferred-lane finding${matcherResult.summary.inferred_count === 1 ? "" : "s"} via your model`,
150
+ tool: "zivis_threat_get_inference_prompt",
151
+ why: "Inferred findings need host-LLM confirmation before they can land in the threat model.",
152
+ },
153
+ ]
154
+ : [
155
+ {
156
+ id: "expand_via_platform",
157
+ label: "Public pack found nothing — proprietary patterns evaluated server-side may still apply",
158
+ tool: "zivis_inspect",
159
+ why: "Phase 4 sends the artifact to the platform for proprietary pattern evaluation; that path is queued.",
160
+ },
161
+ ], headline);
162
+ };
163
+ }
164
+ async function spawnInspect(cwd, applicationId) {
165
+ const bin = await findZivisCliBin();
166
+ const args = ["inspect", "--root", cwd];
167
+ if (applicationId) {
168
+ args.push("--application", applicationId);
169
+ }
170
+ return new Promise((resolve, reject) => {
171
+ const child = spawn(bin.command, [...bin.prefixArgs, ...args], { cwd });
172
+ let stdout = "";
173
+ let stderr = "";
174
+ child.stdout.on("data", (d) => (stdout += d.toString()));
175
+ child.stderr.on("data", (d) => (stderr += d.toString()));
176
+ child.on("error", (err) => reject(err));
177
+ child.on("close", (code) => {
178
+ if (code !== 0) {
179
+ reject(new Error(`zivis inspect exited ${code}\n${stderr.slice(-500)}`));
180
+ return;
181
+ }
182
+ resolve({ stdout, stderr, code: code ?? 0 });
183
+ });
184
+ });
185
+ }
186
+ async function findZivisCliBin() {
187
+ const envBin = process.env.ZIVIS_CLI_BIN;
188
+ if (envBin) {
189
+ if (fssync.existsSync(envBin)) {
190
+ return { command: process.execPath, prefixArgs: [envBin] };
191
+ }
192
+ throw new Error(`ZIVIS_CLI_BIN points to ${envBin} which does not exist`);
193
+ }
194
+ const sibling = await tryResolveZivisCli();
195
+ if (sibling) {
196
+ return { command: process.execPath, prefixArgs: [sibling] };
197
+ }
198
+ return { command: "zivis", prefixArgs: [] };
199
+ }
200
+ async function tryResolveZivisCli() {
201
+ try {
202
+ const here = path.dirname(fileURLToPath(import.meta.url));
203
+ const candidates = [
204
+ path.resolve(here, "../../../zivis-cli/dist/index.js"),
205
+ path.resolve(here, "../../node_modules/@zivis/cli/dist/index.js"),
206
+ path.resolve(here, "../../../node_modules/@zivis/cli/dist/index.js"),
207
+ ];
208
+ for (const c of candidates) {
209
+ if (fssync.existsSync(c))
210
+ return c;
211
+ }
212
+ }
213
+ catch {
214
+ }
215
+ return undefined;
216
+ }
217
+ function parseArtifactPath(stderr) {
218
+ const match = stderr.match(/wrote\s+(\S+\.json)/);
219
+ return match?.[1];
220
+ }
221
+ void parseArtifactPath;
222
+ void fs;
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_applications — List target applications for the organization
3
- *
4
- * Maps to: GET /api/rt/applications
5
- */
6
1
  import { z } from "zod";
7
2
  import type { ApiClient } from "../api-client.js";
8
3
  export declare const LIST_APPLICATIONS_NAME = "zivis_list_applications";
@@ -10,8 +5,8 @@ export declare const LIST_APPLICATIONS_DESCRIPTION = "List target applications c
10
5
  export declare const LIST_APPLICATIONS_SCHEMA: {
11
6
  status: z.ZodOptional<z.ZodEnum<{
12
7
  error: "error";
13
- not_connected: "not_connected";
14
8
  connected: "connected";
9
+ not_connected: "not_connected";
15
10
  expired: "expired";
16
11
  }>>;
17
12
  limit: z.ZodDefault<z.ZodNumber>;
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_applications — List target applications for the organization
3
- *
4
- * Maps to: GET /api/rt/applications
5
- */
6
1
  import { z } from "zod";
7
2
  import { sanitizeResponse } from "../sanitize.js";
8
3
  export const LIST_APPLICATIONS_NAME = "zivis_list_applications";
@@ -71,4 +66,3 @@ export function createListApplicationsHandler(apiClient) {
71
66
  }
72
67
  };
73
68
  }
74
- //# sourceMappingURL=list-applications.js.map
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_diagrams — List diagrams for the org
3
- *
4
- * Maps to: GET /api/diagrams
5
- */
6
1
  import { z } from "zod";
7
2
  import type { ApiClient } from "../api-client.js";
8
3
  export declare const LIST_DIAGRAMS_NAME = "zivis_list_diagrams";
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_diagrams — List diagrams for the org
3
- *
4
- * Maps to: GET /api/diagrams
5
- */
6
1
  import { z } from "zod";
7
2
  import { sanitizeResponse } from "../sanitize.js";
8
3
  export const LIST_DIAGRAMS_NAME = "zivis_list_diagrams";
@@ -78,4 +73,3 @@ export function createListDiagramsHandler(apiClient) {
78
73
  }
79
74
  };
80
75
  }
81
- //# sourceMappingURL=list-diagrams.js.map
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_documents — List documents in the org.
3
- *
4
- * Maps to: GET /api/documents[?threatModelId=<uuid>]
5
- */
6
1
  import { z } from "zod";
7
2
  import type { ApiClient } from "../api-client.js";
8
3
  export declare const LIST_DOCUMENTS_NAME = "zivis_list_documents";
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_documents — List documents in the org.
3
- *
4
- * Maps to: GET /api/documents[?threatModelId=<uuid>]
5
- */
6
1
  import { z } from "zod";
7
2
  import { sanitizeResponse } from "../sanitize.js";
8
3
  export const LIST_DOCUMENTS_NAME = "zivis_list_documents";
@@ -47,4 +42,3 @@ export function createListDocumentsHandler(apiClient) {
47
42
  }
48
43
  };
49
44
  }
50
- //# sourceMappingURL=list-documents.js.map
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_endpoints — List API endpoints for an application
3
- *
4
- * Maps to: GET /api/rt/applications/:id/endpoints
5
- */
6
1
  import { z } from "zod";
7
2
  import type { ApiClient } from "../api-client.js";
8
3
  export declare const LIST_ENDPOINTS_NAME = "zivis_list_endpoints";
@@ -14,8 +9,8 @@ export declare const LIST_ENDPOINTS_SCHEMA: {
14
9
  POST: "POST";
15
10
  GET: "GET";
16
11
  PATCH: "PATCH";
17
- DELETE: "DELETE";
18
12
  PUT: "PUT";
13
+ DELETE: "DELETE";
19
14
  HEAD: "HEAD";
20
15
  OPTIONS: "OPTIONS";
21
16
  }>>;
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_list_endpoints — List API endpoints for an application
3
- *
4
- * Maps to: GET /api/rt/applications/:id/endpoints
5
- */
6
1
  import { z } from "zod";
7
2
  import { requireApplicationId } from "../resolve-application-id.js";
8
3
  import { sanitizeResponse } from "../sanitize.js";
@@ -95,4 +90,3 @@ export function createListEndpointsHandler(apiClient) {
95
90
  }
96
91
  };
97
92
  }
98
- //# sourceMappingURL=list-endpoints.js.map
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+ import type { ApiClient } from "../api-client.js";
3
+ export declare const LIST_SIGNALS_NAME = "zivis_list_signals";
4
+ export declare const LIST_SIGNALS_DESCRIPTION = "List the application's current Signals \u2014 the unified \"needs attention\" stream.\n\nA Signal is ZIVIS's promoted artifact that crosses source families (threat-model Observations, red-team / pen-test Findings, behavior-monitoring Behaviors / Patterns). Each Signal carries severity, status, the chain reference when applicable, and the source family discriminator.\n\nUse this when the user asks:\n- \"what are the open security issues\" / \"what threats does ZIVIS show\"\n- \"what's high or critical\" (filter by severity)\n- \"what's still open\" (filter by status)\n\nReturns display-shaped DTOs. `id` is an opaque token \u2014 pass to `zivis_get_signal` for detail.\n\nSECURITY: This is a low-cost read. Caller must be authorized for the application; cross-org reads return empty.";
5
+ export declare const LIST_SIGNALS_SCHEMA: {
6
+ application_id: z.ZodOptional<z.ZodString>;
7
+ severity: z.ZodOptional<z.ZodEnum<{
8
+ critical: "critical";
9
+ high: "high";
10
+ medium: "medium";
11
+ low: "low";
12
+ info: "info";
13
+ }>>;
14
+ status: z.ZodOptional<z.ZodEnum<{
15
+ open: "open";
16
+ in_progress: "in_progress";
17
+ resolved: "resolved";
18
+ dismissed: "dismissed";
19
+ }>>;
20
+ };
21
+ export declare function createListSignalsHandler(apiClient: ApiClient): (params: {
22
+ application_id?: string;
23
+ severity?: string;
24
+ status?: string;
25
+ }) => Promise<{
26
+ content: {
27
+ type: "text";
28
+ text: string;
29
+ }[];
30
+ isError: boolean;
31
+ } | {
32
+ content: {
33
+ type: "text";
34
+ text: string;
35
+ }[];
36
+ isError?: undefined;
37
+ }>;
@@ -0,0 +1,83 @@
1
+ import { z } from "zod";
2
+ import { requireApplicationId } from "../resolve-application-id.js";
3
+ import { sanitizeResponse } from "../sanitize.js";
4
+ export const LIST_SIGNALS_NAME = "zivis_list_signals";
5
+ export const LIST_SIGNALS_DESCRIPTION = `List the application's current Signals — the unified "needs attention" stream.
6
+
7
+ A Signal is ZIVIS's promoted artifact that crosses source families (threat-model Observations, red-team / pen-test Findings, behavior-monitoring Behaviors / Patterns). Each Signal carries severity, status, the chain reference when applicable, and the source family discriminator.
8
+
9
+ Use this when the user asks:
10
+ - "what are the open security issues" / "what threats does ZIVIS show"
11
+ - "what's high or critical" (filter by severity)
12
+ - "what's still open" (filter by status)
13
+
14
+ Returns display-shaped DTOs. \`id\` is an opaque token — pass to \`zivis_get_signal\` for detail.
15
+
16
+ SECURITY: This is a low-cost read. Caller must be authorized for the application; cross-org reads return empty.`;
17
+ export const LIST_SIGNALS_SCHEMA = {
18
+ application_id: z
19
+ .string()
20
+ .optional()
21
+ .describe("Application UUID (from zivis_list_applications). If omitted, uses applicationId from .zivis/project.json when set."),
22
+ severity: z
23
+ .enum(["critical", "high", "medium", "low", "info"])
24
+ .optional()
25
+ .describe("Filter by severity. Omit to return all."),
26
+ status: z
27
+ .enum(["open", "in_progress", "resolved", "dismissed"])
28
+ .optional()
29
+ .describe("Filter by wire status. Omit to return all."),
30
+ };
31
+ export function createListSignalsHandler(apiClient) {
32
+ return async (params) => {
33
+ const req = requireApplicationId(params.application_id);
34
+ if (!req.ok) {
35
+ return {
36
+ content: [{ type: "text", text: `Error: ${req.message}` }],
37
+ isError: true,
38
+ };
39
+ }
40
+ const application_id = req.id;
41
+ const qs = new URLSearchParams();
42
+ if (params.severity)
43
+ qs.set("severity", params.severity);
44
+ if (params.status)
45
+ qs.set("status", params.status);
46
+ const path = `/api/apps/${application_id}/signals${qs.toString() ? `?${qs}` : ""}`;
47
+ try {
48
+ const data = await apiClient.get(path);
49
+ const result = {
50
+ total: data.length,
51
+ items: data.map((s) => ({
52
+ id: s.id,
53
+ source: s.source,
54
+ severity: s.severity,
55
+ status: s.status,
56
+ confidence: s.confidence,
57
+ title: s.title,
58
+ category: s.category,
59
+ attack_chain: s.attackChain
60
+ ? {
61
+ name: s.attackChain.chainName,
62
+ step: `${s.attackChain.stepIndex}/${s.attackChain.totalSteps}`,
63
+ }
64
+ : null,
65
+ components: s.components?.map((c) => c.name) ?? [],
66
+ recommended_action: s.recommendedAction,
67
+ })),
68
+ };
69
+ return {
70
+ content: [
71
+ { type: "text", text: JSON.stringify(sanitizeResponse(result), null, 2) },
72
+ ],
73
+ };
74
+ }
75
+ catch (err) {
76
+ const message = err instanceof Error ? err.message : "Failed to list signals";
77
+ return {
78
+ content: [{ type: "text", text: `Error: ${message}` }],
79
+ isError: true,
80
+ };
81
+ }
82
+ };
83
+ }
@@ -0,0 +1,64 @@
1
+ import { z } from "zod";
2
+ import type { ApiClient } from "../api-client.js";
3
+ export declare const MANAGE_APPLICATION_NAME = "zivis_manage_application";
4
+ export declare const MANAGE_APPLICATION_DESCRIPTION = "Create, update, or delete a target application.\n\nActions:\n- create: requires at least name, base_url, auth_type\n- update: patch an existing application (requires application_id)\n- delete: remove an application (requires application_id)";
5
+ export declare const MANAGE_APPLICATION_SCHEMA: {
6
+ action: z.ZodEnum<{
7
+ create: "create";
8
+ update: "update";
9
+ delete: "delete";
10
+ }>;
11
+ application_id: z.ZodOptional<z.ZodString>;
12
+ name: z.ZodOptional<z.ZodString>;
13
+ description: z.ZodOptional<z.ZodString>;
14
+ base_url: z.ZodOptional<z.ZodString>;
15
+ api_url: z.ZodOptional<z.ZodString>;
16
+ auth_type: z.ZodOptional<z.ZodEnum<{
17
+ none: "none";
18
+ oauth_pkce: "oauth_pkce";
19
+ static_token: "static_token";
20
+ client_credentials: "client_credentials";
21
+ bearer_refresh: "bearer_refresh";
22
+ }>>;
23
+ has_rag: z.ZodOptional<z.ZodBoolean>;
24
+ has_tools: z.ZodOptional<z.ZodBoolean>;
25
+ has_memory: z.ZodOptional<z.ZodBoolean>;
26
+ is_multi_turn: z.ZodOptional<z.ZodBoolean>;
27
+ system_context: z.ZodOptional<z.ZodString>;
28
+ type: z.ZodOptional<z.ZodEnum<{
29
+ api: "api";
30
+ chat: "chat";
31
+ sse: "sse";
32
+ validation: "validation";
33
+ web: "web";
34
+ }>>;
35
+ use_ephemeral_creds: z.ZodOptional<z.ZodBoolean>;
36
+ };
37
+ export declare function createManageApplicationHandler(apiClient: ApiClient): (params: {
38
+ action: "create" | "update" | "delete";
39
+ application_id?: string;
40
+ name?: string;
41
+ description?: string;
42
+ base_url?: string;
43
+ api_url?: string;
44
+ auth_type?: "none" | "oauth_pkce" | "static_token" | "client_credentials" | "bearer_refresh";
45
+ has_rag?: boolean;
46
+ has_tools?: boolean;
47
+ has_memory?: boolean;
48
+ is_multi_turn?: boolean;
49
+ system_context?: string;
50
+ type?: "api" | "chat" | "sse" | "validation" | "web";
51
+ use_ephemeral_creds?: boolean;
52
+ }) => Promise<{
53
+ content: {
54
+ type: "text";
55
+ text: string;
56
+ }[];
57
+ isError: boolean;
58
+ } | {
59
+ content: {
60
+ type: "text";
61
+ text: string;
62
+ }[];
63
+ isError?: undefined;
64
+ }>;
@@ -0,0 +1,129 @@
1
+ import { z } from "zod";
2
+ import { requireApplicationId } from "../resolve-application-id.js";
3
+ import { sanitizeResponse } from "../sanitize.js";
4
+ export const MANAGE_APPLICATION_NAME = "zivis_manage_application";
5
+ export const MANAGE_APPLICATION_DESCRIPTION = `Create, update, or delete a target application.
6
+
7
+ Actions:
8
+ - create: requires at least name, base_url, auth_type
9
+ - update: patch an existing application (requires application_id)
10
+ - delete: remove an application (requires application_id)`;
11
+ export const MANAGE_APPLICATION_SCHEMA = {
12
+ action: z.enum(["create", "update", "delete"]).describe("CRUD action"),
13
+ application_id: z
14
+ .string()
15
+ .optional()
16
+ .describe("Required for update/delete. Optional for create."),
17
+ name: z.string().optional().describe("Application name"),
18
+ description: z.string().optional().describe("Application description"),
19
+ base_url: z.string().optional().describe("Base URL, e.g. https://api.example.com"),
20
+ api_url: z.string().optional().describe("Explicit API URL"),
21
+ auth_type: z
22
+ .enum(["none", "oauth_pkce", "static_token", "client_credentials", "bearer_refresh"])
23
+ .optional()
24
+ .describe("Application auth type (required for create)"),
25
+ has_rag: z.boolean().optional().describe("LLM capability flag"),
26
+ has_tools: z.boolean().optional().describe("LLM capability flag"),
27
+ has_memory: z.boolean().optional().describe("LLM capability flag"),
28
+ is_multi_turn: z.boolean().optional().describe("LLM capability flag"),
29
+ system_context: z.string().optional().describe("System context/prompt context"),
30
+ type: z
31
+ .enum(["api", "chat", "sse", "validation", "web"])
32
+ .optional()
33
+ .describe("Application type"),
34
+ use_ephemeral_creds: z
35
+ .boolean()
36
+ .optional()
37
+ .describe("Whether ephemeral credentials are enabled"),
38
+ };
39
+ export function createManageApplicationHandler(apiClient) {
40
+ return async (params) => {
41
+ try {
42
+ const { action } = params;
43
+ let data;
44
+ if (action === "create") {
45
+ if (!params.name || !params.base_url || !params.auth_type) {
46
+ return {
47
+ content: [
48
+ {
49
+ type: "text",
50
+ text: "Error: create requires name, base_url, and auth_type",
51
+ },
52
+ ],
53
+ isError: true,
54
+ };
55
+ }
56
+ data = await apiClient.post("/api/rt/applications", {
57
+ name: params.name,
58
+ description: params.description,
59
+ baseUrl: params.base_url,
60
+ apiUrl: params.api_url,
61
+ authType: params.auth_type,
62
+ hasRag: params.has_rag,
63
+ hasTools: params.has_tools,
64
+ hasMemory: params.has_memory,
65
+ isMultiTurn: params.is_multi_turn,
66
+ systemContext: params.system_context,
67
+ type: params.type,
68
+ useEphemeralCreds: params.use_ephemeral_creds,
69
+ });
70
+ }
71
+ else {
72
+ const req = requireApplicationId(params.application_id);
73
+ if (!req.ok) {
74
+ return {
75
+ content: [{ type: "text", text: `Error: ${req.message}` }],
76
+ isError: true,
77
+ };
78
+ }
79
+ if (action === "delete") {
80
+ data = await apiClient.del(`/api/rt/applications/${req.id}`);
81
+ }
82
+ else {
83
+ const body = {};
84
+ if (params.name !== undefined)
85
+ body.name = params.name;
86
+ if (params.description !== undefined)
87
+ body.description = params.description;
88
+ if (params.base_url !== undefined)
89
+ body.baseUrl = params.base_url;
90
+ if (params.api_url !== undefined)
91
+ body.apiUrl = params.api_url;
92
+ if (params.auth_type !== undefined)
93
+ body.authType = params.auth_type;
94
+ if (params.has_rag !== undefined)
95
+ body.hasRag = params.has_rag;
96
+ if (params.has_tools !== undefined)
97
+ body.hasTools = params.has_tools;
98
+ if (params.has_memory !== undefined)
99
+ body.hasMemory = params.has_memory;
100
+ if (params.is_multi_turn !== undefined)
101
+ body.isMultiTurn = params.is_multi_turn;
102
+ if (params.system_context !== undefined)
103
+ body.systemContext = params.system_context;
104
+ if (params.type !== undefined)
105
+ body.type = params.type;
106
+ if (params.use_ephemeral_creds !== undefined) {
107
+ body.useEphemeralCreds = params.use_ephemeral_creds;
108
+ }
109
+ data = await apiClient.patch(`/api/rt/applications/${req.id}`, body);
110
+ }
111
+ }
112
+ const sanitized = sanitizeResponse({
113
+ action,
114
+ application_id: params.application_id,
115
+ result: data,
116
+ });
117
+ return {
118
+ content: [{ type: "text", text: JSON.stringify(sanitized, null, 2) }],
119
+ };
120
+ }
121
+ catch (err) {
122
+ const message = err instanceof Error ? err.message : "Failed to manage application";
123
+ return {
124
+ content: [{ type: "text", text: `Error: ${message}` }],
125
+ isError: true,
126
+ };
127
+ }
128
+ };
129
+ }
@@ -1,8 +1,3 @@
1
- /**
2
- * zivis_manage_diagram — Update, delete, or modify diagram content
3
- *
4
- * Maps to: PATCH/DELETE /api/diagrams/:id and sub-resource endpoints
5
- */
6
1
  import { z } from "zod";
7
2
  import type { ApiClient } from "../api-client.js";
8
3
  export declare const MANAGE_DIAGRAM_NAME = "zivis_manage_diagram";