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.
- package/README.md +31 -19
- package/dist/auth/oauthFlow.d.ts +1 -1
- package/dist/auth/oauthFlow.js +3 -3
- package/dist/auth/tokenValidator.d.ts +2 -2
- package/dist/auth/tokenValidator.js +3 -3
- package/dist/client/apiClient.d.ts +6 -4
- package/dist/client/apiClient.d.ts.map +1 -1
- package/dist/client/apiClient.js +38 -9
- package/dist/client/authManager.d.ts +9 -0
- package/dist/client/authManager.d.ts.map +1 -1
- package/dist/client/authManager.js +21 -0
- package/dist/client/types.d.ts +2 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -0
- package/dist/prompts.d.ts +31 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +53 -0
- package/dist/server.js +29 -4
- package/dist/tools/index.d.ts +45 -17
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/protected/autoFix.d.ts +5 -1
- package/dist/tools/protected/autoFix.d.ts.map +1 -1
- package/dist/tools/protected/autoFix.js +27 -12
- package/dist/tools/protected/autoFixAll.d.ts +6 -2
- package/dist/tools/protected/autoFixAll.d.ts.map +1 -1
- package/dist/tools/protected/autoFixAll.js +29 -32
- package/dist/tools/protected/getFixSummary.d.ts +5 -1
- package/dist/tools/protected/getFixSummary.d.ts.map +1 -1
- package/dist/tools/protected/getFixSummary.js +35 -36
- package/dist/tools/protected/getVulnerabilities.d.ts +5 -1
- package/dist/tools/protected/getVulnerabilities.d.ts.map +1 -1
- package/dist/tools/protected/getVulnerabilities.js +7 -5
- package/dist/tools/protected/listApps.d.ts +1 -1
- package/dist/tools/protected/listApps.d.ts.map +1 -1
- package/dist/tools/protected/listApps.js +2 -1
- package/dist/tools/protected/logout.d.ts +1 -1
- package/dist/tools/protected/logout.js +1 -1
- package/dist/tools/protected/manageOrganizations.d.ts.map +1 -1
- package/dist/tools/protected/manageOrganizations.js +4 -5
- package/dist/tools/protected/registerApp.d.ts +1 -1
- package/dist/tools/protected/registerApp.js +3 -3
- package/dist/tools/protected/runSecurityTest.d.ts +5 -1
- package/dist/tools/protected/runSecurityTest.d.ts.map +1 -1
- package/dist/tools/protected/runSecurityTest.js +7 -5
- package/dist/tools/protected/selectApp.d.ts +1 -1
- package/dist/tools/protected/selectApp.d.ts.map +1 -1
- package/dist/tools/protected/selectApp.js +3 -1
- package/dist/tools/protected/vulnerabilityActions.d.ts +12 -4
- package/dist/tools/protected/vulnerabilityActions.d.ts.map +1 -1
- package/dist/tools/protected/vulnerabilityActions.js +25 -6
- package/dist/tools/public/authStatus.d.ts +1 -1
- package/dist/tools/public/authStatus.js +1 -1
- package/dist/tools/public/login.d.ts +12 -2
- package/dist/tools/public/login.d.ts.map +1 -1
- package/dist/tools/public/login.js +78 -86
- package/dist/utils/appResolver.d.ts +24 -0
- package/dist/utils/appResolver.d.ts.map +1 -0
- package/dist/utils/appResolver.js +156 -0
- package/dist/utils/formatters.d.ts.map +1 -1
- package/dist/utils/formatters.js +4 -1
- package/dist/utils/promptBuilder.d.ts +8 -2
- package/dist/utils/promptBuilder.d.ts.map +1 -1
- package/dist/utils/promptBuilder.js +42 -26
- package/package.json +7 -8
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -19,15 +19,6 @@ auth_status # verify you're authenticated, see auth method, current a
|
|
|
19
19
|
logout # clear session
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
For cloud workspace environments, set `PERFAI_TOKEN` in the MCP server's env config instead. It's the same session token the browser/OAuth flow already produces:
|
|
23
|
-
|
|
24
|
-
1. Sign in once at [cloud.perfai.ai](https://cloud.perfai.ai) (or run the OAuth flow locally once).
|
|
25
|
-
2. Copy your `id_token` from the console, or from the `login` tool's confirmation output.
|
|
26
|
-
3. Paste it into your cloud workspace's MCP server config as `PERFAI_TOKEN`. No password ever touches that environment.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
See `.env.example` for the full token/OAuth configuration reference.
|
|
30
|
-
|
|
31
22
|
---
|
|
32
23
|
|
|
33
24
|
## Available Tools
|
|
@@ -42,7 +33,7 @@ See `.env.example` for the full token/OAuth configuration reference.
|
|
|
42
33
|
### Organization Management
|
|
43
34
|
| Tool | Description |
|
|
44
35
|
| --- | --- |
|
|
45
|
-
| `manage_organizations` | List the organizations (tenants) your account belongs to and switch between them. Actions: `list` (default), `select` (by `sequence` or `org_id`), `refresh`. |
|
|
36
|
+
| `manage_organizations` | List the organizations (tenants) your account belongs to and switch between them. Actions: `list` (default), `select` (by `sequence` or `org_id`), `refresh`. Not needed for fixing — app names are resolved across all orgs. |
|
|
46
37
|
|
|
47
38
|
|
|
48
39
|
### App Management
|
|
@@ -57,23 +48,41 @@ See `.env.example` for the full token/OAuth configuration reference.
|
|
|
57
48
|
### Security Testing
|
|
58
49
|
| Tool | Description |
|
|
59
50
|
| --- | --- |
|
|
60
|
-
| `run_security_test` | Start a security scan
|
|
51
|
+
| `run_security_test` | Start a security scan. Accepts `app` (name) or `appId`. |
|
|
61
52
|
| `check_task_status` | Poll scan progress until complete. |
|
|
62
53
|
|
|
63
54
|
### Vulnerability Management
|
|
64
55
|
| Tool | Description |
|
|
65
56
|
| --- | --- |
|
|
66
|
-
| `get_vulnerabilities` | List all findings from the latest scan. |
|
|
57
|
+
| `get_vulnerabilities` | List all findings from the latest scan. Accepts `app` (name) or `appId`. |
|
|
67
58
|
| `suggest_fix` | Get a conversational fix prompt for a specific vulnerability. |
|
|
68
|
-
| `auto_fix` | Get structured, step-by-step fix instructions for one vulnerability. |
|
|
69
|
-
| `auto_fix_all` |
|
|
70
|
-
| `get_fix_summary` |
|
|
71
|
-
| `dismiss_vulnerability` | Dismiss a finding (false positive, accepted risk, etc.). |
|
|
59
|
+
| `auto_fix` | Get structured, step-by-step fix instructions for one vulnerability. Accepts `app` (name). |
|
|
60
|
+
| `auto_fix_all` | The one-line fix. Takes `app` (name), optional `severity` / `max_fixes`; returns a prioritized plan the agent runs autonomously, 15 findings per batch. |
|
|
61
|
+
| `get_fix_summary` | Fix progress: fixed, skipped as not applicable, still open — by severity. Accepts `app` (name). |
|
|
62
|
+
| `dismiss_vulnerability` | Dismiss a finding (false positive, accepted risk, etc.) with an optional `reason`, stored on the finding. |
|
|
72
63
|
| `reopen_vulnerability` | Reopen a previously dismissed finding. |
|
|
73
|
-
| `mark_vulnerability_fixed` |
|
|
64
|
+
| `mark_vulnerability_fixed` | Claim a finding as fixed after applying the code change; the next scan confirms it. |
|
|
74
65
|
|
|
75
66
|
---
|
|
76
67
|
|
|
68
|
+
## One-line fix
|
|
69
|
+
|
|
70
|
+
Connect the server to your code agent, sign in with `login`, open the app's codebase, and type:
|
|
71
|
+
|
|
72
|
+
> **<App_name> fix all**
|
|
73
|
+
|
|
74
|
+
That's it: no listing orgs, listing apps, or selecting a project. The agent calls `auto_fix_all` with `app: "<App_name>"`; the name is resolved across every organization you belong to, the right org and app are selected, and the agent fixes every open finding from critical to low. Findings that don't apply to your code are dismissed silently with a reason, and the run ends with one line of counts.
|
|
75
|
+
|
|
76
|
+
| Say | Does |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `<App_name> fix all` | Every open finding |
|
|
79
|
+
| `<App_name> fix critical` | Only critical (also `high`, `medium`, `low`) |
|
|
80
|
+
| `<App_name> fix 1` | The single most severe open finding (`fix 5` → top 5) |
|
|
81
|
+
|
|
82
|
+
Clients that support MCP prompts also get it as a slash command — in Claude Code: `/mcp__perfai-cloud__fix_all <App_name>` or `/mcp__perfai-cloud__fix <App_name> critical` (the middle part is whatever you named the server).
|
|
83
|
+
|
|
84
|
+
You only see a list when the name is ambiguous (e.g. two apps called "Shared" in different orgs) — pick one and the run continues. An exact name wins over partial ones, so `<App_name>` is not ambiguous with `<App_name>-staging`.
|
|
85
|
+
|
|
77
86
|
## Typical Workflow
|
|
78
87
|
|
|
79
88
|
### The simple version
|
|
@@ -108,7 +117,8 @@ Here are some things you can say to your AI assistant:
|
|
|
108
117
|
| What you want | What to say |
|
|
109
118
|
| --- | --- |
|
|
110
119
|
| **Full scan** | *"Register https://api.myapp.com, run a security test, and show me all vulnerabilities."* |
|
|
111
|
-
| **Fix everything** | *"
|
|
120
|
+
| **Fix everything** | *"Bookstore fix all"* |
|
|
121
|
+
| **Fix only critical** | *"Bookstore fix critical"* |
|
|
112
122
|
| **Fix one issue** | *"Show me how to fix vulnerability #2."* |
|
|
113
123
|
| **Check progress** | *"Show me the fix summary for my app."* |
|
|
114
124
|
| **List organizations** | *"List my organizations."* |
|
|
@@ -165,6 +175,7 @@ $env:MCP_TRANSPORT="http"; node dist/server.js
|
|
|
165
175
|
| `AUTH0_AUDIENCE` | No | — | Auth0 API audience, if your tenant requires one |
|
|
166
176
|
| `OAUTH_CALLBACK_PORT` | No | `5173` | Local port the OAuth flow listens on for the Auth0 redirect |
|
|
167
177
|
| `OAUTH_SCOPES` | No | `openid profile email offline_access` | Scopes requested during OAuth login |
|
|
178
|
+
| `LOGIN_WAIT_SECONDS` | No | `90` | How long `login` waits for the browser sign-in before asking the agent to call it again. Keep it under your client's tool-call timeout |
|
|
168
179
|
| `MCP_API_KEY` | No | — | Legacy static API key (accepted alongside credential tokens) |
|
|
169
180
|
|
|
170
181
|
### Deploy with Docker
|
|
@@ -214,9 +225,10 @@ Every tool maps directly to a Perfai cloud API endpoint:
|
|
|
214
225
|
| `auto_fix` | Local prompt builder (no API call) |
|
|
215
226
|
| `auto_fix_all` | `GET /v1/apps/{appId}/vulnerabilities` + local prompt builder |
|
|
216
227
|
| `get_fix_summary` | `GET /v1/apps/{appId}/vulnerabilities` + local aggregation |
|
|
217
|
-
| `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` |
|
|
228
|
+
| `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` (`reason` → `comment`) |
|
|
218
229
|
| `reopen_vulnerability` | `POST /v1/vulnerabilities/{id}/reopen` |
|
|
219
230
|
| `mark_vulnerability_fixed` | `POST /v1/vulnerabilities/{id}/fix` |
|
|
231
|
+
| `app` name on any tool | `GET /v1/apps?search=` in the session org; on a miss, `GET /api/v1/org-users/get_users_orgs` then the same search per org with `X-Org-ID` |
|
|
220
232
|
| `auth_status` / `logout` | Local session state only (`logout` also clears the selected organization) |
|
|
221
233
|
|
|
222
234
|
---
|
package/dist/auth/oauthFlow.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface OAuthTokens {
|
|
|
17
17
|
*
|
|
18
18
|
* Reuses the existing login token — no new auth mechanism — just the
|
|
19
19
|
* standard Auth0 PKCE handshake that produces the same id_token the
|
|
20
|
-
*
|
|
20
|
+
* Perfai API already accepts.
|
|
21
21
|
*/
|
|
22
22
|
export declare function startOAuthBrowserFlow(): Promise<OAuthTokens>;
|
|
23
23
|
//# sourceMappingURL=oauthFlow.d.ts.map
|
package/dist/auth/oauthFlow.js
CHANGED
|
@@ -24,7 +24,7 @@ function openBrowser(url) {
|
|
|
24
24
|
*
|
|
25
25
|
* Reuses the existing login token — no new auth mechanism — just the
|
|
26
26
|
* standard Auth0 PKCE handshake that produces the same id_token the
|
|
27
|
-
*
|
|
27
|
+
* Perfai API already accepts.
|
|
28
28
|
*/
|
|
29
29
|
export function startOAuthBrowserFlow() {
|
|
30
30
|
return new Promise((resolve, reject) => {
|
|
@@ -48,13 +48,13 @@ export function startOAuthBrowserFlow() {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
const SUCCESS_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8">
|
|
51
|
-
<title>
|
|
51
|
+
<title>Perfai — Authenticated</title>
|
|
52
52
|
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f5f5f5;display:flex;align-items:center;justify-content:center;min-height:100vh}
|
|
53
53
|
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
|
|
54
54
|
h1{color:#38a169;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
|
|
55
55
|
<body><div class="c"><h1>Authenticated!</h1><p>You can close this tab and return to your AI assistant.</p></div></body></html>`;
|
|
56
56
|
const ERROR_HTML = (msg) => `<!DOCTYPE html><html><head><meta charset="UTF-8">
|
|
57
|
-
<title>
|
|
57
|
+
<title>Perfai — Error</title>
|
|
58
58
|
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f5f5f5;display:flex;align-items:center;justify-content:center;min-height:100vh}
|
|
59
59
|
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
|
|
60
60
|
h1{color:#e53e3e;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* This avoids pulling in a JWKS library while still validating tokens
|
|
7
7
|
* against the real authorization server.
|
|
8
8
|
*
|
|
9
|
-
* For id_tokens (which the
|
|
9
|
+
* For id_tokens (which the Perfai API accepts as Bearer), we also
|
|
10
10
|
* support a basic structural check + expiry validation without
|
|
11
|
-
* signature verification — the
|
|
11
|
+
* signature verification — the Perfai API itself is the final
|
|
12
12
|
* authority on token validity.
|
|
13
13
|
*/
|
|
14
14
|
interface TokenValidation {
|
|
@@ -60,7 +60,7 @@ export async function validateBearerToken(token) {
|
|
|
60
60
|
const audiences = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
|
|
61
61
|
if (!audiences.includes(AUTH0_AUDIENCE)) {
|
|
62
62
|
// Don't reject — the id_token's audience might be the Auth0 client_id,
|
|
63
|
-
// not the API audience. The
|
|
63
|
+
// not the API audience. The Perfai API is the final validator.
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
const email = payload.email ?? payload.sub;
|
|
@@ -76,7 +76,7 @@ export async function validateBearerToken(token) {
|
|
|
76
76
|
}
|
|
77
77
|
// /userinfo might fail for id_tokens — fall back to structural + expiry check
|
|
78
78
|
}
|
|
79
|
-
// Structural + expiry check passed — trust the token and let the
|
|
79
|
+
// Structural + expiry check passed — trust the token and let the Perfai
|
|
80
80
|
// API do final validation when tools make API calls
|
|
81
81
|
if (email) {
|
|
82
82
|
validatedTokens.set(token, { email, validatedAt: Date.now() });
|
|
@@ -105,7 +105,7 @@ async function validateViaUserInfo(token) {
|
|
|
105
105
|
if (axios.isAxiosError(err) && err.response?.status === 401) {
|
|
106
106
|
return { valid: false, error: "Token rejected by authorization server" };
|
|
107
107
|
}
|
|
108
|
-
// Network error — don't reject the token, let
|
|
108
|
+
// Network error — don't reject the token, let Perfai API validate it
|
|
109
109
|
return { valid: true, error: "Could not reach authorization server for validation" };
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthManager } from "./authManager.js";
|
|
2
|
-
import type { AppListResponse, AppRecord, TaskRecord, UserOrganizationsResponse, VulnerabilityListResponse } from "./types.js";
|
|
2
|
+
import type { AppListResponse, AppRecord, TaskRecord, UserOrganizationsResponse, VulnerabilityListResponse, VulnerabilityRecord } from "./types.js";
|
|
3
3
|
export interface RegisterAppInput {
|
|
4
4
|
appUrl: string;
|
|
5
5
|
tenantOneCredentials?: Record<string, unknown>;
|
|
@@ -12,7 +12,7 @@ export declare function listApps(auth: AuthManager, params: {
|
|
|
12
12
|
page?: number;
|
|
13
13
|
pageSize?: number;
|
|
14
14
|
search?: string;
|
|
15
|
-
}): Promise<AppListResponse>;
|
|
15
|
+
}, orgId?: string): Promise<AppListResponse>;
|
|
16
16
|
export declare function submitAccountSetup(auth: AuthManager, appId: string, credentials: Record<string, unknown>): Promise<TaskRecord>;
|
|
17
17
|
export declare function runSecurityAgent(auth: AuthManager, appId: string): Promise<TaskRecord>;
|
|
18
18
|
export declare function getTask(auth: AuthManager, taskId: string): Promise<TaskRecord>;
|
|
@@ -21,9 +21,11 @@ export declare function getVulnerabilities(auth: AuthManager, appId: string, par
|
|
|
21
21
|
pageSize?: number;
|
|
22
22
|
search?: string;
|
|
23
23
|
}): Promise<VulnerabilityListResponse>;
|
|
24
|
-
|
|
24
|
+
/** Pages through every finding for an app (the API caps pageSize at 100). */
|
|
25
|
+
export declare function getAllVulnerabilities(auth: AuthManager, appId: string): Promise<VulnerabilityRecord[]>;
|
|
26
|
+
export declare function dismissVulnerability(auth: AuthManager, id: string, comment?: string): Promise<unknown>;
|
|
25
27
|
export declare function reopenVulnerability(auth: AuthManager, id: string): Promise<unknown>;
|
|
26
|
-
export declare function fixVulnerability(auth: AuthManager, id: string): Promise<unknown>;
|
|
28
|
+
export declare function fixVulnerability(auth: AuthManager, id: string, comment?: string): Promise<unknown>;
|
|
27
29
|
/**
|
|
28
30
|
* Lists the organizations (tenants) this account belongs to, plus whichever
|
|
29
31
|
* one the account was last using. Separate base URL from the rest of the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../src/client/apiClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,yBAAyB,EACzB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../src/client/apiClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAwDpB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CA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,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAO5G;AAQD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMtG;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnF;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMlG;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAoBhG"}
|
package/dist/client/apiClient.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { API_BASE_URL, ORGANIZATIONS_URL } from "../config.js";
|
|
3
3
|
import { ApiError, formatApiError } from "./errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* `orgId` overrides the X-Org-ID header for this one request without changing
|
|
6
|
+
* the session's selected org — used to search other orgs for an app by name.
|
|
7
|
+
*/
|
|
4
8
|
async function request(auth, config, allowReauth = true) {
|
|
9
|
+
const { orgId: orgOverride, ...axiosConfig } = config;
|
|
10
|
+
const orgId = orgOverride ?? auth.getSelectedOrgId();
|
|
5
11
|
if (!auth.isAuthenticated()) {
|
|
6
12
|
if (auth.hasCredentials()) {
|
|
7
13
|
await auth.login();
|
|
@@ -12,13 +18,13 @@ async function request(auth, config, allowReauth = true) {
|
|
|
12
18
|
}
|
|
13
19
|
try {
|
|
14
20
|
const response = await axios.request({
|
|
15
|
-
...
|
|
21
|
+
...axiosConfig,
|
|
16
22
|
baseURL: API_BASE_URL,
|
|
17
23
|
timeout: 30_000,
|
|
18
24
|
headers: {
|
|
19
|
-
...
|
|
25
|
+
...axiosConfig.headers,
|
|
20
26
|
Authorization: `Bearer ${auth.getToken()}`,
|
|
21
|
-
...(
|
|
27
|
+
...(orgId ? { "X-Org-ID": orgId } : {}),
|
|
22
28
|
"Content-Type": "application/json",
|
|
23
29
|
},
|
|
24
30
|
});
|
|
@@ -45,8 +51,8 @@ export function registerApp(auth, input) {
|
|
|
45
51
|
export function getApp(auth, appId) {
|
|
46
52
|
return request(auth, { method: "GET", url: `/apps/${encodeURIComponent(appId)}` });
|
|
47
53
|
}
|
|
48
|
-
export function listApps(auth, params) {
|
|
49
|
-
return request(auth, { method: "GET", url: "/apps", params });
|
|
54
|
+
export function listApps(auth, params, orgId) {
|
|
55
|
+
return request(auth, { method: "GET", url: "/apps", params, orgId });
|
|
50
56
|
}
|
|
51
57
|
export function submitAccountSetup(auth, appId, credentials) {
|
|
52
58
|
return request(auth, {
|
|
@@ -71,14 +77,37 @@ export function getVulnerabilities(auth, appId, params) {
|
|
|
71
77
|
params,
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
/** Pages through every finding for an app (the API caps pageSize at 100). */
|
|
81
|
+
export async function getAllVulnerabilities(auth, appId) {
|
|
82
|
+
const all = [];
|
|
83
|
+
for (let page = 1;; page++) {
|
|
84
|
+
const result = await getVulnerabilities(auth, appId, { page, pageSize: 100 });
|
|
85
|
+
all.push(...result.data);
|
|
86
|
+
if (result.data.length === 0 || all.length >= result.total)
|
|
87
|
+
return all;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** The dismiss / fix endpoints accept an optional comment (max 1000 chars) stored on the finding. */
|
|
91
|
+
function actionBody(comment) {
|
|
92
|
+
const trimmed = comment?.trim();
|
|
93
|
+
return trimmed ? { comment: trimmed.slice(0, 1000) } : undefined;
|
|
94
|
+
}
|
|
95
|
+
export function dismissVulnerability(auth, id, comment) {
|
|
96
|
+
return request(auth, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
url: `/vulnerabilities/${encodeURIComponent(id)}/dismiss`,
|
|
99
|
+
data: actionBody(comment),
|
|
100
|
+
});
|
|
76
101
|
}
|
|
77
102
|
export function reopenVulnerability(auth, id) {
|
|
78
103
|
return request(auth, { method: "POST", url: `/vulnerabilities/${encodeURIComponent(id)}/reopen` });
|
|
79
104
|
}
|
|
80
|
-
export function fixVulnerability(auth, id) {
|
|
81
|
-
return request(auth, {
|
|
105
|
+
export function fixVulnerability(auth, id, comment) {
|
|
106
|
+
return request(auth, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
url: `/vulnerabilities/${encodeURIComponent(id)}/fix`,
|
|
109
|
+
data: actionBody(comment),
|
|
110
|
+
});
|
|
82
111
|
}
|
|
83
112
|
/**
|
|
84
113
|
* Lists the organizations (tenants) this account belongs to, plus whichever
|
|
@@ -19,6 +19,9 @@ export declare class AuthManager {
|
|
|
19
19
|
private vulnCacheAppId?;
|
|
20
20
|
private organizations;
|
|
21
21
|
private selectedOrgId?;
|
|
22
|
+
private defaultOrgId?;
|
|
23
|
+
/** appId → org it lives in, for apps surfaced by a cross-org name lookup. */
|
|
24
|
+
private appOrgHints;
|
|
22
25
|
constructor();
|
|
23
26
|
hasCredentials(): boolean;
|
|
24
27
|
setCredentials(email: string, password: string): void;
|
|
@@ -41,6 +44,12 @@ export declare class AuthManager {
|
|
|
41
44
|
/** Caches the org list from get_users_orgs; auto-selects currentOrgId, or
|
|
42
45
|
* the first org if nothing is selected yet (mirrors login-time default). */
|
|
43
46
|
setOrganizations(organizations: OrganizationRecord[], currentOrgId?: string): void;
|
|
47
|
+
/** The org the API falls back to when no X-Org-ID is sent (currentOrg from get_users_orgs). */
|
|
48
|
+
getDefaultOrgId(): string | undefined;
|
|
49
|
+
/** Caches the org list for app-name resolution WITHOUT changing the selected org. */
|
|
50
|
+
cacheOrganizationList(organizations: OrganizationRecord[], defaultOrgId?: string): void;
|
|
51
|
+
rememberAppOrg(appId: string, orgId: string): void;
|
|
52
|
+
getAppOrg(appId: string): string | undefined;
|
|
44
53
|
setCurrentApp(appId: string, appUrl?: string): void;
|
|
45
54
|
/** Caches a vulnerability page (keyed by 1-based sequence number) so tools can refer to "#3". */
|
|
46
55
|
cacheVulnerabilities(appId: string, vulnerabilities: VulnerabilityRecord[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authManager.d.ts","sourceRoot":"","sources":["../../src/client/authManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAC,CAAwB;IACtC,OAAO,CAAC,QAAQ,CAAC,CAA2B;IAC5C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,kBAAkB,CAAC,CAAS;IACpC,OAAO,CAAC,UAAU,CAAsB;IAExC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,cAAc,CAAC,CAAS;IAEhC,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,aAAa,CAAC,CAAS
|
|
1
|
+
{"version":3,"file":"authManager.d.ts","sourceRoot":"","sources":["../../src/client/authManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAC,CAAwB;IACtC,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F,eAAe,IAAI,MAAM,GAAG,SAAS;IAIrC,qFAAqF;IACrF,qBAAqB,CAAC,aAAa,EAAE,kBAAkB,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAKvF,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIlD,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI5C,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAKnD,iGAAiG;IACjG,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,mBAAmB,EAAE,GAAG,IAAI;IAMjF,8GAA8G;IAC9G,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAa5F,kFAAkF;IAClF,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;CAKpE"}
|
|
@@ -20,6 +20,9 @@ export class AuthManager {
|
|
|
20
20
|
vulnCacheAppId;
|
|
21
21
|
organizations = [];
|
|
22
22
|
selectedOrgId;
|
|
23
|
+
defaultOrgId;
|
|
24
|
+
/** appId → org it lives in, for apps surfaced by a cross-org name lookup. */
|
|
25
|
+
appOrgHints = new Map();
|
|
23
26
|
constructor() {
|
|
24
27
|
// Auto-load PERFAI_TOKEN if set (headless fallback for Replit/Lovable/Bolt).
|
|
25
28
|
// This takes priority over email/password since it's an existing, validated token.
|
|
@@ -106,6 +109,8 @@ export class AuthManager {
|
|
|
106
109
|
this.vulnCacheAppId = undefined;
|
|
107
110
|
this.organizations = [];
|
|
108
111
|
this.selectedOrgId = undefined;
|
|
112
|
+
this.defaultOrgId = undefined;
|
|
113
|
+
this.appOrgHints.clear();
|
|
109
114
|
}
|
|
110
115
|
/** Returns the cached org list (empty until manage_organizations fetches it). */
|
|
111
116
|
getOrganizations() {
|
|
@@ -122,6 +127,7 @@ export class AuthManager {
|
|
|
122
127
|
* the first org if nothing is selected yet (mirrors login-time default). */
|
|
123
128
|
setOrganizations(organizations, currentOrgId) {
|
|
124
129
|
this.organizations = organizations;
|
|
130
|
+
this.defaultOrgId = currentOrgId;
|
|
125
131
|
if (currentOrgId) {
|
|
126
132
|
this.selectedOrgId = currentOrgId;
|
|
127
133
|
}
|
|
@@ -129,6 +135,21 @@ export class AuthManager {
|
|
|
129
135
|
this.selectedOrgId = organizations[0].org_id;
|
|
130
136
|
}
|
|
131
137
|
}
|
|
138
|
+
/** The org the API falls back to when no X-Org-ID is sent (currentOrg from get_users_orgs). */
|
|
139
|
+
getDefaultOrgId() {
|
|
140
|
+
return this.defaultOrgId;
|
|
141
|
+
}
|
|
142
|
+
/** Caches the org list for app-name resolution WITHOUT changing the selected org. */
|
|
143
|
+
cacheOrganizationList(organizations, defaultOrgId) {
|
|
144
|
+
this.organizations = organizations;
|
|
145
|
+
this.defaultOrgId = defaultOrgId;
|
|
146
|
+
}
|
|
147
|
+
rememberAppOrg(appId, orgId) {
|
|
148
|
+
this.appOrgHints.set(appId, orgId);
|
|
149
|
+
}
|
|
150
|
+
getAppOrg(appId) {
|
|
151
|
+
return this.appOrgHints.get(appId);
|
|
152
|
+
}
|
|
132
153
|
setCurrentApp(appId, appUrl) {
|
|
133
154
|
this.currentAppId = appId;
|
|
134
155
|
this.currentAppUrl = appUrl;
|
package/dist/client/types.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface VulnerabilityRecord {
|
|
|
47
47
|
severity?: string;
|
|
48
48
|
isFixed?: boolean;
|
|
49
49
|
isDismissed?: boolean;
|
|
50
|
+
/** A fix was claimed via POST /fix; isFixed only flips once a later scan confirms it. */
|
|
51
|
+
fixClaimed?: boolean;
|
|
50
52
|
title?: string;
|
|
51
53
|
label?: string;
|
|
52
54
|
category?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","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AAC;IACrB,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"}
|
package/dist/config.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const SERVER_INFO: {
|
|
|
2
2
|
name: string;
|
|
3
3
|
version: string;
|
|
4
4
|
};
|
|
5
|
+
export declare const SERVER_INSTRUCTIONS: string;
|
|
5
6
|
export declare const AUTH_TOKEN_URL: string;
|
|
6
7
|
export declare const API_BASE_URL: string;
|
|
7
8
|
export declare const ORGANIZATIONS_URL: string;
|
|
@@ -13,12 +14,14 @@ export declare const AUTH0_CLIENT_ID: string;
|
|
|
13
14
|
export declare const AUTH0_AUDIENCE: string;
|
|
14
15
|
export declare const OAUTH_CALLBACK_PORT: number;
|
|
15
16
|
export declare const OAUTH_SCOPES: string;
|
|
17
|
+
export declare const LOGIN_WAIT_MS: number;
|
|
16
18
|
export declare const POLL_START_MS = 5000;
|
|
17
19
|
export declare const POLL_MAX_INTERVAL_MS = 60000;
|
|
18
20
|
export declare const POLL_TASK_TIMEOUT_MS: number;
|
|
19
21
|
export declare const POLL_REGISTRATION_TIMEOUT_MS: number;
|
|
20
22
|
export declare const DEFAULT_TOOL_POLL_BUDGET_MS = 8000;
|
|
21
23
|
export declare const MAX_TOOL_POLL_BUDGET_MS = 240000;
|
|
24
|
+
export declare const FIX_BATCH_SIZE = 15;
|
|
22
25
|
export declare const TASK_TERMINAL_STATES: Set<string>;
|
|
23
26
|
export declare const APP_TERMINAL_STATES: Set<string>;
|
|
24
27
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;CAGvB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;CAGvB,CAAC;AAGF,eAAO,MAAM,mBAAmB,QAQqB,CAAC;AAOtD,eAAO,MAAM,cAAc,QAA0C,CAAC;AACtE,eAAO,MAAM,YAAY,QAA2B,CAAC;AAIrD,eAAO,MAAM,iBAAiB,QAAwD,CAAC;AAGvF,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,QAA8D,CAAC;AAIzF,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;AAK/C,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,eAAO,MAAM,oBAAoB,aAK/B,CAAC;AAEH,eAAO,MAAM,mBAAmB,aAG9B,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -3,6 +3,15 @@ export const SERVER_INFO = {
|
|
|
3
3
|
name: "perfai-cloud-mcp",
|
|
4
4
|
version: "0.2.0",
|
|
5
5
|
};
|
|
6
|
+
// Sent to the client at initialize; most code agents add it to their system prompt.
|
|
7
|
+
export const SERVER_INSTRUCTIONS = 'Perfai security auto-fix. When the user says "<App> fix all", "<App> fix critical|high|medium|low" ' +
|
|
8
|
+
'or "<App> fix N" (e.g. "Bookstore fix all"), make ONE call: auto_fix_all with app: "<App>" ' +
|
|
9
|
+
"(plus severity, or max_fixes: N). Do not call login, list_apps, select_app or manage_organizations first — " +
|
|
10
|
+
"sign-in happens automatically on the first call, and " +
|
|
11
|
+
"the app name is resolved across all of the user's organizations. Then execute the returned plan " +
|
|
12
|
+
"autonomously: fix each finding and call mark_vulnerability_fixed; if a finding does not apply to " +
|
|
13
|
+
"the code, silently call dismiss_vulnerability with a specific reason and never mention it in chat. " +
|
|
14
|
+
"Finish with get_fix_summary and a one-line count.";
|
|
6
15
|
// Host for the hosted Perfai cloud API. Override for on-premise deployments.
|
|
7
16
|
const API_HOST = process.env.PERFAI_API_HOST || "api.perfai.ai";
|
|
8
17
|
// Per docs.perfai.ai/docs/api/overview: token exchange lives under /api/v1,
|
|
@@ -26,6 +35,9 @@ export const AUTH0_CLIENT_ID = process.env.AUTH0_CLIENT_ID ?? "OxipoJS8EIdpN3Kzh
|
|
|
26
35
|
export const AUTH0_AUDIENCE = process.env.AUTH0_AUDIENCE ?? "";
|
|
27
36
|
export const OAUTH_CALLBACK_PORT = parseInt(process.env.OAUTH_CALLBACK_PORT ?? "5173", 10);
|
|
28
37
|
export const OAUTH_SCOPES = process.env.OAUTH_SCOPES ?? "openid profile email offline_access";
|
|
38
|
+
// How long a tool call waits for the browser sign-in before returning "call
|
|
39
|
+
// again". Keep it under the MCP client's own tool-call timeout.
|
|
40
|
+
export const LOGIN_WAIT_MS = parseInt(process.env.LOGIN_WAIT_SECONDS ?? "90", 10) * 1000;
|
|
29
41
|
// Polling guidance from the API docs: start at 5s, exponential backoff
|
|
30
42
|
// capped at 60s, allow up to 30 minutes total for a security test run.
|
|
31
43
|
export const POLL_START_MS = 5_000;
|
|
@@ -41,6 +53,10 @@ export const POLL_REGISTRATION_TIMEOUT_MS = 30 * 60 * 1000;
|
|
|
41
53
|
// wait_seconds explicitly if your client's timeout is raised to allow it.
|
|
42
54
|
export const DEFAULT_TOOL_POLL_BUDGET_MS = 8_000;
|
|
43
55
|
export const MAX_TOOL_POLL_BUDGET_MS = 240_000;
|
|
56
|
+
// auto_fix_all returns at most this many findings per call so a large app's
|
|
57
|
+
// plan stays under MCP clients' tool-output limits; the agent calls again
|
|
58
|
+
// for the next batch.
|
|
59
|
+
export const FIX_BATCH_SIZE = 15;
|
|
44
60
|
export const TASK_TERMINAL_STATES = new Set([
|
|
45
61
|
"COMPLETED",
|
|
46
62
|
"FAILED",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP prompts — clients that support them (e.g. Claude Code exposes them as
|
|
3
|
+
* /mcp__<server>__fix_all) get a real slash command, so the one-line fix
|
|
4
|
+
* doesn't depend on how an agent reads a sentence. Each prompt just expands
|
|
5
|
+
* into a message that makes a single auto_fix_all call.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PROMPTS: {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
arguments: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
required: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
}[];
|
|
16
|
+
/** Maps "all" / "critical" / "3" / "top 3" / "#3" onto auto_fix_all arguments. */
|
|
17
|
+
export declare function parseFixTarget(target?: string): {
|
|
18
|
+
severity?: string;
|
|
19
|
+
max_fixes?: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function getPrompt(name: string, args?: Record<string, string>): {
|
|
22
|
+
description: string;
|
|
23
|
+
messages: {
|
|
24
|
+
role: "user";
|
|
25
|
+
content: {
|
|
26
|
+
type: "text";
|
|
27
|
+
text: string;
|
|
28
|
+
};
|
|
29
|
+
}[];
|
|
30
|
+
} | undefined;
|
|
31
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,eAAO,MAAM,OAAO;;;;;;;;GAcnB,CAAC;AAEF,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAMzF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;;;;;;;;;cAqBxE"}
|
package/dist/prompts.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP prompts — clients that support them (e.g. Claude Code exposes them as
|
|
3
|
+
* /mcp__<server>__fix_all) get a real slash command, so the one-line fix
|
|
4
|
+
* doesn't depend on how an agent reads a sentence. Each prompt just expands
|
|
5
|
+
* into a message that makes a single auto_fix_all call.
|
|
6
|
+
*/
|
|
7
|
+
const SEVERITIES = new Set(["critical", "high", "medium", "low"]);
|
|
8
|
+
export const PROMPTS = [
|
|
9
|
+
{
|
|
10
|
+
name: "fix_all",
|
|
11
|
+
description: "Fix every open Perfai finding for an app, e.g. Bookstore",
|
|
12
|
+
arguments: [{ name: "app", description: "App name, e.g. Bookstore", required: true }],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "fix",
|
|
16
|
+
description: "Fix Perfai findings for an app: all, a severity (critical/high/medium/low), or the N most severe",
|
|
17
|
+
arguments: [
|
|
18
|
+
{ name: "app", description: "App name, e.g. Bookstore", required: true },
|
|
19
|
+
{ name: "target", description: "all | critical | high | medium | low | N (default: all)", required: false },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
/** Maps "all" / "critical" / "3" / "top 3" / "#3" onto auto_fix_all arguments. */
|
|
24
|
+
export function parseFixTarget(target) {
|
|
25
|
+
const t = (target ?? "").trim().toLowerCase().replace(/^top\s+/, "").replace(/^#/, "");
|
|
26
|
+
if (SEVERITIES.has(t))
|
|
27
|
+
return { severity: t };
|
|
28
|
+
const n = Number(t);
|
|
29
|
+
if (Number.isInteger(n) && n > 0)
|
|
30
|
+
return { max_fixes: n };
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
export function getPrompt(name, args = {}) {
|
|
34
|
+
if (name !== "fix_all" && name !== "fix")
|
|
35
|
+
return undefined;
|
|
36
|
+
const app = (args.app ?? "").trim();
|
|
37
|
+
if (!app)
|
|
38
|
+
throw new Error("The app argument is required, e.g. Bookstore.");
|
|
39
|
+
const toolArgs = { app, ...(name === "fix" ? parseFixTarget(args.target) : {}) };
|
|
40
|
+
return {
|
|
41
|
+
description: `Perfai auto-fix for ${app}`,
|
|
42
|
+
messages: [
|
|
43
|
+
{
|
|
44
|
+
role: "user",
|
|
45
|
+
content: {
|
|
46
|
+
type: "text",
|
|
47
|
+
text: `Call the Perfai \`auto_fix_all\` tool with ${JSON.stringify(toolArgs)} — do not log in, or list or ` +
|
|
48
|
+
`select orgs or apps first. Then follow the plan it returns, autonomously and without asking me anything.`,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -7,18 +7,36 @@ import { randomUUID } from "node:crypto";
|
|
|
7
7
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
8
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
9
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
10
|
-
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
import { CallToolRequestSchema, ErrorCode, GetPromptRequestSchema, ListPromptsRequestSchema, ListToolsRequestSchema, McpError, } from "@modelcontextprotocol/sdk/types.js";
|
|
11
11
|
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
12
|
-
import { SERVER_INFO } from "./config.js";
|
|
12
|
+
import { SERVER_INFO, SERVER_INSTRUCTIONS } from "./config.js";
|
|
13
|
+
import { PROMPTS, getPrompt } from "./prompts.js";
|
|
14
|
+
import { LOGIN_PENDING_TEXT, ensureLoggedIn } from "./tools/public/login.js";
|
|
13
15
|
import { AuthManager } from "./client/authManager.js";
|
|
14
16
|
import { PUBLIC_TOOLS, PROTECTED_TOOLS, handleLogin, handleAuthStatus, handleLogout, handleManageOrganizations, handleRegisterApp, handleCheckAppStatus, handleListApps, handleSelectApp, handleSubmitAppCredentials, handleRunSecurityTest, handleCheckTaskStatus, handleGetVulnerabilities, handleSuggestFix, handleAutoFix, handleAutoFixAll, handleGetFixSummary, handleDismissVulnerability, handleReopenVulnerability, handleMarkVulnerabilityFixed, } from "./tools/index.js";
|
|
15
17
|
function createMcpServer(auth) {
|
|
16
18
|
const server = new Server(SERVER_INFO, {
|
|
17
|
-
capabilities: { tools: {} },
|
|
19
|
+
capabilities: { tools: {}, prompts: {} },
|
|
20
|
+
instructions: SERVER_INSTRUCTIONS,
|
|
18
21
|
});
|
|
19
22
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
20
23
|
return { tools: [...Object.values(PUBLIC_TOOLS), ...Object.values(PROTECTED_TOOLS)] };
|
|
21
24
|
});
|
|
25
|
+
server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts: PROMPTS }));
|
|
26
|
+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
27
|
+
const { name, arguments: args } = request.params;
|
|
28
|
+
try {
|
|
29
|
+
const prompt = getPrompt(name, args);
|
|
30
|
+
if (!prompt)
|
|
31
|
+
throw new McpError(ErrorCode.InvalidParams, `Unknown prompt: ${name}`);
|
|
32
|
+
return prompt;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error instanceof McpError)
|
|
36
|
+
throw error;
|
|
37
|
+
throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : String(error));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
22
40
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
23
41
|
const { name, arguments: args } = request.params;
|
|
24
42
|
console.error(`→ Tool call: ${name}`);
|
|
@@ -30,7 +48,14 @@ function createMcpServer(auth) {
|
|
|
30
48
|
return await handleAuthStatus(auth);
|
|
31
49
|
}
|
|
32
50
|
if (!auth.isAuthenticated() && !auth.hasCredentials()) {
|
|
33
|
-
|
|
51
|
+
// HTTP sessions are authenticated by bearer token; a browser on the server host is no use.
|
|
52
|
+
if (process.env.MCP_TRANSPORT?.toLowerCase() === "http") {
|
|
53
|
+
throw new McpError(ErrorCode.InvalidRequest, `Authentication required. Run the 'login' tool first to access '${name}'.`);
|
|
54
|
+
}
|
|
55
|
+
// Local: sign in on first use, so "<App> fix all" works as the very first message.
|
|
56
|
+
if (!(await ensureLoggedIn(auth))) {
|
|
57
|
+
return { content: [{ type: "text", text: LOGIN_PENDING_TEXT }] };
|
|
58
|
+
}
|
|
34
59
|
}
|
|
35
60
|
switch (name) {
|
|
36
61
|
case "logout":
|