perfai-cloud-mcp 0.1.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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +243 -0
  3. package/dist/auth/oauthFlow.d.ts +23 -0
  4. package/dist/auth/oauthFlow.d.ts.map +1 -0
  5. package/dist/auth/oauthFlow.js +174 -0
  6. package/dist/auth/pkce.d.ts +11 -0
  7. package/dist/auth/pkce.d.ts.map +1 -0
  8. package/dist/auth/pkce.js +17 -0
  9. package/dist/auth/tokenValidator.d.ts +40 -0
  10. package/dist/auth/tokenValidator.d.ts.map +1 -0
  11. package/dist/auth/tokenValidator.js +117 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +387 -0
  15. package/dist/client/apiClient.d.ts +27 -0
  16. package/dist/client/apiClient.d.ts.map +1 -0
  17. package/dist/client/apiClient.js +81 -0
  18. package/dist/client/authManager.d.ts +42 -0
  19. package/dist/client/authManager.d.ts.map +1 -0
  20. package/dist/client/authManager.js +136 -0
  21. package/dist/client/errors.d.ts +10 -0
  22. package/dist/client/errors.d.ts.map +1 -0
  23. package/dist/client/errors.js +29 -0
  24. package/dist/client/types.d.ts +54 -0
  25. package/dist/client/types.d.ts.map +1 -0
  26. package/dist/client/types.js +1 -0
  27. package/dist/config.d.ts +23 -0
  28. package/dist/config.d.ts.map +1 -0
  29. package/dist/config.js +50 -0
  30. package/dist/env.d.ts +2 -0
  31. package/dist/env.d.ts.map +1 -0
  32. package/dist/env.js +8 -0
  33. package/dist/log-guard.d.ts +2 -0
  34. package/dist/log-guard.d.ts.map +1 -0
  35. package/dist/log-guard.js +17 -0
  36. package/dist/server.d.ts +4 -0
  37. package/dist/server.d.ts.map +1 -0
  38. package/dist/server.js +370 -0
  39. package/dist/tools/index.d.ts +352 -0
  40. package/dist/tools/index.d.ts.map +1 -0
  41. package/dist/tools/index.js +39 -0
  42. package/dist/tools/protected/autoFix.d.ts +22 -0
  43. package/dist/tools/protected/autoFix.d.ts.map +1 -0
  44. package/dist/tools/protected/autoFix.js +64 -0
  45. package/dist/tools/protected/autoFixAll.d.ts +26 -0
  46. package/dist/tools/protected/autoFixAll.d.ts.map +1 -0
  47. package/dist/tools/protected/autoFixAll.js +79 -0
  48. package/dist/tools/protected/checkAppStatus.d.ts +21 -0
  49. package/dist/tools/protected/checkAppStatus.d.ts.map +1 -0
  50. package/dist/tools/protected/checkAppStatus.js +57 -0
  51. package/dist/tools/protected/checkTaskStatus.d.ts +21 -0
  52. package/dist/tools/protected/checkTaskStatus.d.ts.map +1 -0
  53. package/dist/tools/protected/checkTaskStatus.js +53 -0
  54. package/dist/tools/protected/getFixSummary.d.ts +17 -0
  55. package/dist/tools/protected/getFixSummary.d.ts.map +1 -0
  56. package/dist/tools/protected/getFixSummary.js +90 -0
  57. package/dist/tools/protected/getVulnerabilities.d.ts +29 -0
  58. package/dist/tools/protected/getVulnerabilities.d.ts.map +1 -0
  59. package/dist/tools/protected/getVulnerabilities.js +41 -0
  60. package/dist/tools/protected/listApps.d.ts +25 -0
  61. package/dist/tools/protected/listApps.d.ts.map +1 -0
  62. package/dist/tools/protected/listApps.js +32 -0
  63. package/dist/tools/protected/logout.d.ts +12 -0
  64. package/dist/tools/protected/logout.d.ts.map +1 -0
  65. package/dist/tools/protected/logout.js +9 -0
  66. package/dist/tools/protected/registerApp.d.ts +33 -0
  67. package/dist/tools/protected/registerApp.d.ts.map +1 -0
  68. package/dist/tools/protected/registerApp.js +96 -0
  69. package/dist/tools/protected/runSecurityTest.d.ts +17 -0
  70. package/dist/tools/protected/runSecurityTest.d.ts.map +1 -0
  71. package/dist/tools/protected/runSecurityTest.js +48 -0
  72. package/dist/tools/protected/selectApp.d.ts +18 -0
  73. package/dist/tools/protected/selectApp.d.ts.map +1 -0
  74. package/dist/tools/protected/selectApp.js +29 -0
  75. package/dist/tools/protected/submitAppCredentials.d.ts +22 -0
  76. package/dist/tools/protected/submitAppCredentials.d.ts.map +1 -0
  77. package/dist/tools/protected/submitAppCredentials.js +43 -0
  78. package/dist/tools/protected/suggestFix.d.ts +22 -0
  79. package/dist/tools/protected/suggestFix.d.ts.map +1 -0
  80. package/dist/tools/protected/suggestFix.js +37 -0
  81. package/dist/tools/protected/vulnerabilityActions.d.ts +62 -0
  82. package/dist/tools/protected/vulnerabilityActions.d.ts.map +1 -0
  83. package/dist/tools/protected/vulnerabilityActions.js +69 -0
  84. package/dist/tools/public/authStatus.d.ts +12 -0
  85. package/dist/tools/public/authStatus.d.ts.map +1 -0
  86. package/dist/tools/public/authStatus.js +13 -0
  87. package/dist/tools/public/login.d.ts +21 -0
  88. package/dist/tools/public/login.d.ts.map +1 -0
  89. package/dist/tools/public/login.js +305 -0
  90. package/dist/utils/formatters.d.ts +7 -0
  91. package/dist/utils/formatters.d.ts.map +1 -0
  92. package/dist/utils/formatters.js +47 -0
  93. package/dist/utils/poll.d.ts +19 -0
  94. package/dist/utils/poll.d.ts.map +1 -0
  95. package/dist/utils/poll.js +32 -0
  96. package/dist/utils/promptBuilder.d.ts +20 -0
  97. package/dist/utils/promptBuilder.d.ts.map +1 -0
  98. package/dist/utils/promptBuilder.js +131 -0
  99. package/package.json +55 -0
@@ -0,0 +1,136 @@
1
+ import axios from "axios";
2
+ import { AUTH_TOKEN_URL, PERFAI_EMAIL, PERFAI_PASSWORD, PERFAI_TOKEN } from "../config.js";
3
+ import { formatApiError } from "./errors.js";
4
+ /**
5
+ * Holds the auth token plus the small amount of "current selection" state
6
+ * (app / task / cached vulnerability sequence numbers) that lets tools refer
7
+ * to things by short-lived sequence numbers instead of raw IDs, matching the
8
+ * UX of listing something then acting on "#3".
9
+ */
10
+ export class AuthManager {
11
+ email = PERFAI_EMAIL;
12
+ password = PERFAI_PASSWORD;
13
+ idToken;
14
+ authenticatedEmail;
15
+ authMethod = "none";
16
+ currentAppId;
17
+ currentAppUrl;
18
+ currentTaskId;
19
+ vulnCache = new Map();
20
+ vulnCacheAppId;
21
+ constructor() {
22
+ // Auto-load PERFAI_TOKEN if set (headless fallback for Replit/Lovable/Bolt).
23
+ // This takes priority over email/password since it's an existing, validated token.
24
+ if (PERFAI_TOKEN) {
25
+ this.setToken(PERFAI_TOKEN);
26
+ console.error("Loaded PERFAI_TOKEN from environment (headless token auth).");
27
+ }
28
+ }
29
+ hasCredentials() {
30
+ return Boolean(this.email && this.password);
31
+ }
32
+ setCredentials(email, password) {
33
+ this.email = email;
34
+ this.password = password;
35
+ }
36
+ /**
37
+ * Accept a pre-existing id_token directly — no email/password exchange.
38
+ * Used by: PERFAI_TOKEN env var, OAuth PKCE browser flow, HTTP bearer auth.
39
+ */
40
+ setToken(token, email, method = "token") {
41
+ this.idToken = token;
42
+ this.authMethod = method;
43
+ if (email) {
44
+ this.authenticatedEmail = email;
45
+ }
46
+ else {
47
+ // Try to extract email from JWT payload
48
+ try {
49
+ const payload = JSON.parse(Buffer.from(token.split(".")[1], "base64url").toString());
50
+ this.authenticatedEmail = payload.email ?? payload.sub;
51
+ }
52
+ catch { /* non-JWT or malformed — that's fine */ }
53
+ }
54
+ }
55
+ isAuthenticated() {
56
+ return Boolean(this.idToken);
57
+ }
58
+ getToken() {
59
+ return this.idToken;
60
+ }
61
+ getAuthenticatedEmail() {
62
+ return this.authenticatedEmail;
63
+ }
64
+ getAuthMethod() {
65
+ return this.authMethod;
66
+ }
67
+ async login(email, password) {
68
+ const useEmail = email ?? this.email;
69
+ const usePassword = password ?? this.password;
70
+ if (!useEmail || !usePassword) {
71
+ throw new Error("No credentials available. Pass email/password to the login tool, " +
72
+ "set PERFAI_EMAIL / PERFAI_PASSWORD, or set PERFAI_TOKEN.");
73
+ }
74
+ try {
75
+ const response = await axios.post(AUTH_TOKEN_URL, { username: useEmail, password: usePassword }, { headers: { "Content-Type": "application/json" }, timeout: 30_000 });
76
+ const idToken = response.data?.id_token;
77
+ if (!idToken) {
78
+ throw new Error(`Login response did not include an id_token. Response: ${JSON.stringify(response.data)}`);
79
+ }
80
+ this.idToken = idToken;
81
+ this.email = useEmail;
82
+ this.password = usePassword;
83
+ this.authenticatedEmail = useEmail;
84
+ this.authMethod = "credentials";
85
+ console.error(`Authenticated as ${useEmail}`);
86
+ return idToken;
87
+ }
88
+ catch (error) {
89
+ if (axios.isAxiosError(error)) {
90
+ console.error(`Login failed for ${useEmail}:`, error.response?.status, error.response?.data);
91
+ throw new Error(formatApiError(error));
92
+ }
93
+ throw error;
94
+ }
95
+ }
96
+ logout() {
97
+ this.idToken = undefined;
98
+ this.authenticatedEmail = undefined;
99
+ this.authMethod = "none";
100
+ this.currentAppId = undefined;
101
+ this.currentAppUrl = undefined;
102
+ this.currentTaskId = undefined;
103
+ this.vulnCache.clear();
104
+ this.vulnCacheAppId = undefined;
105
+ }
106
+ setCurrentApp(appId, appUrl) {
107
+ this.currentAppId = appId;
108
+ this.currentAppUrl = appUrl;
109
+ }
110
+ /** Caches a vulnerability page (keyed by 1-based sequence number) so tools can refer to "#3". */
111
+ cacheVulnerabilities(appId, vulnerabilities) {
112
+ this.vulnCache.clear();
113
+ this.vulnCacheAppId = appId;
114
+ vulnerabilities.forEach((v, i) => this.vulnCache.set(i + 1, v));
115
+ }
116
+ /** Looks up a cached vulnerability by sequence number ("3") or raw ID, if it was seen in the last listing. */
117
+ getCachedVulnerability(appId, idOrSequence) {
118
+ if (this.vulnCacheAppId !== appId)
119
+ return undefined;
120
+ const asNumber = Number(idOrSequence);
121
+ if (Number.isInteger(asNumber) && asNumber > 0 && this.vulnCache.has(asNumber)) {
122
+ return this.vulnCache.get(asNumber);
123
+ }
124
+ for (const v of this.vulnCache.values()) {
125
+ if (String(v.id ?? v._id) === idOrSequence)
126
+ return v;
127
+ }
128
+ return undefined;
129
+ }
130
+ /** Resolves a raw vulnerability ID or a cached sequence number ("3") to an ID. */
131
+ resolveVulnerabilityId(appId, idOrSequence) {
132
+ const cached = this.getCachedVulnerability(appId, idOrSequence);
133
+ const id = cached?.id ?? cached?._id;
134
+ return id ? String(id) : idOrSequence;
135
+ }
136
+ }
@@ -0,0 +1,10 @@
1
+ import type { AxiosError } from "axios";
2
+ /** An API failure that preserves the status + RFC 9457 Problem Details body, so callers can react to specific fields (e.g. an existing appId on a 409). */
3
+ export declare class ApiError extends Error {
4
+ readonly status: number | undefined;
5
+ readonly data: Record<string, unknown> | undefined;
6
+ constructor(message: string, status: number | undefined, data: Record<string, unknown> | undefined);
7
+ }
8
+ /** Formats an axios error whose body follows RFC 9457 Problem Details into a readable message. */
9
+ export declare function formatApiError(error: AxiosError): string;
10
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAExC,2JAA2J;AAC3J,qBAAa,QAAS,SAAQ,KAAK;aAGf,MAAM,EAAE,MAAM,GAAG,SAAS;aAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;gBAFzD,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;CAK5D;AAED,kGAAkG;AAClG,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAqBxD"}
@@ -0,0 +1,29 @@
1
+ /** An API failure that preserves the status + RFC 9457 Problem Details body, so callers can react to specific fields (e.g. an existing appId on a 409). */
2
+ export class ApiError extends Error {
3
+ status;
4
+ data;
5
+ constructor(message, status, data) {
6
+ super(message);
7
+ this.status = status;
8
+ this.data = data;
9
+ this.name = "ApiError";
10
+ }
11
+ }
12
+ /** Formats an axios error whose body follows RFC 9457 Problem Details into a readable message. */
13
+ export function formatApiError(error) {
14
+ const status = error.response?.status;
15
+ const data = error.response?.data;
16
+ if (status === 429) {
17
+ const retryAfter = error.response?.headers?.["retry-after"];
18
+ return `Rate limited (429)${retryAfter ? ` — retry after ${retryAfter}s` : ""}: ${data?.title ?? "Too many requests"}`;
19
+ }
20
+ if (data && typeof data === "object" && ("title" in data || "type" in data)) {
21
+ const title = data.title ?? "Request failed";
22
+ const extra = Object.entries(data)
23
+ .filter(([k]) => !["type", "title", "status"].includes(k))
24
+ .map(([k, v]) => `${k}: ${typeof v === "string" ? v : JSON.stringify(v)}`)
25
+ .join(", ");
26
+ return `[${status ?? "?"}] ${title}${extra ? ` (${extra})` : ""}`;
27
+ }
28
+ return `[${status ?? "?"}] ${error.message}`;
29
+ }
@@ -0,0 +1,54 @@
1
+ export interface ProblemDetails {
2
+ type?: string;
3
+ title?: string;
4
+ status?: number;
5
+ [key: string]: unknown;
6
+ }
7
+ export interface AppRecord {
8
+ appId: string;
9
+ appUrl?: string;
10
+ label?: string;
11
+ name?: string;
12
+ registrationStatus?: string;
13
+ statusUrl?: string;
14
+ [key: string]: unknown;
15
+ }
16
+ export interface AppListResponse {
17
+ total: number;
18
+ page: number;
19
+ pageSize: number;
20
+ data: AppRecord[];
21
+ }
22
+ export interface TaskRecord {
23
+ taskId: string;
24
+ state?: string;
25
+ statusUrl?: string;
26
+ [key: string]: unknown;
27
+ }
28
+ export interface VulnerabilityRecord {
29
+ id?: string;
30
+ _id?: string;
31
+ severity?: string;
32
+ isFixed?: boolean;
33
+ isDismissed?: boolean;
34
+ title?: string;
35
+ label?: string;
36
+ category?: string;
37
+ description?: string;
38
+ remediation?: string;
39
+ recommendation?: string;
40
+ method?: string;
41
+ path?: string;
42
+ [key: string]: unknown;
43
+ }
44
+ export interface VulnerabilityListResponse {
45
+ total: number;
46
+ page: number;
47
+ pageSize: number;
48
+ data: VulnerabilityRecord[];
49
+ }
50
+ export interface Credentials {
51
+ email: string;
52
+ password: string;
53
+ }
54
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,SAAS,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,mBAAmB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ export declare const SERVER_INFO: {
2
+ name: string;
3
+ version: string;
4
+ };
5
+ export declare const AUTH_TOKEN_URL: string;
6
+ export declare const API_BASE_URL: string;
7
+ export declare const PERFAI_EMAIL: string | undefined;
8
+ export declare const PERFAI_PASSWORD: string | undefined;
9
+ export declare const PERFAI_TOKEN: string | undefined;
10
+ export declare const AUTH0_DOMAIN: string;
11
+ export declare const AUTH0_CLIENT_ID: string;
12
+ export declare const AUTH0_AUDIENCE: string;
13
+ export declare const OAUTH_CALLBACK_PORT: number;
14
+ export declare const OAUTH_SCOPES: string;
15
+ export declare const POLL_START_MS = 5000;
16
+ export declare const POLL_MAX_INTERVAL_MS = 60000;
17
+ export declare const POLL_TASK_TIMEOUT_MS: number;
18
+ export declare const POLL_REGISTRATION_TIMEOUT_MS: number;
19
+ export declare const DEFAULT_TOOL_POLL_BUDGET_MS = 8000;
20
+ export declare const MAX_TOOL_POLL_BUDGET_MS = 240000;
21
+ export declare const TASK_TERMINAL_STATES: Set<string>;
22
+ export declare const APP_TERMINAL_STATES: Set<string>;
23
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;CAGvB,CAAC;AAOF,eAAO,MAAM,cAAc,QAA0C,CAAC;AACtE,eAAO,MAAM,YAAY,QAA2B,CAAC;AAGrD,eAAO,MAAM,YAAY,oBAA2B,CAAC;AACrD,eAAO,MAAM,eAAe,oBAA8B,CAAC;AAI3D,eAAO,MAAM,YAAY,oBAA2B,CAAC;AAKrD,eAAO,MAAM,YAAY,QAA+C,CAAC;AACzE,eAAO,MAAM,eAAe,QAAoE,CAAC;AACjG,eAAO,MAAM,cAAc,QAAmC,CAAC;AAC/D,eAAO,MAAM,mBAAmB,QAA0D,CAAC;AAC3F,eAAO,MAAM,YAAY,QAAoE,CAAC;AAI9F,eAAO,MAAM,aAAa,OAAQ,CAAC;AACnC,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,eAAO,MAAM,oBAAoB,QAAiB,CAAC;AACnD,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAS3D,eAAO,MAAM,2BAA2B,OAAQ,CAAC;AACjD,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAE/C,eAAO,MAAM,oBAAoB,aAK/B,CAAC;AAEH,eAAO,MAAM,mBAAmB,aAG9B,CAAC"}
package/dist/config.js ADDED
@@ -0,0 +1,50 @@
1
+ // Server identity reported to MCP clients.
2
+ export const SERVER_INFO = {
3
+ name: "perfai-cloud-mcp",
4
+ version: "0.1.0",
5
+ };
6
+ // Host for the hosted PerfAI cloud API. Override for on-premise deployments.
7
+ const API_HOST = process.env.PERFAI_API_HOST || "api.perfai.ai";
8
+ // Per docs.perfai.ai/docs/api/overview: token exchange lives under /api/v1,
9
+ // everything else (apps, tasks, vulnerabilities) lives under /v1.
10
+ export const AUTH_TOKEN_URL = `https://${API_HOST}/api/v1/auth/token`;
11
+ export const API_BASE_URL = `https://${API_HOST}/v1`;
12
+ // Credentials for non-interactive login (recommended for MCP client configs).
13
+ export const PERFAI_EMAIL = process.env.PERFAI_EMAIL;
14
+ export const PERFAI_PASSWORD = process.env.PERFAI_PASSWORD;
15
+ // Pre-existing token for headless environments (Replit, Lovable, Bolt, CI).
16
+ // Users copy this from the PerfAI console after a normal browser login.
17
+ export const PERFAI_TOKEN = process.env.PERFAI_TOKEN;
18
+ // ── OAuth / Auth0 PKCE configuration ───────────────────────────────
19
+ // Used for the browser-based login flow (Cursor, Claude Code, VS Code, etc.).
20
+ // The PKCE flow produces the same id_token that PerfAI's API already accepts.
21
+ export const AUTH0_DOMAIN = process.env.AUTH0_DOMAIN ?? "auth.perfai.ai";
22
+ export const AUTH0_CLIENT_ID = process.env.AUTH0_CLIENT_ID ?? "OxipoJS8EIdpN3KzhVQ280zkKxwzGLfI";
23
+ export const AUTH0_AUDIENCE = process.env.AUTH0_AUDIENCE ?? "";
24
+ export const OAUTH_CALLBACK_PORT = parseInt(process.env.OAUTH_CALLBACK_PORT ?? "5173", 10);
25
+ export const OAUTH_SCOPES = process.env.OAUTH_SCOPES ?? "openid profile email offline_access";
26
+ // Polling guidance from the API docs: start at 5s, exponential backoff
27
+ // capped at 60s, allow up to 30 minutes total for a security test run.
28
+ export const POLL_START_MS = 5_000;
29
+ export const POLL_MAX_INTERVAL_MS = 60_000;
30
+ export const POLL_TASK_TIMEOUT_MS = 30 * 60 * 1000;
31
+ export const POLL_REGISTRATION_TIMEOUT_MS = 30 * 60 * 1000;
32
+ // A single `check_*_status` tool call polls in-process for at most this long
33
+ // before returning the current (possibly non-terminal) state, so it never
34
+ // hangs past a calling client's own request timeout. Callers re-invoke the
35
+ // tool to keep polling — mirrors the `wait_seconds` pattern.
36
+ // Kept short by default since some MCP clients (e.g. the Inspector) use a
37
+ // client-side request timeout well under a minute; pass a larger
38
+ // wait_seconds explicitly if your client's timeout is raised to allow it.
39
+ export const DEFAULT_TOOL_POLL_BUDGET_MS = 8_000;
40
+ export const MAX_TOOL_POLL_BUDGET_MS = 240_000;
41
+ export const TASK_TERMINAL_STATES = new Set([
42
+ "COMPLETED",
43
+ "FAILED",
44
+ "CANCELLED",
45
+ "INTERRUPTED",
46
+ ]);
47
+ export const APP_TERMINAL_STATES = new Set([
48
+ "COMPLETED",
49
+ "FAILED",
50
+ ]);
package/dist/env.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC"}
package/dist/env.js ADDED
@@ -0,0 +1,8 @@
1
+ // Loads .env into process.env as a side effect of importing this module.
2
+ // Must be imported before any module that reads process.env at its own
3
+ // top level (e.g. config.ts) — ES module imports are fully evaluated before
4
+ // the importing file's own statements run, so calling dotenv.config() as a
5
+ // plain statement further down in server.ts would run too late.
6
+ import dotenv from "dotenv";
7
+ // dotenvx v17 writes to stdout by default, which would corrupt MCP stdio.
8
+ dotenv.config({ quiet: true });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=log-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-guard.d.ts","sourceRoot":"","sources":["../src/log-guard.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ // MCP stdio transport requires that stdout carry ONLY JSON-RPC messages.
2
+ // Any stray write to stdout (e.g. a dependency's banner/tips, a stray
3
+ // console.log) corrupts the stream and the client drops the connection with
4
+ // "MCP error -32000: Connection closed".
5
+ //
6
+ // This module is imported first (before any other import) so that every
7
+ // console.* call — ours or a dependency's — is redirected to stderr, leaving
8
+ // stdout exclusively for the protocol. The MCP SDK writes protocol frames via
9
+ // process.stdout.write directly, so it is unaffected by this redirect.
10
+ const toStderr = (...args) => {
11
+ console.error(...args);
12
+ };
13
+ console.log = toStderr;
14
+ console.info = toStderr;
15
+ console.debug = toStderr;
16
+ console.warn = toStderr;
17
+ export {};
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import "./log-guard.js";
3
+ import "./env.js";
4
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAGA,OAAO,gBAAgB,CAAC;AAExB,OAAO,UAAU,CAAC"}