perfai-cloud-mcp 0.2.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 (67) hide show
  1. package/README.md +31 -19
  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/client/apiClient.d.ts +6 -4
  7. package/dist/client/apiClient.d.ts.map +1 -1
  8. package/dist/client/apiClient.js +38 -9
  9. package/dist/client/authManager.d.ts +9 -0
  10. package/dist/client/authManager.d.ts.map +1 -1
  11. package/dist/client/authManager.js +21 -0
  12. package/dist/client/types.d.ts +2 -0
  13. package/dist/client/types.d.ts.map +1 -1
  14. package/dist/config.d.ts +3 -0
  15. package/dist/config.d.ts.map +1 -1
  16. package/dist/config.js +16 -0
  17. package/dist/prompts.d.ts +31 -0
  18. package/dist/prompts.d.ts.map +1 -0
  19. package/dist/prompts.js +53 -0
  20. package/dist/server.js +29 -4
  21. package/dist/tools/index.d.ts +45 -17
  22. package/dist/tools/index.d.ts.map +1 -1
  23. package/dist/tools/protected/autoFix.d.ts +5 -1
  24. package/dist/tools/protected/autoFix.d.ts.map +1 -1
  25. package/dist/tools/protected/autoFix.js +27 -12
  26. package/dist/tools/protected/autoFixAll.d.ts +6 -2
  27. package/dist/tools/protected/autoFixAll.d.ts.map +1 -1
  28. package/dist/tools/protected/autoFixAll.js +29 -32
  29. package/dist/tools/protected/getFixSummary.d.ts +5 -1
  30. package/dist/tools/protected/getFixSummary.d.ts.map +1 -1
  31. package/dist/tools/protected/getFixSummary.js +35 -36
  32. package/dist/tools/protected/getVulnerabilities.d.ts +5 -1
  33. package/dist/tools/protected/getVulnerabilities.d.ts.map +1 -1
  34. package/dist/tools/protected/getVulnerabilities.js +7 -5
  35. package/dist/tools/protected/listApps.d.ts +1 -1
  36. package/dist/tools/protected/listApps.d.ts.map +1 -1
  37. package/dist/tools/protected/listApps.js +2 -1
  38. package/dist/tools/protected/logout.d.ts +1 -1
  39. package/dist/tools/protected/logout.js +1 -1
  40. package/dist/tools/protected/manageOrganizations.d.ts.map +1 -1
  41. package/dist/tools/protected/manageOrganizations.js +4 -5
  42. package/dist/tools/protected/registerApp.d.ts +1 -1
  43. package/dist/tools/protected/registerApp.js +3 -3
  44. package/dist/tools/protected/runSecurityTest.d.ts +5 -1
  45. package/dist/tools/protected/runSecurityTest.d.ts.map +1 -1
  46. package/dist/tools/protected/runSecurityTest.js +7 -5
  47. package/dist/tools/protected/selectApp.d.ts +1 -1
  48. package/dist/tools/protected/selectApp.d.ts.map +1 -1
  49. package/dist/tools/protected/selectApp.js +3 -1
  50. package/dist/tools/protected/vulnerabilityActions.d.ts +12 -4
  51. package/dist/tools/protected/vulnerabilityActions.d.ts.map +1 -1
  52. package/dist/tools/protected/vulnerabilityActions.js +25 -6
  53. package/dist/tools/public/authStatus.d.ts +1 -1
  54. package/dist/tools/public/authStatus.js +1 -1
  55. package/dist/tools/public/login.d.ts +12 -2
  56. package/dist/tools/public/login.d.ts.map +1 -1
  57. package/dist/tools/public/login.js +78 -86
  58. package/dist/utils/appResolver.d.ts +24 -0
  59. package/dist/utils/appResolver.d.ts.map +1 -0
  60. package/dist/utils/appResolver.js +156 -0
  61. package/dist/utils/formatters.d.ts.map +1 -1
  62. package/dist/utils/formatters.js +4 -1
  63. package/dist/utils/promptBuilder.d.ts +8 -2
  64. package/dist/utils/promptBuilder.d.ts.map +1 -1
  65. package/dist/utils/promptBuilder.js +42 -26
  66. package/package.json +7 -8
  67. package/LICENSE +0 -21
@@ -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) {
@@ -1 +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;;;;;;;;;;;;;;;;;;;;;;CA6B1B,CAAC;AAUX,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAwG1F"}
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"}
@@ -2,11 +2,10 @@ import { getUserOrganizations } from "../../client/apiClient.js";
2
2
  import { formatOrganizations } from "../../utils/formatters.js";
3
3
  export const manageOrganizationsTool = {
4
4
  name: "manage_organizations",
5
- description: "🏢 List and switch between organizations (tenants) this account belongs to. " +
6
- "Needed for multi-org accounts (e.g. SuperAdmin/support) — list_apps / select_app / " +
7
- "register_app / etc. are all scoped to whichever org is currently selected, so an appId " +
8
- "belonging to a non-selected org will 404 until you select the right org here. " +
9
- "Use action=select with sequence (number from the list) or org_id.",
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.",
10
9
  inputSchema: {
11
10
  type: "object",
12
11
  properties: {
@@ -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";
@@ -3,7 +3,7 @@ import { ApiError } from "../../client/errors.js";
3
3
  import { formatApp } from "../../utils/formatters.js";
4
4
  export const registerAppTool = {
5
5
  name: "register_app",
6
- description: "📱 Register an app by its deployed URL (POST /v1/apps). PerfAI onboards it autonomously — " +
6
+ description: "📱 Register an app by its deployed URL (POST /v1/apps). Perfai onboards it autonomously — " +
7
7
  "the returned app becomes the 'current app' for subsequent tools. First onboarding can take a " +
8
8
  "while; follow up with check_app_status until registrationStatus is COMPLETED.",
9
9
  inputSchema: {
@@ -12,7 +12,7 @@ export const registerAppTool = {
12
12
  appUrl: { type: "string", description: "Fully-qualified URL of the deployed app, e.g. https://app.example.com" },
13
13
  createTestAccounts: {
14
14
  type: "boolean",
15
- description: "Let PerfAI auto sign-up test accounts during onboarding (default: true)",
15
+ description: "Let Perfai auto sign-up test accounts during onboarding (default: true)",
16
16
  },
17
17
  skipEndpoints: {
18
18
  type: "array",
@@ -65,7 +65,7 @@ export async function handleRegisterApp(auth, args) {
65
65
  };
66
66
  }
67
67
  catch (error) {
68
- // PerfAI treats appUrl as unique — a 409 here means it's already
68
+ // Perfai treats appUrl as unique — a 409 here means it's already
69
69
  // registered. Rather than just failing, pick up the existing app so the
70
70
  // rest of the workflow (check_app_status, run_security_test, ...) keeps
71
71
  // working without the caller having to copy the appId out of the error.
@@ -5,9 +5,13 @@ export declare const runSecurityTestTool: {
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":"runSecurityTest.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/runSecurityTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;CAYtB,CAAC;AAEX,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAoCtF"}
1
+ {"version":3,"file":"runSecurityTest.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/runSecurityTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;CAatB,CAAC;AAEX,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAmCtF"}
@@ -1,4 +1,5 @@
1
1
  import { getApp, runSecurityAgent } from "../../client/apiClient.js";
2
+ import { APP_NAME_PROPERTY, resolveApp } from "../../utils/appResolver.js";
2
3
  export const runSecurityTestTool = {
3
4
  name: "run_security_test",
4
5
  description: "🚀 Start a security test run (POST /v1/apps/{appId}/security-agent). Requires registrationStatus " +
@@ -6,17 +7,18 @@ export const runSecurityTestTool = {
6
7
  inputSchema: {
7
8
  type: "object",
8
9
  properties: {
9
- appId: { type: "string", description: "App ID (defaults to the current app)" },
10
+ app: APP_NAME_PROPERTY,
11
+ appId: { type: "string", description: "App ID (alternative to app; defaults to the current app)" },
10
12
  },
11
13
  additionalProperties: false,
12
14
  },
13
15
  };
14
16
  export async function handleRunSecurityTest(auth, args) {
15
- const appId = args?.appId ?? auth.currentAppId;
16
- if (!appId) {
17
- return { content: [{ type: "text", text: "❌ No app selected. Run register_app or select_app first." }] };
18
- }
19
17
  try {
18
+ const resolved = await resolveApp(auth, args);
19
+ if (!resolved.ok)
20
+ return { content: [{ type: "text", text: resolved.message }] };
21
+ const { appId } = resolved.app;
20
22
  // Pre-flight check so we can give a clearer message than the API's bare 400.
21
23
  const app = await getApp(auth, appId);
22
24
  if (app.registrationStatus !== "COMPLETED") {
@@ -1,7 +1,7 @@
1
1
  import { AuthManager } from "../../client/authManager.js";
2
2
  export declare const selectAppTool: {
3
3
  readonly name: "select_app";
4
- readonly description: "🎯 Set the 'current app' for subsequent tools (run_security_test, get_vulnerabilities, etc.) by appId.";
4
+ readonly description: string;
5
5
  readonly inputSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {
@@ -1 +1 @@
1
- {"version":3,"file":"selectApp.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/selectApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;CAWhB,CAAC;AAEX,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAahF"}
1
+ {"version":3,"file":"selectApp.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/selectApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAI1D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;CAchB,CAAC;AAEX,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAahF"}
@@ -2,7 +2,9 @@ import { getApp } from "../../client/apiClient.js";
2
2
  import { formatApp } from "../../utils/formatters.js";
3
3
  export const selectAppTool = {
4
4
  name: "select_app",
5
- description: "🎯 Set the 'current app' for subsequent tools (run_security_test, get_vulnerabilities, etc.) by appId.",
5
+ description: "🎯 Set the 'current app' by appId. Rarely needed: auto_fix_all, get_vulnerabilities, run_security_test " +
6
+ "and get_fix_summary accept an app name directly and select it automatically. Use only when the user " +
7
+ "explicitly asks to switch apps.",
6
8
  inputSchema: {
7
9
  type: "object",
8
10
  properties: {
@@ -1,10 +1,13 @@
1
1
  import { AuthManager } from "../../client/authManager.js";
2
2
  export declare const dismissVulnerabilityTool: {
3
3
  readonly name: "dismiss_vulnerability";
4
- readonly description: "🙈 Dismiss a finding as a false positive / won't-fix (POST /v1/vulnerabilities/{id}/dismiss).";
4
+ readonly description: string;
5
5
  readonly inputSchema: {
6
- readonly type: "object";
7
6
  readonly properties: {
7
+ readonly reason: {
8
+ readonly type: "string";
9
+ readonly description: string;
10
+ };
8
11
  readonly vulnerability_id: {
9
12
  readonly type: "string";
10
13
  readonly description: "Sequence number from get_vulnerabilities (e.g. '3') or raw vulnerability id";
@@ -14,6 +17,7 @@ export declare const dismissVulnerabilityTool: {
14
17
  readonly description: "App ID (defaults to the current app)";
15
18
  };
16
19
  };
20
+ readonly type: "object";
17
21
  readonly required: readonly ["vulnerability_id"];
18
22
  readonly additionalProperties: false;
19
23
  };
@@ -41,10 +45,13 @@ export declare const reopenVulnerabilityTool: {
41
45
  export declare function handleReopenVulnerability(auth: AuthManager, args: any): Promise<any>;
42
46
  export declare const markVulnerabilityFixedTool: {
43
47
  readonly name: "mark_vulnerability_fixed";
44
- readonly description: "✅ Mark a finding as fixed after applying the suggested fix (POST /v1/vulnerabilities/{id}/fix).";
48
+ readonly description: string;
45
49
  readonly inputSchema: {
46
- readonly type: "object";
47
50
  readonly properties: {
51
+ readonly comment: {
52
+ readonly type: "string";
53
+ readonly description: "Optional short note on what was changed";
54
+ };
48
55
  readonly vulnerability_id: {
49
56
  readonly type: "string";
50
57
  readonly description: "Sequence number from get_vulnerabilities (e.g. '3') or raw vulnerability id";
@@ -54,6 +61,7 @@ export declare const markVulnerabilityFixedTool: {
54
61
  readonly description: "App ID (defaults to the current app)";
55
62
  };
56
63
  };
64
+ readonly type: "object";
57
65
  readonly required: readonly ["vulnerability_id"];
58
66
  readonly additionalProperties: false;
59
67
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vulnerabilityActions.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/vulnerabilityActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAoB1D,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;CAI3B,CAAC;AAEX,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAS3F;AAED,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;CAI1B,CAAC;AAEX,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAS1F;AAED,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;CAI7B,CAAC;AAEX,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAS7F"}
1
+ {"version":3,"file":"vulnerabilityActions.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/vulnerabilityActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAoB1D,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;CAkB3B,CAAC;AAEX,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAS3F;AAED,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;CAI1B,CAAC;AAEX,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAS1F;AAED,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;CAY7B,CAAC;AAEX,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAS7F"}
@@ -18,15 +18,27 @@ const idSchema = {
18
18
  };
19
19
  export const dismissVulnerabilityTool = {
20
20
  name: "dismiss_vulnerability",
21
- description: "🙈 Dismiss a finding as a false positive / won't-fix (POST /v1/vulnerabilities/{id}/dismiss).",
22
- inputSchema: idSchema,
21
+ description: "🙈 Dismiss a finding as a false positive / won't-fix (POST /v1/vulnerabilities/{id}/dismiss). " +
22
+ "During an auto_fix_all run, call this silently for findings that do not apply to the code, with a " +
23
+ "specific reason — it is stored on the finding and used to triage false positives.",
24
+ inputSchema: {
25
+ ...idSchema,
26
+ properties: {
27
+ ...idSchema.properties,
28
+ reason: {
29
+ type: "string",
30
+ description: "Why it does not apply, based on what you saw in the code (e.g. \"not reachable from any route\", " +
31
+ "\"input is validated by the zod schema in orders.ts\"). Prefer specifics over \"false positive\".",
32
+ },
33
+ },
34
+ },
23
35
  };
24
36
  export async function handleDismissVulnerability(auth, args) {
25
37
  const resolved = resolveArgs(auth, args);
26
38
  if ("error" in resolved)
27
39
  return { content: [{ type: "text", text: `❌ ${resolved.error}` }] };
28
40
  try {
29
- await dismissVulnerability(auth, resolved.id);
41
+ await dismissVulnerability(auth, resolved.id, args?.reason);
30
42
  return { content: [{ type: "text", text: `🙈 Dismissed vulnerability ${resolved.id}.` }] };
31
43
  }
32
44
  catch (error) {
@@ -52,15 +64,22 @@ export async function handleReopenVulnerability(auth, args) {
52
64
  }
53
65
  export const markVulnerabilityFixedTool = {
54
66
  name: "mark_vulnerability_fixed",
55
- description: "✅ Mark a finding as fixed after applying the suggested fix (POST /v1/vulnerabilities/{id}/fix).",
56
- inputSchema: idSchema,
67
+ description: "✅ Claim a finding as fixed after applying the code change (POST /v1/vulnerabilities/{id}/fix). " +
68
+ "The next security test confirms the fix or reopens the finding.",
69
+ inputSchema: {
70
+ ...idSchema,
71
+ properties: {
72
+ ...idSchema.properties,
73
+ comment: { type: "string", description: "Optional short note on what was changed" },
74
+ },
75
+ },
57
76
  };
58
77
  export async function handleMarkVulnerabilityFixed(auth, args) {
59
78
  const resolved = resolveArgs(auth, args);
60
79
  if ("error" in resolved)
61
80
  return { content: [{ type: "text", text: `❌ ${resolved.error}` }] };
62
81
  try {
63
- await fixVulnerability(auth, resolved.id);
82
+ await fixVulnerability(auth, resolved.id, args?.comment);
64
83
  return { content: [{ type: "text", text: `✅ Marked vulnerability ${resolved.id} as fixed.` }] };
65
84
  }
66
85
  catch (error) {
@@ -1,7 +1,7 @@
1
1
  import { AuthManager } from "../../client/authManager.js";
2
2
  export declare const authStatusTool: {
3
3
  readonly name: "auth_status";
4
- readonly description: "🔎 Check whether the server currently holds a valid PerfAI session.";
4
+ readonly description: "🔎 Check whether the server currently holds a valid Perfai session.";
5
5
  readonly inputSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {};
@@ -1,6 +1,6 @@
1
1
  export const authStatusTool = {
2
2
  name: "auth_status",
3
- description: "🔎 Check whether the server currently holds a valid PerfAI session.",
3
+ description: "🔎 Check whether the server currently holds a valid Perfai session.",
4
4
  inputSchema: { type: "object", properties: {}, additionalProperties: false },
5
5
  };
6
6
  export async function handleAuthStatus(auth) {
@@ -7,15 +7,25 @@ export declare const loginTool: {
7
7
  readonly properties: {
8
8
  readonly email: {
9
9
  readonly type: "string";
10
- readonly description: "PerfAI account email (optional)";
10
+ readonly description: "Perfai account email (optional)";
11
11
  };
12
12
  readonly password: {
13
13
  readonly type: "string";
14
- readonly description: "PerfAI account password (optional)";
14
+ readonly description: "Perfai account password (optional)";
15
15
  };
16
16
  };
17
17
  readonly additionalProperties: false;
18
18
  };
19
19
  };
20
+ /**
21
+ * Signs in on first use so "<App> fix all" works as the very first message:
22
+ * env credentials if set, otherwise the browser sign-in (OAuth, or the local
23
+ * form when OAuth is disabled), waiting up to `waitMs` for the user to finish.
24
+ * An already-signed-in browser (Auth0 SSO) usually completes in seconds.
25
+ * The browser flow keeps running past `waitMs`, so a retry picks it up.
26
+ */
27
+ export declare function ensureLoggedIn(auth: AuthManager, waitMs?: number): Promise<boolean>;
20
28
  export declare function handleLogin(auth: AuthManager, args: any): Promise<any>;
29
+ /** Shown when the browser sign-in is still open after the wait. */
30
+ export declare const LOGIN_PENDING_TEXT: string;
21
31
  //# sourceMappingURL=login.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/tools/public/login.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;CAgBZ,CAAC;AAmNX,wBAAsB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAgG5E"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/tools/public/login.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;CAgBZ,CAAC;AAoOX;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,SAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBhG;AAQD,wBAAsB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAiC5E;AAED,mEAAmE;AACnE,eAAO,MAAM,kBAAkB,QAGyD,CAAC"}
@@ -1,10 +1,10 @@
1
1
  import { createServer } from "node:http";
2
2
  import { exec } from "node:child_process";
3
3
  import { platform } from "node:os";
4
- import { AUTH0_CLIENT_ID } from "../../config.js";
4
+ import { AUTH0_CLIENT_ID, LOGIN_WAIT_MS } from "../../config.js";
5
5
  export const loginTool = {
6
6
  name: "login",
7
- description: "Authenticate with PerfAI. " +
7
+ description: "Authenticate with Perfai. Not needed before other tools — the first tool call signs in automatically. " +
8
8
  "With no arguments: opens a browser for OAuth login (if configured) " +
9
9
  "or falls back to a simple login form. " +
10
10
  "You can also pass email/password directly, or rely on " +
@@ -12,8 +12,8 @@ export const loginTool = {
12
12
  inputSchema: {
13
13
  type: "object",
14
14
  properties: {
15
- email: { type: "string", description: "PerfAI account email (optional)" },
16
- password: { type: "string", description: "PerfAI account password (optional)" },
15
+ email: { type: "string", description: "Perfai account email (optional)" },
16
+ password: { type: "string", description: "Perfai account password (optional)" },
17
17
  },
18
18
  additionalProperties: false,
19
19
  },
@@ -35,7 +35,7 @@ const LOGIN_PAGE_HTML = `<!DOCTYPE html>
35
35
  <head>
36
36
  <meta charset="UTF-8">
37
37
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
38
- <title>PerfAI — Login</title>
38
+ <title>Perfai — Login</title>
39
39
  <style>
40
40
  * { margin: 0; padding: 0; box-sizing: border-box; }
41
41
  body {
@@ -74,7 +74,7 @@ const LOGIN_PAGE_HTML = `<!DOCTYPE html>
74
74
  <body>
75
75
  <div class="card">
76
76
  <div class="logo">
77
- <h1>PerfAI</h1>
77
+ <h1>Perfai</h1>
78
78
  <p>Sign in with your cloud.perfai.ai account</p>
79
79
  </div>
80
80
  <form id="loginForm">
@@ -192,26 +192,71 @@ function startBrowserLoginServer(auth) {
192
192
  /* ------------------------------------------------------------------ */
193
193
  /* OAuth PKCE browser flow (primary when AUTH0_CLIENT_ID is set) */
194
194
  /* ------------------------------------------------------------------ */
195
- let oauthFlowInProgress = false;
196
- async function startOAuthLogin(auth) {
197
- if (oauthFlowInProgress)
198
- return false;
199
- oauthFlowInProgress = true;
200
- try {
201
- const { startOAuthBrowserFlow } = await import("../../auth/oauthFlow.js");
202
- const tokens = await startOAuthBrowserFlow();
203
- auth.setToken(tokens.idToken, tokens.email, "oauth");
204
- console.error(`OAuth login successful: ${tokens.email ?? "unknown"}`);
195
+ // The in-flight flow, shared so a retried tool call waits on the same browser
196
+ // sign-in instead of opening a second one.
197
+ let oauthFlow = null;
198
+ function startOAuthLogin(auth) {
199
+ if (oauthFlow)
200
+ return oauthFlow;
201
+ oauthFlow = (async () => {
202
+ try {
203
+ const { startOAuthBrowserFlow } = await import("../../auth/oauthFlow.js");
204
+ const tokens = await startOAuthBrowserFlow();
205
+ auth.setToken(tokens.idToken, tokens.email, "oauth");
206
+ console.error(`OAuth login successful: ${tokens.email ?? "unknown"}`);
207
+ return true;
208
+ }
209
+ catch (err) {
210
+ console.error("OAuth flow failed:", err instanceof Error ? err.message : err);
211
+ return false;
212
+ }
213
+ finally {
214
+ oauthFlow = null;
215
+ }
216
+ })();
217
+ return oauthFlow;
218
+ }
219
+ /** Resolves true once `auth` holds a session, or false after `waitMs`. */
220
+ function waitForSession(auth, flow, waitMs) {
221
+ return new Promise((resolve) => {
222
+ const deadline = Date.now() + waitMs;
223
+ const timer = setInterval(() => {
224
+ if (auth.isAuthenticated() || Date.now() >= deadline) {
225
+ clearInterval(timer);
226
+ resolve(auth.isAuthenticated());
227
+ }
228
+ }, 500);
229
+ flow?.then(() => {
230
+ clearInterval(timer);
231
+ resolve(auth.isAuthenticated());
232
+ });
233
+ });
234
+ }
235
+ /**
236
+ * Signs in on first use so "<App> fix all" works as the very first message:
237
+ * env credentials if set, otherwise the browser sign-in (OAuth, or the local
238
+ * form when OAuth is disabled), waiting up to `waitMs` for the user to finish.
239
+ * An already-signed-in browser (Auth0 SSO) usually completes in seconds.
240
+ * The browser flow keeps running past `waitMs`, so a retry picks it up.
241
+ */
242
+ export async function ensureLoggedIn(auth, waitMs = LOGIN_WAIT_MS) {
243
+ if (auth.isAuthenticated())
205
244
  return true;
245
+ if (auth.hasCredentials()) {
246
+ try {
247
+ await auth.login();
248
+ return true;
249
+ }
250
+ catch {
251
+ // Fall through to browser login
252
+ }
206
253
  }
207
- catch (err) {
208
- console.error("OAuth flow failed:", err instanceof Error ? err.message : err);
209
- return false;
210
- }
211
- finally {
212
- oauthFlowInProgress = false;
213
- }
254
+ if (AUTH0_CLIENT_ID)
255
+ return waitForSession(auth, startOAuthLogin(auth), waitMs);
256
+ startBrowserLoginServer(auth);
257
+ return waitForSession(auth, null, waitMs);
214
258
  }
259
+ const NEXT_STEP = 'Next: tell me which app to fix, e.g. "Bookstore fix all".';
215
260
  /* ------------------------------------------------------------------ */
216
261
  /* Tool handler */
217
262
  /* ------------------------------------------------------------------ */
@@ -223,7 +268,7 @@ export async function handleLogin(auth, args) {
223
268
  {
224
269
  type: "text",
225
270
  text: `Already authenticated as ${auth.getAuthenticatedEmail()} ` +
226
- `(via ${auth.getAuthMethod()}). Run logout first to switch accounts.`,
271
+ `(via ${auth.getAuthMethod()}). Run logout first to switch accounts.\n\n${NEXT_STEP}`,
227
272
  },
228
273
  ],
229
274
  };
@@ -232,15 +277,7 @@ export async function handleLogin(auth, args) {
232
277
  if (args?.email && args?.password) {
233
278
  try {
234
279
  await auth.login(args.email, args.password);
235
- return {
236
- content: [
237
- {
238
- type: "text",
239
- text: `Authenticated as ${auth.getAuthenticatedEmail()}.\n\n` +
240
- `Next: register_app {"appUrl": "https://your-app.example.com"} to onboard an app.`,
241
- },
242
- ],
243
- };
280
+ return { content: [{ type: "text", text: `Authenticated as ${auth.getAuthenticatedEmail()}.\n\n${NEXT_STEP}` }] };
244
281
  }
245
282
  catch (error) {
246
283
  return {
@@ -248,58 +285,13 @@ export async function handleLogin(auth, args) {
248
285
  };
249
286
  }
250
287
  }
251
- // Env credentials (PERFAI_EMAIL + PERFAI_PASSWORD)
252
- if (auth.hasCredentials()) {
253
- try {
254
- await auth.login();
255
- return {
256
- content: [
257
- {
258
- type: "text",
259
- text: `Authenticated as ${auth.getAuthenticatedEmail()}.\n\n` +
260
- `Next: register_app {"appUrl": "https://your-app.example.com"} to onboard an app.`,
261
- },
262
- ],
263
- };
264
- }
265
- catch {
266
- // Fall through to browser login
267
- }
268
- }
269
- // OAuth PKCE browser flow (primary — when AUTH0_CLIENT_ID is configured)
270
- if (AUTH0_CLIENT_ID) {
271
- // Non-blocking: start the OAuth flow in the background
272
- startOAuthLogin(auth).then((success) => {
273
- if (!success) {
274
- console.error("OAuth login did not complete. User can retry with 'login'.");
275
- }
276
- });
277
- return {
278
- content: [
279
- {
280
- type: "text",
281
- text: "A browser window has been opened for PerfAI OAuth login.\n\n" +
282
- "**Sign in with your cloud.perfai.ai account in the browser.**\n\n" +
283
- "Once you see \"Authenticated!\" in the browser, come back here and call " +
284
- "the `login` tool again to confirm.\n\n" +
285
- "Alternatively, set `PERFAI_TOKEN` in your MCP server config with a token " +
286
- "copied from the PerfAI console.",
287
- },
288
- ],
289
- };
288
+ // Env credentials, else browser sign-in — waits for the user to finish.
289
+ if (await ensureLoggedIn(auth)) {
290
+ return { content: [{ type: "text", text: `Authenticated as ${auth.getAuthenticatedEmail()}.\n\n${NEXT_STEP}` }] };
290
291
  }
291
- // Fallback: simple browser login form (no OAuth configured)
292
- startBrowserLoginServer(auth);
293
- return {
294
- content: [
295
- {
296
- type: "text",
297
- text: "A browser window has been opened for PerfAI login.\n\n" +
298
- "**Please sign in with your cloud.perfai.ai credentials in the browser.**\n\n" +
299
- "Once you see \"Authenticated!\" in the browser, come back here and call the `login` tool again to confirm.\n\n" +
300
- "Tip: For a seamless experience, set `AUTH0_CLIENT_ID` in your server config to enable OAuth PKCE login, " +
301
- "or set `PERFAI_TOKEN` with a token from the PerfAI console.",
302
- },
303
- ],
304
- };
292
+ return { content: [{ type: "text", text: LOGIN_PENDING_TEXT }] };
305
293
  }
294
+ /** Shown when the browser sign-in is still open after the wait. */
295
+ export const LOGIN_PENDING_TEXT = "A browser window is open for Perfai sign-in (cloud.perfai.ai account). " +
296
+ "Once the user has signed in, call the same tool again with the same arguments — the sign-in is " +
297
+ "picked up automatically. Alternatively, set `PERFAI_TOKEN` in the MCP server config.";
@@ -0,0 +1,24 @@
1
+ import { AuthManager } from "../client/authManager.js";
2
+ export interface ResolvedApp {
3
+ appId: string;
4
+ /** Human-readable name for prompts/summaries. */
5
+ label: string;
6
+ }
7
+ export type AppResolution = {
8
+ ok: true;
9
+ app: ResolvedApp;
10
+ } | {
11
+ ok: false;
12
+ message: string;
13
+ };
14
+ /**
15
+ * Resolves which app a tool call targets: `app` (name / label / URL fragment,
16
+ * searched across every org) → `appId` → the session's current app.
17
+ */
18
+ export declare function resolveApp(auth: AuthManager, args: any): Promise<AppResolution>;
19
+ /** JSON-schema property shared by every tool that accepts an app name. */
20
+ export declare const APP_NAME_PROPERTY: {
21
+ readonly type: "string";
22
+ readonly description: string;
23
+ };
24
+ //# sourceMappingURL=appResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appResolver.d.ts","sourceRoot":"","sources":["../../src/utils/appResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AA2I5F;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,CAkBrF;AAED,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB;;;CAKpB,CAAC"}