perfai-cloud-mcp 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +47 -26
  2. package/dist/auth/oauthFlow.d.ts +1 -1
  3. package/dist/auth/oauthFlow.js +3 -3
  4. package/dist/auth/tokenValidator.d.ts +2 -2
  5. package/dist/auth/tokenValidator.js +3 -3
  6. package/dist/cli.js +42 -42
  7. package/dist/client/apiClient.d.ts +13 -4
  8. package/dist/client/apiClient.d.ts.map +1 -1
  9. package/dist/client/apiClient.js +63 -9
  10. package/dist/client/authManager.d.ts +20 -1
  11. package/dist/client/authManager.d.ts.map +1 -1
  12. package/dist/client/authManager.js +47 -0
  13. package/dist/client/types.d.ts +18 -0
  14. package/dist/client/types.d.ts.map +1 -1
  15. package/dist/config.d.ts +4 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +23 -4
  18. package/dist/prompts.d.ts +31 -0
  19. package/dist/prompts.d.ts.map +1 -0
  20. package/dist/prompts.js +53 -0
  21. package/dist/server.js +37 -10
  22. package/dist/tools/index.d.ts +70 -18
  23. package/dist/tools/index.d.ts.map +1 -1
  24. package/dist/tools/index.js +3 -1
  25. package/dist/tools/protected/autoFix.d.ts +5 -1
  26. package/dist/tools/protected/autoFix.d.ts.map +1 -1
  27. package/dist/tools/protected/autoFix.js +27 -12
  28. package/dist/tools/protected/autoFixAll.d.ts +6 -2
  29. package/dist/tools/protected/autoFixAll.d.ts.map +1 -1
  30. package/dist/tools/protected/autoFixAll.js +29 -32
  31. package/dist/tools/protected/getFixSummary.d.ts +5 -1
  32. package/dist/tools/protected/getFixSummary.d.ts.map +1 -1
  33. package/dist/tools/protected/getFixSummary.js +35 -36
  34. package/dist/tools/protected/getVulnerabilities.d.ts +5 -1
  35. package/dist/tools/protected/getVulnerabilities.d.ts.map +1 -1
  36. package/dist/tools/protected/getVulnerabilities.js +7 -5
  37. package/dist/tools/protected/listApps.d.ts +1 -1
  38. package/dist/tools/protected/listApps.d.ts.map +1 -1
  39. package/dist/tools/protected/listApps.js +2 -1
  40. package/dist/tools/protected/logout.d.ts +1 -1
  41. package/dist/tools/protected/logout.js +1 -1
  42. package/dist/tools/protected/manageOrganizations.d.ts +26 -0
  43. package/dist/tools/protected/manageOrganizations.d.ts.map +1 -0
  44. package/dist/tools/protected/manageOrganizations.js +131 -0
  45. package/dist/tools/protected/registerApp.d.ts +1 -1
  46. package/dist/tools/protected/registerApp.js +3 -3
  47. package/dist/tools/protected/runSecurityTest.d.ts +5 -1
  48. package/dist/tools/protected/runSecurityTest.d.ts.map +1 -1
  49. package/dist/tools/protected/runSecurityTest.js +7 -5
  50. package/dist/tools/protected/selectApp.d.ts +1 -1
  51. package/dist/tools/protected/selectApp.d.ts.map +1 -1
  52. package/dist/tools/protected/selectApp.js +3 -1
  53. package/dist/tools/protected/vulnerabilityActions.d.ts +12 -4
  54. package/dist/tools/protected/vulnerabilityActions.d.ts.map +1 -1
  55. package/dist/tools/protected/vulnerabilityActions.js +25 -6
  56. package/dist/tools/public/authStatus.d.ts +1 -1
  57. package/dist/tools/public/authStatus.js +1 -1
  58. package/dist/tools/public/login.d.ts +12 -2
  59. package/dist/tools/public/login.d.ts.map +1 -1
  60. package/dist/tools/public/login.js +78 -86
  61. package/dist/utils/appResolver.d.ts +24 -0
  62. package/dist/utils/appResolver.d.ts.map +1 -0
  63. package/dist/utils/appResolver.js +156 -0
  64. package/dist/utils/formatters.d.ts +2 -1
  65. package/dist/utils/formatters.d.ts.map +1 -1
  66. package/dist/utils/formatters.js +19 -1
  67. package/dist/utils/promptBuilder.d.ts +8 -2
  68. package/dist/utils/promptBuilder.d.ts.map +1 -1
  69. package/dist/utils/promptBuilder.js +42 -26
  70. package/package.json +7 -8
  71. package/LICENSE +0 -21
@@ -1,3 +1,5 @@
1
+ import { getAllVulnerabilities } from "../../client/apiClient.js";
2
+ import { APP_NAME_PROPERTY, resolveApp } from "../../utils/appResolver.js";
1
3
  import { buildAutoFixInstruction } from "../../utils/promptBuilder.js";
2
4
  export const autoFixTool = {
3
5
  name: "auto_fix",
@@ -12,9 +14,10 @@ export const autoFixTool = {
12
14
  type: "string",
13
15
  description: "Sequence number from get_vulnerabilities (e.g. '3') or raw vulnerability id",
14
16
  },
17
+ app: APP_NAME_PROPERTY,
15
18
  appId: {
16
19
  type: "string",
17
- description: "App ID (defaults to the current app)",
20
+ description: "App ID (alternative to app; defaults to the current app)",
18
21
  },
19
22
  },
20
23
  required: ["vulnerability_id"],
@@ -22,32 +25,45 @@ export const autoFixTool = {
22
25
  },
23
26
  };
24
27
  export async function handleAutoFix(auth, args) {
25
- const appId = args?.appId ?? auth.currentAppId;
26
- if (!appId) {
28
+ if (!args?.vulnerability_id) {
27
29
  return {
28
- content: [{ type: "text", text: "❌ No app selected. Run register_app or select_app first." }],
30
+ content: [{ type: "text", text: "❌ vulnerability_id is required." }],
29
31
  };
30
32
  }
31
- if (!args?.vulnerability_id) {
33
+ let appLabel;
34
+ let vuln;
35
+ try {
36
+ const resolved = await resolveApp(auth, args);
37
+ if (!resolved.ok)
38
+ return { content: [{ type: "text", text: resolved.message }] };
39
+ const { appId } = resolved.app;
40
+ appLabel = resolved.app.label;
41
+ vuln = auth.getCachedVulnerability(appId, args.vulnerability_id);
42
+ if (!vuln) {
43
+ // Fresh session (e.g. the user named the app directly) — load findings instead of failing.
44
+ auth.cacheVulnerabilities(appId, await getAllVulnerabilities(auth, appId));
45
+ vuln = auth.getCachedVulnerability(appId, args.vulnerability_id);
46
+ }
47
+ }
48
+ catch (error) {
32
49
  return {
33
- content: [{ type: "text", text: "❌ vulnerability_id is required." }],
50
+ content: [{ type: "text", text: `❌ Failed to fetch vulnerabilities: ${error instanceof Error ? error.message : String(error)}` }],
34
51
  };
35
52
  }
36
- const vuln = auth.getCachedVulnerability(appId, args.vulnerability_id);
37
53
  if (!vuln) {
38
54
  return {
39
55
  content: [
40
56
  {
41
57
  type: "text",
42
- text: `❌ Could not find "${args.vulnerability_id}" in the last get_vulnerabilities listing ` +
43
- `for this app. Run get_vulnerabilities first, then reference the # it shows.`,
58
+ text: `❌ Could not find vulnerability "${args.vulnerability_id}" for "${appLabel}". ` +
59
+ `Run get_vulnerabilities to see the numbered list.`,
44
60
  },
45
61
  ],
46
62
  };
47
63
  }
48
- if (vuln.isFixed) {
64
+ if (vuln.isFixed || vuln.fixClaimed) {
49
65
  return {
50
- content: [{ type: "text", text: `✅ Vulnerability #${args.vulnerability_id} is already marked as fixed.` }],
66
+ content: [{ type: "text", text: `✅ Vulnerability #${args.vulnerability_id} is already ${vuln.isFixed ? "fixed" : "claimed fixed (pending re-scan)"}.` }],
51
67
  };
52
68
  }
53
69
  if (vuln.isDismissed) {
@@ -57,7 +73,6 @@ export async function handleAutoFix(auth, args) {
57
73
  }
58
74
  const seq = Number(args.vulnerability_id);
59
75
  const sequence = Number.isInteger(seq) && seq > 0 ? seq : 1;
60
- const appLabel = auth.currentAppUrl ?? appId;
61
76
  return {
62
77
  content: [{ type: "text", text: buildAutoFixInstruction(appLabel, vuln, sequence) }],
63
78
  };
@@ -5,9 +5,13 @@ export declare const autoFixAllTool: {
5
5
  readonly inputSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {
8
+ readonly app: {
9
+ readonly type: "string";
10
+ readonly description: string;
11
+ };
8
12
  readonly appId: {
9
13
  readonly type: "string";
10
- readonly description: "App ID (defaults to the current app)";
14
+ readonly description: "App ID (alternative to app; defaults to the current app)";
11
15
  };
12
16
  readonly severity: {
13
17
  readonly type: "string";
@@ -16,7 +20,7 @@ export declare const autoFixAllTool: {
16
20
  };
17
21
  readonly max_fixes: {
18
22
  readonly type: "number";
19
- readonly description: "Maximum number of fixes to include (default: all)";
23
+ readonly description: "Fix only the N most severe open vulnerabilities (default: all)";
20
24
  };
21
25
  };
22
26
  readonly additionalProperties: false;
@@ -1 +1 @@
1
- {"version":3,"file":"autoFixAll.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/autoFixAll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;CA0BjB,CAAC;AAEX,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAyDjF"}
1
+ {"version":3,"file":"autoFixAll.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/autoFixAll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAM1D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BjB,CAAC;AAEX,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CA8CjF"}
@@ -1,17 +1,24 @@
1
- import { getVulnerabilities } from "../../client/apiClient.js";
2
- import { buildBatchFixPlan } from "../../utils/promptBuilder.js";
1
+ import { getAllVulnerabilities } from "../../client/apiClient.js";
2
+ import { FIX_BATCH_SIZE } from "../../config.js";
3
+ import { APP_NAME_PROPERTY, resolveApp } from "../../utils/appResolver.js";
4
+ import { buildBatchFixPlan, isOpen, sortBySeverity } from "../../utils/promptBuilder.js";
3
5
  export const autoFixAllTool = {
4
6
  name: "auto_fix_all",
5
- description: "🔧 Auto-fix ALL unfixed vulnerabilities for the current app. Fetches every vulnerability, " +
6
- "builds a prioritized fix plan (critical → low), and returns structured step-by-step " +
7
- "instructions for each. You (the AI assistant) should execute each fix in order, then call " +
8
- "mark_vulnerability_fixed for each one after applying the code change.",
7
+ description: "🔧 ONE-CALL FIX. When the user says \"<App> fix all\", \"<App> fix critical\" or \"<App> fix 3\" " +
8
+ "(e.g. \"Bookstore fix all\"), call this tool directly with app: \"<App>\" — do NOT call login, list_apps, " +
9
+ "select_app or manage_organizations first; sign-in happens automatically and the name is resolved " +
10
+ "across all of the user's orgs. " +
11
+ "\"fix all\" → no filter; \"fix critical|high|medium|low\" → severity; \"fix N\" → max_fixes: N " +
12
+ "(the N most severe). Returns a prioritized plan (critical → low) that you execute autonomously: " +
13
+ "fix each finding and call mark_vulnerability_fixed, or — if it does not apply to the code — " +
14
+ "silently call dismiss_vulnerability with a specific reason.",
9
15
  inputSchema: {
10
16
  type: "object",
11
17
  properties: {
18
+ app: APP_NAME_PROPERTY,
12
19
  appId: {
13
20
  type: "string",
14
- description: "App ID (defaults to the current app)",
21
+ description: "App ID (alternative to app; defaults to the current app)",
15
22
  },
16
23
  severity: {
17
24
  type: "string",
@@ -20,35 +27,23 @@ export const autoFixAllTool = {
20
27
  },
21
28
  max_fixes: {
22
29
  type: "number",
23
- description: "Maximum number of fixes to include (default: all)",
30
+ description: "Fix only the N most severe open vulnerabilities (default: all)",
24
31
  },
25
32
  },
26
33
  additionalProperties: false,
27
34
  },
28
35
  };
29
36
  export async function handleAutoFixAll(auth, args) {
30
- const appId = args?.appId ?? auth.currentAppId;
31
- if (!appId) {
32
- return {
33
- content: [{ type: "text", text: "❌ No app selected. Run register_app or select_app first." }],
34
- };
35
- }
36
37
  try {
37
- // Fetch all vulnerabilities (paginate through all pages)
38
- let allVulnerabilities = [];
39
- let page = 1;
40
- const pageSize = 100;
41
- while (true) {
42
- const result = await getVulnerabilities(auth, appId, { page, pageSize });
43
- allVulnerabilities = allVulnerabilities.concat(result.data);
44
- if (allVulnerabilities.length >= result.total)
45
- break;
46
- page++;
47
- }
48
- // Cache them for mark_vulnerability_fixed calls later
38
+ const resolved = await resolveApp(auth, args);
39
+ if (!resolved.ok)
40
+ return { content: [{ type: "text", text: resolved.message }] };
41
+ const { appId, label } = resolved.app;
42
+ const allVulnerabilities = await getAllVulnerabilities(auth, appId);
43
+ // Cache them for mark_vulnerability_fixed / dismiss_vulnerability calls later
49
44
  auth.cacheVulnerabilities(appId, allVulnerabilities);
50
- // Apply filters
51
- let toFix = allVulnerabilities.filter(v => !v.isFixed && !v.isDismissed);
45
+ // Sort before limiting, so "fix 1" means the most severe open finding.
46
+ let toFix = sortBySeverity(allVulnerabilities.filter(isOpen));
52
47
  if (args?.severity) {
53
48
  const target = args.severity.toLowerCase();
54
49
  toFix = toFix.filter(v => (v.severity ?? "").toLowerCase() === target);
@@ -58,12 +53,14 @@ export async function handleAutoFixAll(auth, args) {
58
53
  }
59
54
  if (toFix.length === 0) {
60
55
  const msg = args?.severity
61
- ? `✅ No unfixed ${args.severity} vulnerabilities found.`
62
- : "✅ No unfixed vulnerabilities found. All issues are either fixed or dismissed.";
56
+ ? `✅ No open ${args.severity} vulnerabilities for "${label}".`
57
+ : `✅ No open vulnerabilities for "${label}" — everything is fixed, claimed fixed, or dismissed.`;
63
58
  return { content: [{ type: "text", text: msg }] };
64
59
  }
65
- const appLabel = auth.currentAppUrl ?? appId;
66
- const plan = buildBatchFixPlan(appLabel, toFix);
60
+ // Large apps are returned in batches so one response never blows the client's
61
+ // tool-output limit; handled items drop out of isOpen, so the next call is the next batch.
62
+ const batch = toFix.slice(0, FIX_BATCH_SIZE);
63
+ const plan = buildBatchFixPlan(label, batch, toFix.length - batch.length);
67
64
  return { content: [{ type: "text", text: plan }] };
68
65
  }
69
66
  catch (error) {
@@ -5,9 +5,13 @@ export declare const getFixSummaryTool: {
5
5
  readonly inputSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {
8
+ readonly app: {
9
+ readonly type: "string";
10
+ readonly description: string;
11
+ };
8
12
  readonly appId: {
9
13
  readonly type: "string";
10
- readonly description: "App ID (defaults to the current app)";
14
+ readonly description: "App ID (alternative to app; defaults to the current app)";
11
15
  };
12
16
  };
13
17
  readonly additionalProperties: false;
@@ -1 +1 @@
1
- {"version":3,"file":"getFixSummary.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/getFixSummary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAgBpB,CAAC;AASX,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAuEpF"}
1
+ {"version":3,"file":"getFixSummary.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/getFixSummary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAM1D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAgBpB,CAAC;AAaX,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAgEpF"}
@@ -1,15 +1,17 @@
1
- import { getVulnerabilities } from "../../client/apiClient.js";
1
+ import { getAllVulnerabilities } from "../../client/apiClient.js";
2
+ import { APP_NAME_PROPERTY, resolveApp } from "../../utils/appResolver.js";
3
+ import { isOpen } from "../../utils/promptBuilder.js";
2
4
  export const getFixSummaryTool = {
3
5
  name: "get_fix_summary",
4
- description: "📊 Show a summary of vulnerability fix progress for the current app — how many are " +
5
- "fixed, unfixed, dismissed, broken down by severity. Use after running auto_fix / auto_fix_all " +
6
- "to verify progress.",
6
+ description: "📊 Show fix progress for an app — fixed, skipped as not applicable (dismissed), and still open, " +
7
+ "broken down by severity. Call it at the end of an auto_fix_all run and report its one-line counts.",
7
8
  inputSchema: {
8
9
  type: "object",
9
10
  properties: {
11
+ app: APP_NAME_PROPERTY,
10
12
  appId: {
11
13
  type: "string",
12
- description: "App ID (defaults to the current app)",
14
+ description: "App ID (alternative to app; defaults to the current app)",
13
15
  },
14
16
  },
15
17
  additionalProperties: false,
@@ -21,59 +23,56 @@ const SEVERITY_ICON = {
21
23
  medium: "🟡",
22
24
  low: "🟢",
23
25
  };
26
+ // A fix claim counts as fixed here; it is confirmed (isFixed) or dropped by the next scan.
27
+ const isFixedOrClaimed = (v) => Boolean(v.isFixed || v.fixClaimed);
28
+ const isSkipped = (v) => Boolean(v.isDismissed && !isFixedOrClaimed(v));
24
29
  export async function handleGetFixSummary(auth, args) {
25
- const appId = args?.appId ?? auth.currentAppId;
26
- if (!appId) {
27
- return {
28
- content: [{ type: "text", text: "❌ No app selected. Run register_app or select_app first." }],
29
- };
30
- }
31
30
  try {
32
- let allVulnerabilities = [];
33
- let page = 1;
34
- const pageSize = 100;
35
- while (true) {
36
- const result = await getVulnerabilities(auth, appId, { page, pageSize });
37
- allVulnerabilities = allVulnerabilities.concat(result.data);
38
- if (allVulnerabilities.length >= result.total)
39
- break;
40
- page++;
41
- }
31
+ const resolved = await resolveApp(auth, args);
32
+ if (!resolved.ok)
33
+ return { content: [{ type: "text", text: resolved.message }] };
34
+ const { appId, label } = resolved.app;
35
+ const allVulnerabilities = await getAllVulnerabilities(auth, appId);
42
36
  const total = allVulnerabilities.length;
43
37
  if (total === 0) {
44
- return { content: [{ type: "text", text: "No vulnerabilities found for this app." }] };
38
+ return { content: [{ type: "text", text: `No vulnerabilities found for "${label}".` }] };
45
39
  }
46
- const fixed = allVulnerabilities.filter(v => v.isFixed);
47
- const dismissed = allVulnerabilities.filter(v => v.isDismissed && !v.isFixed);
48
- const unfixed = allVulnerabilities.filter(v => !v.isFixed && !v.isDismissed);
40
+ const fixed = allVulnerabilities.filter(isFixedOrClaimed);
41
+ const pendingRescan = allVulnerabilities.filter(v => v.fixClaimed && !v.isFixed);
42
+ const skipped = allVulnerabilities.filter(isSkipped);
43
+ const open = allVulnerabilities.filter(isOpen);
49
44
  // Breakdown by severity
50
45
  const severities = ["critical", "high", "medium", "low"];
51
46
  const breakdownRows = severities
52
47
  .map(s => {
53
48
  const icon = SEVERITY_ICON[s] ?? "⚪";
54
49
  const all = allVulnerabilities.filter(v => (v.severity ?? "").toLowerCase() === s);
55
- const f = all.filter(v => v.isFixed).length;
56
- const d = all.filter(v => v.isDismissed && !v.isFixed).length;
57
- const u = all.filter(v => !v.isFixed && !v.isDismissed).length;
58
50
  if (all.length === 0)
59
51
  return null;
60
- return `| ${icon} ${s.charAt(0).toUpperCase() + s.slice(1)} | ${all.length} | ${f} | ${u} | ${d} |`;
52
+ const f = all.filter(isFixedOrClaimed).length;
53
+ const d = all.filter(isSkipped).length;
54
+ const o = all.filter(isOpen).length;
55
+ return `| ${icon} ${s.charAt(0).toUpperCase() + s.slice(1)} | ${all.length} | ${f} | ${d} | ${o} |`;
61
56
  })
62
57
  .filter(Boolean)
63
58
  .join("\n");
64
- const pct = total > 0 ? Math.round((fixed.length / total) * 100) : 0;
59
+ const pct = Math.round((fixed.length / total) * 100);
65
60
  const progressBar = "█".repeat(Math.round(pct / 5)) + "░".repeat(20 - Math.round(pct / 5));
66
- let summary = `# Fix Progress: ${auth.currentAppUrl ?? appId}\n\n`;
61
+ let summary = `# Fix Progress: ${label}\n\n`;
62
+ summary += `**${fixed.length} fixed, ${skipped.length} skipped as not applicable, ${open.length} still open.**\n\n`;
67
63
  summary += `\`${progressBar}\` **${pct}%** (${fixed.length}/${total} fixed)\n\n`;
68
- summary += `| Severity | Total | Fixed | Unfixed | Dismissed |\n`;
64
+ summary += `| Severity | Total | Fixed | Skipped | Open |\n`;
69
65
  summary += `| --- | --- | --- | --- | --- |\n`;
70
66
  summary += breakdownRows + "\n";
71
- summary += `| **Total** | **${total}** | **${fixed.length}** | **${unfixed.length}** | **${dismissed.length}** |\n\n`;
72
- if (unfixed.length > 0) {
73
- summary += `**${unfixed.length} vulnerabilities still need fixing.** Run \`auto_fix_all\` to get fix instructions for all remaining issues.\n`;
67
+ summary += `| **Total** | **${total}** | **${fixed.length}** | **${skipped.length}** | **${open.length}** |\n\n`;
68
+ if (pendingRescan.length > 0) {
69
+ summary += `${pendingRescan.length} of the fixed are claimed fixes — the next security test confirms them.\n`;
70
+ }
71
+ if (open.length > 0) {
72
+ summary += `**${open.length} vulnerabilities still need fixing.** Run \`auto_fix_all\` to continue.\n`;
74
73
  }
75
74
  else {
76
- summary += `✅ **All vulnerabilities are resolved!**\n`;
75
+ summary += `✅ **Nothing left to fix.**\n`;
77
76
  }
78
77
  return { content: [{ type: "text", text: summary }] };
79
78
  }
@@ -5,9 +5,13 @@ export declare const getVulnerabilitiesTool: {
5
5
  readonly inputSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {
8
+ readonly app: {
9
+ readonly type: "string";
10
+ readonly description: string;
11
+ };
8
12
  readonly appId: {
9
13
  readonly type: "string";
10
- readonly description: "App ID (defaults to the current app)";
14
+ readonly description: "App ID (alternative to app; defaults to the current app)";
11
15
  };
12
16
  readonly search: {
13
17
  readonly type: "string";
@@ -1 +1 @@
1
- {"version":3,"file":"getVulnerabilities.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/getVulnerabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;CAezB,CAAC;AAEX,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAyBzF"}
1
+ {"version":3,"file":"getVulnerabilities.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/getVulnerabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAK1D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBzB,CAAC;AAEX,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAwBzF"}
@@ -1,4 +1,5 @@
1
1
  import { getVulnerabilities } from "../../client/apiClient.js";
2
+ import { APP_NAME_PROPERTY, resolveApp } from "../../utils/appResolver.js";
2
3
  import { formatVulnerabilityList } from "../../utils/formatters.js";
3
4
  export const getVulnerabilitiesTool = {
4
5
  name: "get_vulnerabilities",
@@ -7,7 +8,8 @@ export const getVulnerabilitiesTool = {
7
8
  inputSchema: {
8
9
  type: "object",
9
10
  properties: {
10
- appId: { type: "string", description: "App ID (defaults to the current app)" },
11
+ app: APP_NAME_PROPERTY,
12
+ appId: { type: "string", description: "App ID (alternative to app; defaults to the current app)" },
11
13
  search: { type: "string", description: "Case-insensitive keyword search" },
12
14
  page: { type: "number", description: "Page number (default 1)" },
13
15
  pageSize: { type: "number", description: "Results per page, 1-100 (default 20)" },
@@ -16,11 +18,11 @@ export const getVulnerabilitiesTool = {
16
18
  },
17
19
  };
18
20
  export async function handleGetVulnerabilities(auth, args) {
19
- const appId = args?.appId ?? auth.currentAppId;
20
- if (!appId) {
21
- return { content: [{ type: "text", text: "❌ No app selected. Run register_app or select_app first." }] };
22
- }
23
21
  try {
22
+ const resolved = await resolveApp(auth, args);
23
+ if (!resolved.ok)
24
+ return { content: [{ type: "text", text: resolved.message }] };
25
+ const { appId } = resolved.app;
24
26
  const result = await getVulnerabilities(auth, appId, {
25
27
  page: args?.page,
26
28
  pageSize: args?.pageSize,
@@ -1,7 +1,7 @@
1
1
  import { AuthManager } from "../../client/authManager.js";
2
2
  export declare const listAppsTool: {
3
3
  readonly name: "list_apps";
4
- readonly description: "📋 List previously registered apps (GET /v1/apps). Supports search + pagination.";
4
+ readonly description: string;
5
5
  readonly inputSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {
@@ -1 +1 @@
1
- {"version":3,"file":"listApps.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/listApps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;CAYf,CAAC;AAEX,wBAAsB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAe/E"}
1
+ {"version":3,"file":"listApps.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/listApps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;CAcf,CAAC;AAEX,wBAAsB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAe/E"}
@@ -2,7 +2,8 @@ import { listApps } from "../../client/apiClient.js";
2
2
  import { formatAppList } from "../../utils/formatters.js";
3
3
  export const listAppsTool = {
4
4
  name: "list_apps",
5
- description: "📋 List previously registered apps (GET /v1/apps). Supports search + pagination.",
5
+ description: "📋 Browse registered apps (GET /v1/apps). Not a prerequisite: the fix and scan tools take an app " +
6
+ "name directly (app: \"Bookstore\"). Use this only when the user asks to see their apps.",
6
7
  inputSchema: {
7
8
  type: "object",
8
9
  properties: {
@@ -1,7 +1,7 @@
1
1
  import { AuthManager } from "../../client/authManager.js";
2
2
  export declare const logoutTool: {
3
3
  readonly name: "logout";
4
- readonly description: "🚪 Clear the current PerfAI session and selected app/task state.";
4
+ readonly description: "🚪 Clear the current Perfai session and selected app/task state.";
5
5
  readonly inputSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {};
@@ -1,6 +1,6 @@
1
1
  export const logoutTool = {
2
2
  name: "logout",
3
- description: "🚪 Clear the current PerfAI session and selected app/task state.",
3
+ description: "🚪 Clear the current Perfai session and selected app/task state.",
4
4
  inputSchema: { type: "object", properties: {}, additionalProperties: false },
5
5
  };
6
6
  export async function handleLogout(auth) {
@@ -0,0 +1,26 @@
1
+ import { AuthManager } from "../../client/authManager.js";
2
+ export declare const manageOrganizationsTool: {
3
+ readonly name: "manage_organizations";
4
+ readonly description: string;
5
+ readonly inputSchema: {
6
+ readonly type: "object";
7
+ readonly properties: {
8
+ readonly action: {
9
+ readonly type: "string";
10
+ readonly enum: readonly ["list", "select", "refresh"];
11
+ readonly description: string;
12
+ };
13
+ readonly sequence: {
14
+ readonly type: "number";
15
+ readonly description: "Sequence number from the list output (use instead of org_id)";
16
+ };
17
+ readonly org_id: {
18
+ readonly type: "string";
19
+ readonly description: "Organization ID to select directly";
20
+ };
21
+ };
22
+ readonly additionalProperties: false;
23
+ };
24
+ };
25
+ export declare function handleManageOrganizations(auth: AuthManager, args: any): Promise<any>;
26
+ //# sourceMappingURL=manageOrganizations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manageOrganizations.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/manageOrganizations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAK1D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;CA4B1B,CAAC;AAUX,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAwG1F"}
@@ -0,0 +1,131 @@
1
+ import { getUserOrganizations } from "../../client/apiClient.js";
2
+ import { formatOrganizations } from "../../utils/formatters.js";
3
+ export const manageOrganizationsTool = {
4
+ name: "manage_organizations",
5
+ description: "🏢 List and switch between organizations (tenants) this account belongs to. Not needed before " +
6
+ "fixing or scanning: tools that take an app name search every org and select the right one " +
7
+ "automatically. Use this only when the user asks about orgs, or before register_app / list_apps " +
8
+ "in a non-default org. Use action=select with sequence (number from the list) or org_id.",
9
+ inputSchema: {
10
+ type: "object",
11
+ properties: {
12
+ action: {
13
+ type: "string",
14
+ enum: ["list", "select", "refresh"],
15
+ description: "list (default): show orgs, fetching them first if not cached yet. " +
16
+ "select: choose org by sequence or org_id. refresh: re-fetch orgs from the API.",
17
+ },
18
+ sequence: {
19
+ type: "number",
20
+ description: "Sequence number from the list output (use instead of org_id)",
21
+ },
22
+ org_id: {
23
+ type: "string",
24
+ description: "Organization ID to select directly",
25
+ },
26
+ },
27
+ additionalProperties: false,
28
+ },
29
+ };
30
+ async function fetchAndCacheOrganizations(auth) {
31
+ const data = await getUserOrganizations(auth);
32
+ const organizations = data?.data?.userOrgs ?? [];
33
+ const currentOrgId = data?.data?.currentOrg;
34
+ auth.setOrganizations(organizations, currentOrgId);
35
+ return organizations;
36
+ }
37
+ export async function handleManageOrganizations(auth, args) {
38
+ const action = args?.action ?? "list";
39
+ try {
40
+ if (action === "refresh") {
41
+ const organizations = await fetchAndCacheOrganizations(auth);
42
+ return {
43
+ content: [
44
+ {
45
+ type: "text",
46
+ text: `🔄 Refreshed — found ${organizations.length} organization${organizations.length === 1 ? "" : "s"}.\n\n` +
47
+ formatOrganizations(organizations, auth.getSelectedOrgId()),
48
+ },
49
+ ],
50
+ };
51
+ }
52
+ if (action === "select") {
53
+ const sequence = args?.sequence;
54
+ const orgId = args?.org_id;
55
+ if (!sequence && !orgId) {
56
+ return {
57
+ content: [
58
+ {
59
+ type: "text",
60
+ text: `❌ Provide a sequence number or org_id when using action=select.\n\n` +
61
+ `**Examples**:\n` +
62
+ `• \`manage_organizations {"action": "select", "sequence": 1}\`\n` +
63
+ `• \`manage_organizations {"action": "select", "org_id": "<id>"}\`\n\n` +
64
+ `Run \`manage_organizations\` first to see the list.`,
65
+ },
66
+ ],
67
+ };
68
+ }
69
+ let organizations = auth.getOrganizations();
70
+ if (organizations.length === 0) {
71
+ organizations = await fetchAndCacheOrganizations(auth);
72
+ }
73
+ let selectedOrg;
74
+ if (sequence) {
75
+ selectedOrg = organizations[sequence - 1];
76
+ if (!selectedOrg) {
77
+ return {
78
+ content: [
79
+ {
80
+ type: "text",
81
+ text: `❌ Sequence '${sequence}' not found (${organizations.length} org${organizations.length !== 1 ? "s" : ""} available).\n\n` +
82
+ `Run \`manage_organizations\` to see the list.`,
83
+ },
84
+ ],
85
+ };
86
+ }
87
+ }
88
+ else {
89
+ selectedOrg = organizations.find((org) => org.org_id === orgId);
90
+ if (!selectedOrg) {
91
+ return {
92
+ content: [
93
+ {
94
+ type: "text",
95
+ text: `❌ Organization '${orgId}' not found in the cached list.\n\n` +
96
+ `Run \`manage_organizations {"action": "refresh"}\` to update it.`,
97
+ },
98
+ ],
99
+ };
100
+ }
101
+ }
102
+ auth.setSelectedOrgId(selectedOrg.org_id);
103
+ const name = selectedOrg.orgDetails?.name ?? selectedOrg.name ?? selectedOrg.org_id;
104
+ return {
105
+ content: [
106
+ {
107
+ type: "text",
108
+ text: `✅ Organization selected: **${name}** (${selectedOrg.org_id})\n\n` +
109
+ `list_apps / select_app / register_app are now scoped to this org.`,
110
+ },
111
+ ],
112
+ };
113
+ }
114
+ // Default action: list (fetch first if nothing cached yet)
115
+ let organizations = auth.getOrganizations();
116
+ if (organizations.length === 0) {
117
+ organizations = await fetchAndCacheOrganizations(auth);
118
+ }
119
+ return { content: [{ type: "text", text: formatOrganizations(organizations, auth.getSelectedOrgId()) }] };
120
+ }
121
+ catch (error) {
122
+ return {
123
+ content: [
124
+ {
125
+ type: "text",
126
+ text: `❌ Organization management failed: ${error instanceof Error ? error.message : String(error)}`,
127
+ },
128
+ ],
129
+ };
130
+ }
131
+ }
@@ -11,7 +11,7 @@ export declare const registerAppTool: {
11
11
  };
12
12
  readonly createTestAccounts: {
13
13
  readonly type: "boolean";
14
- readonly description: "Let PerfAI auto sign-up test accounts during onboarding (default: true)";
14
+ readonly description: "Let Perfai auto sign-up test accounts during onboarding (default: true)";
15
15
  };
16
16
  readonly skipEndpoints: {
17
17
  readonly type: "array";