perfai-cloud-mcp 0.5.2 → 0.5.3

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 CHANGED
@@ -1,285 +1,285 @@
1
- # Perfai Cloud MCP Server
2
-
3
- A standalone Model Context Protocol (MCP) server for the **hosted Perfai cloud API**. Register an app by its URL, let Perfai run a security test in the cloud, pull the findings, and get an AI-powered fix prompt — from any MCP-compatible client.
4
-
5
-
6
- ## Authentication
7
-
8
- 1. **`PERFAI_API_KEY` env var** (recommended) — a PerfAI API key (`pfk_…`). Create one with `POST /api/v1/api-keys`; it is shown once, expires (default 90 days, max 365) and can be revoked. The server starts already authenticated as the key's owner. `PERFAI_TOKEN` also accepts a key, or an id_token you already have.
9
- 2. **Explicit args** — `login {"email": "...", "password": "..."}`
10
- 3. **Env credentials** — `PERFAI_EMAIL` / `PERFAI_PASSWORD` set in the server's env; `login {}` authenticates directly.
11
- 4. **OAuth login** (Auth0 Authorization Code + PKCE) — if none of the above is available and `AUTH0_CLIENT_ID` is configured (it defaults to Perfai's own client, so this is on by default), `login {}` opens your browser to Auth0's hosted login page and starts a local callback server on `OAUTH_CALLBACK_PORT` (default `5173`). If your browser already has an active Auth0 session, this can complete silently via SSO without prompting for credentials again.
12
- 5. **Legacy browser login form** — fallback if OAuth is explicitly disabled (`AUTH0_CLIENT_ID=""`): opens a local HTML login form on `http://127.0.0.1:18200–18300`.
13
-
14
- Once you see "Authenticated!" in the browser, call `login` again to confirm the session server-side.
15
-
16
- ```
17
- login # tries token / env / OAuth / browser login in the order above
18
- auth_status # verify you're authenticated, see auth method, current app/task
19
- logout # clear session
20
- ```
21
-
22
- ---
23
-
24
- ## Available Tools
25
-
26
- ### Authentication
27
- | Tool | Description |
28
- | --- | --- |
29
- | `login` | Sign in to Perfai. Opens browser or uses provided credentials. |
30
- | `auth_status` | Check if you're currently authenticated. |
31
- | `logout` | Sign out and clear session. |
32
-
33
- ### Organization Management
34
- | Tool | Description |
35
- | --- | --- |
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`. App names are only looked up in the selected organization — select another org here to work in it. |
37
-
38
-
39
- ### App Management
40
- | Tool | Description |
41
- | --- | --- |
42
- | `register_app` | Register a new app by URL for security testing. |
43
- | `check_app_status` | Check onboarding status once (on demand — never polled). |
44
- | `list_apps` | List all your registered apps. |
45
- | `select_app` | Switch to a different registered app. |
46
- | `submit_app_credentials` | Provide login credentials for apps that require authentication. |
47
-
48
- ### Security Testing
49
- | Tool | Description |
50
- | --- | --- |
51
- | `run_security_test` | Start a security test. Accepts `app` (name or URL — a new URL is registered) or `appId`. |
52
- | `check_task_status` | Check a security test's status once (on demand — never polled). |
53
-
54
- ### Vulnerability Management
55
- | Tool | Description |
56
- | --- | --- |
57
- | `get_vulnerabilities` | List findings from the latest security test. Accepts `app` (name) or `appId`, and `status`: `open` (default), `fixed` (confirmed fixes) or `dismissed` (Perfai staff only — other accounts are told dismissed findings are not listable). The open list ends with how many dismissed findings it leaves out. |
58
- | `suggest_fix` | Get a conversational fix prompt for a specific vulnerability. |
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 (dismissed), still open — by severity. Accepts `app` (name). Every account gets the skipped total (the API's `dismissedCount`); only Perfai staff get it by severity. If the API cannot count dismissals, Skipped reads `?`, never 0. |
62
- | `dismiss_vulnerability` | Dismiss a finding (false positive, accepted risk, etc.) with an optional `reason`, stored on the finding. The reply names the finding and gives its ID for undoing it. |
63
- | `reopen_vulnerability` | Reopen a dismissed finding (or undo a fix claim), by the ID from the dismiss reply. |
64
- | `mark_vulnerability_fixed` | Claim a finding as fixed after applying the code change; the next scan confirms it. |
65
-
66
- ---
67
-
68
- ## Test, issues, fix
69
-
70
- | Say | Does |
71
- | --- | --- |
72
- | `perfai test <url>` | A new URL is registered and onboarded; onboarding runs the first security test itself. Replies "Onboarding <App>. Say perfai issues later to view issues." |
73
- | `perfai test` (onboarded app) | Starts a new security test. |
74
- | `perfai status` / `check status` | Reads the status once: "<App> is still onboarding. Check again later." or "<App> onboarding is complete." |
75
- | `perfai issues` | Lists the findings — or says the app is still onboarding. |
76
- | `perfai fix` / `<App_name> fix all` | Fixes the findings (see below). |
77
-
78
- Onboarding and security tests run in the background on Perfai. The agent never waits or polls for them — every reply ends the turn, and status is checked only when you ask.
79
-
80
- ## One-line fix
81
-
82
- Connect the server to your code agent, sign in with `login`, open the app's codebase, and type:
83
-
84
- > **<App_name> fix all**
85
-
86
- That's it: no listing apps or selecting a project. The agent calls `auto_fix_all` with `app: "<App_name>"`; the name is looked up in your current organization, and the agent fixes every open finding from critical to low by editing code — it does not run commands. Findings that don't apply to your code are dismissed silently with a reason, and the run ends with one line of counts.
87
-
88
- If your account belongs to several organizations, the app must be in the selected one. Apps in other organizations are never searched; if the name isn't found, select the right org first (*"Switch to the Acme organization"* → `manage_organizations`), then say `<App_name> fix all` again.
89
-
90
- | Say | Does |
91
- | --- | --- |
92
- | `<App_name> fix all` | Every open finding |
93
- | `<App_name> fix critical` | Only critical (also `high`, `medium`, `low`) |
94
- | `<App_name> fix 1` | The single most severe open finding (`fix 5` → top 5) |
95
-
96
- 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).
97
-
98
- 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`.
99
-
100
- ## Typical Workflow
101
-
102
- ### The simple version
103
-
104
- Just tell your AI assistant:
105
-
106
- > *"Register https://myapp.com, run a security test, show me the results, and auto-fix everything."*
107
-
108
- The AI handles all the tool calls automatically.
109
-
110
- ### Step-by-step version
111
-
112
- ```
113
- 1. login → authenticate
114
- 2. register_app {"appUrl": "https://myapp.com"} → register your app
115
- (onboarding runs the first security test in the background)
116
- 3. check_app_status → check onboarding (when you ask)
117
- 4. get_vulnerabilities → see the findings
118
- 5. run_security_test → re-test later (optional)
119
- 6. check_task_status → check that test (when you ask)
120
- 7. auto_fix_all → get fix instructions
121
- 8. (apply fixes in your code)
122
- 9. mark_vulnerability_fixed {"vulnerability_id": "1"} → mark each as done
123
- 10. get_fix_summary → verify progress
124
- ```
125
-
126
- ---
127
-
128
- ## Example Prompts
129
-
130
- Here are some things you can say to your AI assistant:
131
-
132
- | What you want | What to say |
133
- | --- | --- |
134
- | **Full scan** | *"Register https://api.myapp.com, run a security test, and show me all vulnerabilities."* |
135
- | **Fix everything** | *"Bookstore fix all"* |
136
- | **Fix only critical** | *"Bookstore fix critical"* |
137
- | **Fix one issue** | *"Show me how to fix vulnerability #2."* |
138
- | **Check progress** | *"Show me the fix summary for my app."* |
139
- | **List organizations** | *"List my organizations."* |
140
- | **Switch organization** | *"Switch to the second organization, then list my apps."* |
141
- | **List my apps** | *"List all my registered apps."* |
142
- | **Switch apps** | *"Select the app with URL https://other-app.com."* |
143
- | **Dismiss a finding** | *"Dismiss vulnerability #3 — it's a false positive."* |
144
- | **Undo a dismissal** | *"Reopen the finding I just dismissed."* |
145
- | **List dismissed findings** (Perfai staff) | *"Perfai issues dismissed."* |
146
-
147
- ---
148
-
149
- ## Self-Hosting / Development
150
-
151
- ### Prerequisites
152
-
153
- - Node.js 18+
154
- - npm
155
-
156
- ### Build from source
157
-
158
- ```bash
159
- git clone https://github.com/user/mcp-server.git
160
- cd mcp-server
161
- npm install
162
- npm run build
163
- ```
164
-
165
- ### Run locally
166
-
167
- **Stdio mode** (for Cursor / Claude Code):
168
- ```bash
169
- npm start
170
- ```
171
-
172
- **HTTP mode** (for ChatGPT / remote access):
173
- ```bash
174
- # Linux / Mac
175
- MCP_TRANSPORT=http node dist/server.js
176
-
177
- # Windows PowerShell
178
- $env:MCP_TRANSPORT="http"; node dist/server.js
179
- ```
180
-
181
- ### Environment Variables
182
-
183
- | Variable | Required | Default | Description |
184
- | --- | --- | --- | --- |
185
- | `MCP_TRANSPORT` | No | `stdio` | Set to `http` for remote HTTP server mode |
186
- | `PORT` | No | `3000` | Port for the HTTP server |
187
- | `PERFAI_API_KEY` | No | — | PerfAI API key (`pfk_…`) — **recommended for headless / cloud workspaces** (Replit, Lovable, Bolt, v0, CI). Skips login entirely. |
188
- | `PERFAI_TOKEN` | No | — | Same as `PERFAI_API_KEY` (wins if both are set); also accepts a pre-obtained id_token. |
189
- | `PERFAI_EMAIL` | No | — | Auto-login email (stdio only — ignored in HTTP mode) |
190
- | `PERFAI_PASSWORD` | No | — | Auto-login password (stdio only — ignored in HTTP mode) |
191
- | `AUTH0_DOMAIN` | No | `auth.perfai.ai` | Auth0 tenant domain used for OAuth PKCE login and HTTP bearer-token validation |
192
- | `AUTH0_CLIENT_ID` | No | *(Perfai's public client)* | Auth0 application client ID for the OAuth PKCE browser flow |
193
- | `AUTH0_AUDIENCE` | No | — | Auth0 API audience, if your tenant requires one |
194
- | `OAUTH_CALLBACK_PORT` | No | `5173` | Local port the OAuth flow listens on for the Auth0 redirect |
195
- | `OAUTH_SCOPES` | No | `openid profile email offline_access` | Scopes requested during OAuth login |
196
- | `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 |
197
- | `MCP_API_KEY` | No | — | Legacy shared key. Opens an HTTP session with no PerfAI identity — the caller must still `login`. Use per-user API keys instead. |
198
-
199
- ### Deploy with Docker
200
-
201
- ```bash
202
- docker build -t perfai-mcp .
203
- docker run -p 3000:3000 -e MCP_TRANSPORT=http perfai-mcp
204
- ```
205
-
206
- ### Endpoints (HTTP mode)
207
-
208
- | Method | Path | Description |
209
- | --- | --- | --- |
210
- | `POST` | `/mcp` | MCP JSON-RPC requests |
211
- | `GET` | `/mcp` | SSE stream (server-initiated messages) |
212
- | `DELETE` | `/mcp` | Session termination |
213
- | `GET` | `/health` | Health check — `{"status":"ok"}` only |
214
- | `GET` | `/` | `{"status":"ok"}` only. The running version is in the MCP `initialize` reply (`serverInfo.version`). |
215
-
216
- ### Test with MCP Inspector
217
-
218
- ```bash
219
- npm run mcp:inspect
220
- ```
221
-
222
- Opens the Inspector UI at `http://localhost:6274` where you can test tools interactively.
223
-
224
- ---
225
-
226
- ## API Mapping
227
-
228
- Every tool maps directly to a Perfai cloud API endpoint:
229
-
230
- | Tool | API Endpoint |
231
- | --- | --- |
232
- | `login` | `POST /api/v1/auth/token` |
233
- | `manage_organizations` | `GET /api/v1/org-users/get_users_orgs` (selected org is then sent as the `X-Org-ID` header on app requests) |
234
- | `register_app` | `POST /v1/apps` |
235
- | `check_app_status` | `GET /v1/apps/{appId}` |
236
- | `list_apps` | `GET /v1/apps` |
237
- | `select_app` | `GET /v1/apps/{appId}` |
238
- | `submit_app_credentials` | `POST /v1/apps/{appId}/account-setup` |
239
- | `run_security_test` | `POST /v1/apps/{appId}/security-agent` |
240
- | `check_task_status` | `GET /v1/tasks/{taskId}` |
241
- | `get_vulnerabilities` | `GET /v1/apps/{appId}/vulnerabilities` (`status` → `isFixed` / `isDismissed`) |
242
- | `suggest_fix` | Local prompt builder (no API call) |
243
- | `auto_fix` | Local prompt builder (no API call) |
244
- | `auto_fix_all` | `GET /v1/apps/{appId}/vulnerabilities` + local prompt builder |
245
- | `get_fix_summary` | `GET /v1/apps/{appId}/vulnerabilities` — default (with `dismissedCount`), `isFixed=true` and `isDismissed=true` — merged locally |
246
- | `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` (`reason` → `comment`) |
247
- | `reopen_vulnerability` | `POST /v1/vulnerabilities/{id}/reopen` |
248
- | `mark_vulnerability_fixed` | `POST /v1/vulnerabilities/{id}/fix` |
249
- | `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` |
250
- | `auth_status` / `logout` | Local session state only (`logout` also clears the selected organization) |
251
-
252
- ---
253
-
254
- ## Troubleshooting
255
-
256
- | Problem | Solution |
257
- | --- | --- |
258
- | **Can't connect from ChatGPT** | Make sure the URL ends with `/mcp`: `https://mcp-server.perfai.ai/mcp` |
259
- | **401 Unauthorized** | Regenerate your access token — make sure email and password are correct |
260
- | **No tools visible after connecting** | Check that the access token is valid; try refreshing the connection |
261
- | **"Authentication required" on every tool** | Call `login` first, or verify credentials are set |
262
- | **`check_app_status` says still onboarding** | Normal for first-time onboarding — it runs in the background; check again later |
263
- | **Status reads Needs input / Needs login** | Onboarding is waiting on you — supply a login with `submit_app_credentials` (or resolve it in the Perfai console), then check again |
264
- | **Status reads Interrupted** | A problem on Perfai's side; results so far are saved. If it stays that way, run `register_app` again with the same URL |
265
- | **Status reads Completed — partial** | Some checks didn't run, so `get_vulnerabilities` shows incomplete findings — an area with no finding was not necessarily tested. `run_security_test` can be tried; Perfai says if the app can't be tested until onboarding finishes |
266
- | **`run_security_test` says the app is still onboarding** | Onboarding runs the first security test itself — check again later, then say `perfai issues` |
267
- | **429 rate limit errors** | Wait for the `Retry-After` duration and try again |
268
- | **`suggest_fix` / `auto_fix` says "not found"** | Call `get_vulnerabilities` first in the same session to load the findings |
269
- | **`MCP error -32000: Connection closed`** | Ensure you ran `npm run build` — clients need `dist/server.js`, not `src/` |
270
-
271
- ---
272
-
273
- ## Security
274
-
275
- - Access tokens are transmitted over **HTTPS** only
276
- - Tokens are validated against the Perfai cloud auth API on every new session
277
- - Validated tokens are cached server-side for 30 minutes to reduce auth API calls
278
- - Each MCP session gets its own isolated authentication state
279
- - No credentials are stored on disk by the MCP server
280
-
281
- ---
282
-
283
- ## License
284
-
285
- MIT
1
+ # Perfai Cloud MCP Server
2
+
3
+ A standalone Model Context Protocol (MCP) server for the **hosted Perfai cloud API**. Register an app by its URL, let Perfai run a security test in the cloud, pull the findings, and get an AI-powered fix prompt — from any MCP-compatible client.
4
+
5
+
6
+ ## Authentication
7
+
8
+ 1. **`PERFAI_API_KEY` env var** (recommended) — a PerfAI API key (`pfk_…`). Create one with `POST /api/v1/api-keys`; it is shown once, expires (default 90 days, max 365) and can be revoked. The server starts already authenticated as the key's owner. `PERFAI_TOKEN` also accepts a key, or an id_token you already have.
9
+ 2. **Explicit args** — `login {"email": "...", "password": "..."}`
10
+ 3. **Env credentials** — `PERFAI_EMAIL` / `PERFAI_PASSWORD` set in the server's env; `login {}` authenticates directly.
11
+ 4. **OAuth login** (Auth0 Authorization Code + PKCE) — if none of the above is available and `AUTH0_CLIENT_ID` is configured (it defaults to Perfai's own client, so this is on by default), `login {}` opens your browser to Auth0's hosted login page and starts a local callback server on `OAUTH_CALLBACK_PORT` (default `5173`). If your browser already has an active Auth0 session, this can complete silently via SSO without prompting for credentials again.
12
+ 5. **Legacy browser login form** — fallback if OAuth is explicitly disabled (`AUTH0_CLIENT_ID=""`): opens a local HTML login form on `http://127.0.0.1:18200–18300`.
13
+
14
+ Once you see "Authenticated!" in the browser, call `login` again to confirm the session server-side.
15
+
16
+ ```
17
+ login # tries token / env / OAuth / browser login in the order above
18
+ auth_status # verify you're authenticated, see auth method, current app/task
19
+ logout # clear session
20
+ ```
21
+
22
+ ---
23
+
24
+ ## Available Tools
25
+
26
+ ### Authentication
27
+ | Tool | Description |
28
+ | --- | --- |
29
+ | `login` | Sign in to Perfai. Opens browser or uses provided credentials. |
30
+ | `auth_status` | Check if you're currently authenticated. |
31
+ | `logout` | Sign out and clear session. |
32
+
33
+ ### Organization Management
34
+ | Tool | Description |
35
+ | --- | --- |
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`. App names are only looked up in the selected organization — select another org here to work in it. |
37
+
38
+
39
+ ### App Management
40
+ | Tool | Description |
41
+ | --- | --- |
42
+ | `register_app` | Register a new app by URL for security testing. |
43
+ | `check_app_status` | Check onboarding status once (on demand — never polled). |
44
+ | `list_apps` | List all your registered apps. |
45
+ | `select_app` | Switch to a different registered app. |
46
+ | `submit_app_credentials` | Provide login credentials for apps that require authentication. |
47
+
48
+ ### Security Testing
49
+ | Tool | Description |
50
+ | --- | --- |
51
+ | `run_security_test` | Start a security test. Accepts `app` (name or URL — a new URL is registered) or `appId`. |
52
+ | `check_task_status` | Check a security test's status once (on demand — never polled). |
53
+
54
+ ### Vulnerability Management
55
+ | Tool | Description |
56
+ | --- | --- |
57
+ | `get_vulnerabilities` | List findings from the latest security test. Accepts `app` (name) or `appId`, and `status`: `open` (default), `fixed` (confirmed fixes) or `dismissed` (Perfai staff only — other accounts are told dismissed findings are not listable). The open list ends with how many dismissed findings it leaves out. |
58
+ | `suggest_fix` | Get a conversational fix prompt for a specific vulnerability. |
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 (dismissed), still open — by severity. Accepts `app` (name). Every account gets the skipped total (the API's `dismissedCount`); only Perfai staff get it by severity. If the API cannot count dismissals, Skipped reads `?`, never 0. |
62
+ | `dismiss_vulnerability` | Dismiss a finding (false positive, accepted risk, etc.) with an optional `reason`, stored on the finding. The reply names the finding and gives its ID for undoing it. |
63
+ | `reopen_vulnerability` | Reopen a dismissed finding (or undo a fix claim), by the ID from the dismiss reply. |
64
+ | `mark_vulnerability_fixed` | Claim a finding as fixed after applying the code change; the next scan confirms it. |
65
+
66
+ ---
67
+
68
+ ## Test, issues, fix
69
+
70
+ | Say | Does |
71
+ | --- | --- |
72
+ | `perfai test <url>` | A new URL is registered and onboarded; onboarding runs the first security test itself. Replies "Onboarding <App>. Say perfai issues later to view issues." |
73
+ | `perfai test` (onboarded app) | Starts a new security test. |
74
+ | `perfai status` / `check status` | Reads the status once: "<App> is still onboarding. Check again later." or "<App> onboarding is complete." |
75
+ | `perfai issues` | Lists the findings — or says the app is still onboarding. |
76
+ | `perfai fix` / `<App_name> fix all` | Fixes the findings (see below). |
77
+
78
+ Onboarding and security tests run in the background on Perfai. The agent never waits or polls for them — every reply ends the turn, and status is checked only when you ask.
79
+
80
+ ## One-line fix
81
+
82
+ Connect the server to your code agent, sign in with `login`, open the app's codebase, and type:
83
+
84
+ > **<App_name> fix all**
85
+
86
+ That's it: no listing apps or selecting a project. The agent calls `auto_fix_all` with `app: "<App_name>"`; the name is looked up in your current organization, and the agent fixes every open finding from critical to low by editing code — it does not run commands. Findings that don't apply to your code are dismissed silently with a reason, and the run ends with one line of counts.
87
+
88
+ If your account belongs to several organizations, the app must be in the selected one. Apps in other organizations are never searched; if the name isn't found, select the right org first (*"Switch to the Acme organization"* → `manage_organizations`), then say `<App_name> fix all` again.
89
+
90
+ | Say | Does |
91
+ | --- | --- |
92
+ | `<App_name> fix all` | Every open finding |
93
+ | `<App_name> fix critical` | Only critical (also `high`, `medium`, `low`) |
94
+ | `<App_name> fix 1` | The single most severe open finding (`fix 5` → top 5) |
95
+
96
+ 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).
97
+
98
+ 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`.
99
+
100
+ ## Typical Workflow
101
+
102
+ ### The simple version
103
+
104
+ Just tell your AI assistant:
105
+
106
+ > *"Register https://myapp.com, run a security test, show me the results, and auto-fix everything."*
107
+
108
+ The AI handles all the tool calls automatically.
109
+
110
+ ### Step-by-step version
111
+
112
+ ```
113
+ 1. login → authenticate
114
+ 2. register_app {"appUrl": "https://myapp.com"} → register your app
115
+ (onboarding runs the first security test in the background)
116
+ 3. check_app_status → check onboarding (when you ask)
117
+ 4. get_vulnerabilities → see the findings
118
+ 5. run_security_test → re-test later (optional)
119
+ 6. check_task_status → check that test (when you ask)
120
+ 7. auto_fix_all → get fix instructions
121
+ 8. (apply fixes in your code)
122
+ 9. mark_vulnerability_fixed {"vulnerability_id": "1"} → mark each as done
123
+ 10. get_fix_summary → verify progress
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Example Prompts
129
+
130
+ Here are some things you can say to your AI assistant:
131
+
132
+ | What you want | What to say |
133
+ | --- | --- |
134
+ | **Full scan** | *"Register https://api.myapp.com, run a security test, and show me all vulnerabilities."* |
135
+ | **Fix everything** | *"Bookstore fix all"* |
136
+ | **Fix only critical** | *"Bookstore fix critical"* |
137
+ | **Fix one issue** | *"Show me how to fix vulnerability #2."* |
138
+ | **Check progress** | *"Show me the fix summary for my app."* |
139
+ | **List organizations** | *"List my organizations."* |
140
+ | **Switch organization** | *"Switch to the second organization, then list my apps."* |
141
+ | **List my apps** | *"List all my registered apps."* |
142
+ | **Switch apps** | *"Select the app with URL https://other-app.com."* |
143
+ | **Dismiss a finding** | *"Dismiss vulnerability #3 — it's a false positive."* |
144
+ | **Undo a dismissal** | *"Reopen the finding I just dismissed."* |
145
+ | **List dismissed findings** (Perfai staff) | *"Perfai issues dismissed."* |
146
+
147
+ ---
148
+
149
+ ## Self-Hosting / Development
150
+
151
+ ### Prerequisites
152
+
153
+ - Node.js 18+
154
+ - npm
155
+
156
+ ### Build from source
157
+
158
+ ```bash
159
+ git clone https://github.com/user/mcp-server.git
160
+ cd mcp-server
161
+ npm install
162
+ npm run build
163
+ ```
164
+
165
+ ### Run locally
166
+
167
+ **Stdio mode** (for Cursor / Claude Code):
168
+ ```bash
169
+ npm start
170
+ ```
171
+
172
+ **HTTP mode** (for ChatGPT / remote access):
173
+ ```bash
174
+ # Linux / Mac
175
+ MCP_TRANSPORT=http node dist/server.js
176
+
177
+ # Windows PowerShell
178
+ $env:MCP_TRANSPORT="http"; node dist/server.js
179
+ ```
180
+
181
+ ### Environment Variables
182
+
183
+ | Variable | Required | Default | Description |
184
+ | --- | --- | --- | --- |
185
+ | `MCP_TRANSPORT` | No | `stdio` | Set to `http` for remote HTTP server mode |
186
+ | `PORT` | No | `3000` | Port for the HTTP server |
187
+ | `PERFAI_API_KEY` | No | — | PerfAI API key (`pfk_…`) — **recommended for headless / cloud workspaces** (Replit, Lovable, Bolt, v0, CI). Skips login entirely. |
188
+ | `PERFAI_TOKEN` | No | — | Same as `PERFAI_API_KEY` (wins if both are set); also accepts a pre-obtained id_token. |
189
+ | `PERFAI_EMAIL` | No | — | Auto-login email (stdio only — ignored in HTTP mode) |
190
+ | `PERFAI_PASSWORD` | No | — | Auto-login password (stdio only — ignored in HTTP mode) |
191
+ | `AUTH0_DOMAIN` | No | `auth.perfai.ai` | Auth0 tenant domain used for OAuth PKCE login and HTTP bearer-token validation |
192
+ | `AUTH0_CLIENT_ID` | No | *(Perfai's public client)* | Auth0 application client ID for the OAuth PKCE browser flow |
193
+ | `AUTH0_AUDIENCE` | No | — | Auth0 API audience, if your tenant requires one |
194
+ | `OAUTH_CALLBACK_PORT` | No | `5173` | Local port the OAuth flow listens on for the Auth0 redirect |
195
+ | `OAUTH_SCOPES` | No | `openid profile email offline_access` | Scopes requested during OAuth login |
196
+ | `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 |
197
+ | `MCP_API_KEY` | No | — | Legacy shared key. Opens an HTTP session with no PerfAI identity — the caller must still `login`. Use per-user API keys instead. |
198
+
199
+ ### Deploy with Docker
200
+
201
+ ```bash
202
+ docker build -t perfai-mcp .
203
+ docker run -p 3000:3000 -e MCP_TRANSPORT=http perfai-mcp
204
+ ```
205
+
206
+ ### Endpoints (HTTP mode)
207
+
208
+ | Method | Path | Description |
209
+ | --- | --- | --- |
210
+ | `POST` | `/mcp` | MCP JSON-RPC requests |
211
+ | `GET` | `/mcp` | SSE stream (server-initiated messages) |
212
+ | `DELETE` | `/mcp` | Session termination |
213
+ | `GET` | `/health` | Health check — `{"status":"ok"}` only |
214
+ | `GET` | `/` | `{"status":"ok"}` only. The running version is in the MCP `initialize` reply (`serverInfo.version`). |
215
+
216
+ ### Test with MCP Inspector
217
+
218
+ ```bash
219
+ npm run mcp:inspect
220
+ ```
221
+
222
+ Opens the Inspector UI at `http://localhost:6274` where you can test tools interactively.
223
+
224
+ ---
225
+
226
+ ## API Mapping
227
+
228
+ Every tool maps directly to a Perfai cloud API endpoint:
229
+
230
+ | Tool | API Endpoint |
231
+ | --- | --- |
232
+ | `login` | `POST /api/v1/auth/token` |
233
+ | `manage_organizations` | `GET /api/v1/org-users/get_users_orgs` (selected org is then sent as the `X-Org-ID` header on app requests) |
234
+ | `register_app` | `POST /v1/apps` |
235
+ | `check_app_status` | `GET /v1/apps/{appId}` |
236
+ | `list_apps` | `GET /v1/apps` |
237
+ | `select_app` | `GET /v1/apps/{appId}` |
238
+ | `submit_app_credentials` | `POST /v1/apps/{appId}/account-setup` |
239
+ | `run_security_test` | `POST /v1/apps/{appId}/security-agent` |
240
+ | `check_task_status` | `GET /v1/tasks/{taskId}` |
241
+ | `get_vulnerabilities` | `GET /v1/apps/{appId}/vulnerabilities` (`status` → `isFixed` / `isDismissed`) |
242
+ | `suggest_fix` | Local prompt builder (no API call) |
243
+ | `auto_fix` | Local prompt builder (no API call) |
244
+ | `auto_fix_all` | `GET /v1/apps/{appId}/vulnerabilities` + local prompt builder |
245
+ | `get_fix_summary` | `GET /v1/apps/{appId}/vulnerabilities` — default (with `dismissedCount`), `isFixed=true` and `isDismissed=true` — merged locally |
246
+ | `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` (`reason` → `comment`) |
247
+ | `reopen_vulnerability` | `POST /v1/vulnerabilities/{id}/reopen` |
248
+ | `mark_vulnerability_fixed` | `POST /v1/vulnerabilities/{id}/fix` |
249
+ | `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` |
250
+ | `auth_status` / `logout` | Local session state only (`logout` also clears the selected organization) |
251
+
252
+ ---
253
+
254
+ ## Troubleshooting
255
+
256
+ | Problem | Solution |
257
+ | --- | --- |
258
+ | **Can't connect from ChatGPT** | Make sure the URL ends with `/mcp`: `https://mcp-server.perfai.ai/mcp` |
259
+ | **401 Unauthorized** | Regenerate your access token — make sure email and password are correct |
260
+ | **No tools visible after connecting** | Check that the access token is valid; try refreshing the connection |
261
+ | **"Authentication required" on every tool** | Call `login` first, or verify credentials are set |
262
+ | **`check_app_status` says still onboarding** | Normal for first-time onboarding — it runs in the background; check again later |
263
+ | **Status reads Needs input / Needs login** | Onboarding is waiting on you — supply a login with `submit_app_credentials` (or resolve it in the Perfai console), then check again |
264
+ | **Status reads Interrupted** | A problem on Perfai's side; results so far are saved. If it stays that way, run `register_app` again with the same URL |
265
+ | **Status reads Completed — partial** | Some checks didn't run, so `get_vulnerabilities` shows incomplete findings — an area with no finding was not necessarily tested. `run_security_test` can be tried; Perfai says if the app can't be tested until onboarding finishes |
266
+ | **`run_security_test` says the app is still onboarding** | Onboarding runs the first security test itself — check again later, then say `perfai issues` |
267
+ | **429 rate limit errors** | Wait for the `Retry-After` duration and try again |
268
+ | **`suggest_fix` / `auto_fix` says "not found"** | Call `get_vulnerabilities` first in the same session to load the findings |
269
+ | **`MCP error -32000: Connection closed`** | Ensure you ran `npm run build` — clients need `dist/server.js`, not `src/` |
270
+
271
+ ---
272
+
273
+ ## Security
274
+
275
+ - Access tokens are transmitted over **HTTPS** only
276
+ - Tokens are validated against the Perfai cloud auth API on every new session
277
+ - Validated tokens are cached server-side for 30 minutes to reduce auth API calls
278
+ - Each MCP session gets its own isolated authentication state
279
+ - No credentials are stored on disk by the MCP server
280
+
281
+ ---
282
+
283
+ ## License
284
+
285
+ MIT
@@ -33,17 +33,17 @@ export function startOAuthBrowserFlow() {
33
33
  callbackServer = null;
34
34
  }
35
35
  };
36
- const SUCCESS_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8">
37
- <title>Perfai — Authenticated</title>
38
- <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}
39
- .c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
40
- h1{color:#38a169;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
36
+ const SUCCESS_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8">
37
+ <title>Perfai — Authenticated</title>
38
+ <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}
39
+ .c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
40
+ h1{color:#38a169;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
41
41
  <body><div class="c"><h1>Authenticated!</h1><p>You can close this tab and return to your AI assistant.</p></div></body></html>`;
42
- const ERROR_HTML = (msg) => `<!DOCTYPE html><html><head><meta charset="UTF-8">
43
- <title>Perfai — Error</title>
44
- <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}
45
- .c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
46
- h1{color:#e53e3e;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
42
+ const ERROR_HTML = (msg) => `<!DOCTYPE html><html><head><meta charset="UTF-8">
43
+ <title>Perfai — Error</title>
44
+ <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}
45
+ .c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
46
+ h1{color:#e53e3e;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
47
47
  <body><div class="c"><h1>Login Failed</h1><p>${msg}</p></div></body></html>`;
48
48
  callbackServer = createServer(async (req, res) => {
49
49
  const url = new URL(req.url ?? "/", `http://localhost:${OAUTH_CALLBACK_PORT}`);
package/dist/cli.js CHANGED
@@ -64,25 +64,25 @@ function openBrowser(url) {
64
64
  : `xdg-open "${url}"`;
65
65
  exec(cmd, () => { });
66
66
  }
67
- const LOGIN_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
68
- <title>Perfai Login</title><style>
69
- *{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}
70
- .c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);width:100%;max-width:400px}
71
- .logo{text-align:center;margin-bottom:24px}.logo h1{font-size:24px;color:#111}.logo p{color:#666;font-size:14px;margin-top:4px}
72
- label{display:block;font-size:14px;font-weight:500;color:#333;margin-bottom:6px}
73
- input{width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:8px;font-size:14px;margin-bottom:16px;outline:none}input:focus{border-color:#111}
74
- button{width:100%;padding:12px;background:#111;color:#fff;border:none;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer}button:hover{background:#333}button:disabled{background:#999}
75
- .err{color:#e53e3e;font-size:13px;margin-bottom:12px;display:none}.ok{text-align:center;color:#38a169;font-size:16px;font-weight:600;display:none;margin-top:16px}
76
- </style></head><body><div class="c"><div class="logo"><h1>Perfai</h1><p>Sign in with your cloud.perfai.ai account</p></div>
77
- <form id="f"><label for="e">Email</label><input type="email" id="e" placeholder="you@example.com" required autofocus>
78
- <label for="p">Password</label><input type="password" id="p" placeholder="Your password" required>
79
- <div class="err" id="x"></div><button type="submit" id="b">Sign in</button></form>
80
- <div class="ok" id="s">Authenticated! You can close this tab.</div></div>
81
- <script>document.getElementById('f').addEventListener('submit',async e=>{e.preventDefault();const b=document.getElementById('b'),x=document.getElementById('x');
82
- b.disabled=true;b.textContent='Signing in...';x.style.display='none';try{const r=await fetch('/auth',{method:'POST',headers:{'Content-Type':'application/json'},
83
- body:JSON.stringify({email:document.getElementById('e').value,password:document.getElementById('p').value})});const d=await r.json();
84
- if(d.ok){document.getElementById('f').style.display='none';document.getElementById('s').style.display='block'}
85
- else{x.textContent=d.message||'Login failed';x.style.display='block';b.disabled=false;b.textContent='Sign in'}}
67
+ const LOGIN_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
68
+ <title>Perfai Login</title><style>
69
+ *{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}
70
+ .c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);width:100%;max-width:400px}
71
+ .logo{text-align:center;margin-bottom:24px}.logo h1{font-size:24px;color:#111}.logo p{color:#666;font-size:14px;margin-top:4px}
72
+ label{display:block;font-size:14px;font-weight:500;color:#333;margin-bottom:6px}
73
+ input{width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:8px;font-size:14px;margin-bottom:16px;outline:none}input:focus{border-color:#111}
74
+ button{width:100%;padding:12px;background:#111;color:#fff;border:none;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer}button:hover{background:#333}button:disabled{background:#999}
75
+ .err{color:#e53e3e;font-size:13px;margin-bottom:12px;display:none}.ok{text-align:center;color:#38a169;font-size:16px;font-weight:600;display:none;margin-top:16px}
76
+ </style></head><body><div class="c"><div class="logo"><h1>Perfai</h1><p>Sign in with your cloud.perfai.ai account</p></div>
77
+ <form id="f"><label for="e">Email</label><input type="email" id="e" placeholder="you@example.com" required autofocus>
78
+ <label for="p">Password</label><input type="password" id="p" placeholder="Your password" required>
79
+ <div class="err" id="x"></div><button type="submit" id="b">Sign in</button></form>
80
+ <div class="ok" id="s">Authenticated! You can close this tab.</div></div>
81
+ <script>document.getElementById('f').addEventListener('submit',async e=>{e.preventDefault();const b=document.getElementById('b'),x=document.getElementById('x');
82
+ b.disabled=true;b.textContent='Signing in...';x.style.display='none';try{const r=await fetch('/auth',{method:'POST',headers:{'Content-Type':'application/json'},
83
+ body:JSON.stringify({email:document.getElementById('e').value,password:document.getElementById('p').value})});const d=await r.json();
84
+ if(d.ok){document.getElementById('f').style.display='none';document.getElementById('s').style.display='block'}
85
+ else{x.textContent=d.message||'Login failed';x.style.display='block';b.disabled=false;b.textContent='Sign in'}}
86
86
  catch{x.textContent='Connection error';x.style.display='block';b.disabled=false;b.textContent='Sign in'}});</script></body></html>`;
87
87
  function browserLogin(auth) {
88
88
  return new Promise((resolve, reject) => {
@@ -359,33 +359,33 @@ async function scan(url) {
359
359
  log("");
360
360
  }
361
361
  function printHelp() {
362
- log(`
363
- ${BOLD}perfai${RESET} — Perfai Security Scanner CLI v${SERVER_INFO.version}
364
-
365
- ${BOLD}USAGE${RESET}
366
- npx perfai scan <url> Scan an app for security vulnerabilities
367
- npx perfai scan --help Show this help
368
-
369
- ${BOLD}EXAMPLES${RESET}
370
- npx perfai scan https://api.myapp.com
371
- npx perfai scan https://staging.example.com
372
-
373
- ${BOLD}AUTHENTICATION${RESET}
374
- Set environment variables for non-interactive login:
375
- PERFAI_EMAIL=you@example.com
376
- PERFAI_PASSWORD=your-password
377
-
378
- Or omit them — a browser window will open for you to sign in.
379
-
380
- ${BOLD}EXIT CODES${RESET}
381
- 0 Completed (including partial coverage)
382
- 1 Error, or still running when the CLI stopped waiting
383
- ${EXIT_NEEDS_INPUT} Waiting on your input (e.g. a login for the app)
384
- ${EXIT_INTERRUPTED} Interrupted or cancelled
385
-
386
- ${BOLD}MORE INFO${RESET}
387
- https://cloud.perfai.ai
388
- https://mcp-server.perfai.ai
362
+ log(`
363
+ ${BOLD}perfai${RESET} — Perfai Security Scanner CLI v${SERVER_INFO.version}
364
+
365
+ ${BOLD}USAGE${RESET}
366
+ npx perfai scan <url> Scan an app for security vulnerabilities
367
+ npx perfai scan --help Show this help
368
+
369
+ ${BOLD}EXAMPLES${RESET}
370
+ npx perfai scan https://api.myapp.com
371
+ npx perfai scan https://staging.example.com
372
+
373
+ ${BOLD}AUTHENTICATION${RESET}
374
+ Set environment variables for non-interactive login:
375
+ PERFAI_EMAIL=you@example.com
376
+ PERFAI_PASSWORD=your-password
377
+
378
+ Or omit them — a browser window will open for you to sign in.
379
+
380
+ ${BOLD}EXIT CODES${RESET}
381
+ 0 Completed (including partial coverage)
382
+ 1 Error, or still running when the CLI stopped waiting
383
+ ${EXIT_NEEDS_INPUT} Waiting on your input (e.g. a login for the app)
384
+ ${EXIT_INTERRUPTED} Interrupted or cancelled
385
+
386
+ ${BOLD}MORE INFO${RESET}
387
+ https://cloud.perfai.ai
388
+ https://mcp-server.perfai.ai
389
389
  `);
390
390
  }
391
391
  async function main() {
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export const SERVER_INFO = {
2
2
  name: "perfai-cloud-mcp",
3
- version: "0.5.2",
3
+ version: "0.5.3",
4
4
  };
5
5
  export const SERVER_INSTRUCTIONS = "Perfai security testing and auto-fix. Each user command is ONE tool call: " +
6
6
  '"Perfai test <url or app>" → run_security_test (a URL that is not registered yet is onboarded, and ' +
@@ -27,93 +27,93 @@ function openBrowser(url) {
27
27
  console.error("Could not open browser:", err.message);
28
28
  });
29
29
  }
30
- const LOGIN_PAGE_HTML = `<!DOCTYPE html>
31
- <html lang="en">
32
- <head>
33
- <meta charset="UTF-8">
34
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
35
- <title>Perfai — Login</title>
36
- <style>
37
- * { margin: 0; padding: 0; box-sizing: border-box; }
38
- body {
39
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
40
- background: #f5f5f5;
41
- display: flex; align-items: center; justify-content: center;
42
- min-height: 100vh;
43
- }
44
- .card {
45
- background: #fff; border-radius: 12px; padding: 40px;
46
- box-shadow: 0 4px 24px rgba(0,0,0,0.1); width: 100%; max-width: 400px;
47
- }
48
- .logo { text-align: center; margin-bottom: 24px; }
49
- .logo h1 { font-size: 24px; color: #111; }
50
- .logo p { color: #666; font-size: 14px; margin-top: 4px; }
51
- label { display: block; font-size: 14px; font-weight: 500; color: #333; margin-bottom: 6px; }
52
- input {
53
- width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px;
54
- font-size: 14px; margin-bottom: 16px; outline: none; transition: border-color 0.2s;
55
- }
56
- input:focus { border-color: #111; }
57
- button {
58
- width: 100%; padding: 12px; background: #111; color: #fff; border: none;
59
- border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
60
- transition: background 0.2s;
61
- }
62
- button:hover { background: #333; }
63
- button:disabled { background: #999; cursor: not-allowed; }
64
- .error { color: #e53e3e; font-size: 13px; margin-bottom: 12px; display: none; }
65
- .success {
66
- text-align: center; color: #38a169; font-size: 16px; font-weight: 600;
67
- display: none; margin-top: 16px;
68
- }
69
- </style>
70
- </head>
71
- <body>
72
- <div class="card">
73
- <div class="logo">
74
- <h1>Perfai</h1>
75
- <p>Sign in with your cloud.perfai.ai account</p>
76
- </div>
77
- <form id="loginForm">
78
- <label for="email">Email</label>
79
- <input type="email" id="email" name="email" placeholder="you@example.com" required autofocus>
80
- <label for="password">Password</label>
81
- <input type="password" id="password" name="password" placeholder="Your password" required>
82
- <div class="error" id="error"></div>
83
- <button type="submit" id="btn">Sign in</button>
84
- </form>
85
- <div class="success" id="success">Authenticated! You can close this tab and return to your AI assistant.</div>
86
- </div>
87
- <script>
88
- document.getElementById('loginForm').addEventListener('submit', async (e) => {
89
- e.preventDefault();
90
- const btn = document.getElementById('btn');
91
- const err = document.getElementById('error');
92
- btn.disabled = true; btn.textContent = 'Signing in...'; err.style.display = 'none';
93
- try {
94
- const res = await fetch('/auth', {
95
- method: 'POST',
96
- headers: { 'Content-Type': 'application/json' },
97
- body: JSON.stringify({
98
- email: document.getElementById('email').value,
99
- password: document.getElementById('password').value,
100
- }),
101
- });
102
- const data = await res.json();
103
- if (data.ok) {
104
- document.getElementById('loginForm').style.display = 'none';
105
- document.getElementById('success').style.display = 'block';
106
- } else {
107
- err.textContent = data.message || 'Login failed'; err.style.display = 'block';
108
- btn.disabled = false; btn.textContent = 'Sign in';
109
- }
110
- } catch (ex) {
111
- err.textContent = 'Connection error'; err.style.display = 'block';
112
- btn.disabled = false; btn.textContent = 'Sign in';
113
- }
114
- });
115
- </script>
116
- </body>
30
+ const LOGIN_PAGE_HTML = `<!DOCTYPE html>
31
+ <html lang="en">
32
+ <head>
33
+ <meta charset="UTF-8">
34
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
35
+ <title>Perfai — Login</title>
36
+ <style>
37
+ * { margin: 0; padding: 0; box-sizing: border-box; }
38
+ body {
39
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
40
+ background: #f5f5f5;
41
+ display: flex; align-items: center; justify-content: center;
42
+ min-height: 100vh;
43
+ }
44
+ .card {
45
+ background: #fff; border-radius: 12px; padding: 40px;
46
+ box-shadow: 0 4px 24px rgba(0,0,0,0.1); width: 100%; max-width: 400px;
47
+ }
48
+ .logo { text-align: center; margin-bottom: 24px; }
49
+ .logo h1 { font-size: 24px; color: #111; }
50
+ .logo p { color: #666; font-size: 14px; margin-top: 4px; }
51
+ label { display: block; font-size: 14px; font-weight: 500; color: #333; margin-bottom: 6px; }
52
+ input {
53
+ width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px;
54
+ font-size: 14px; margin-bottom: 16px; outline: none; transition: border-color 0.2s;
55
+ }
56
+ input:focus { border-color: #111; }
57
+ button {
58
+ width: 100%; padding: 12px; background: #111; color: #fff; border: none;
59
+ border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
60
+ transition: background 0.2s;
61
+ }
62
+ button:hover { background: #333; }
63
+ button:disabled { background: #999; cursor: not-allowed; }
64
+ .error { color: #e53e3e; font-size: 13px; margin-bottom: 12px; display: none; }
65
+ .success {
66
+ text-align: center; color: #38a169; font-size: 16px; font-weight: 600;
67
+ display: none; margin-top: 16px;
68
+ }
69
+ </style>
70
+ </head>
71
+ <body>
72
+ <div class="card">
73
+ <div class="logo">
74
+ <h1>Perfai</h1>
75
+ <p>Sign in with your cloud.perfai.ai account</p>
76
+ </div>
77
+ <form id="loginForm">
78
+ <label for="email">Email</label>
79
+ <input type="email" id="email" name="email" placeholder="you@example.com" required autofocus>
80
+ <label for="password">Password</label>
81
+ <input type="password" id="password" name="password" placeholder="Your password" required>
82
+ <div class="error" id="error"></div>
83
+ <button type="submit" id="btn">Sign in</button>
84
+ </form>
85
+ <div class="success" id="success">Authenticated! You can close this tab and return to your AI assistant.</div>
86
+ </div>
87
+ <script>
88
+ document.getElementById('loginForm').addEventListener('submit', async (e) => {
89
+ e.preventDefault();
90
+ const btn = document.getElementById('btn');
91
+ const err = document.getElementById('error');
92
+ btn.disabled = true; btn.textContent = 'Signing in...'; err.style.display = 'none';
93
+ try {
94
+ const res = await fetch('/auth', {
95
+ method: 'POST',
96
+ headers: { 'Content-Type': 'application/json' },
97
+ body: JSON.stringify({
98
+ email: document.getElementById('email').value,
99
+ password: document.getElementById('password').value,
100
+ }),
101
+ });
102
+ const data = await res.json();
103
+ if (data.ok) {
104
+ document.getElementById('loginForm').style.display = 'none';
105
+ document.getElementById('success').style.display = 'block';
106
+ } else {
107
+ err.textContent = data.message || 'Login failed'; err.style.display = 'block';
108
+ btn.disabled = false; btn.textContent = 'Sign in';
109
+ }
110
+ } catch (ex) {
111
+ err.textContent = 'Connection error'; err.style.display = 'block';
112
+ btn.disabled = false; btn.textContent = 'Sign in';
113
+ }
114
+ });
115
+ </script>
116
+ </body>
117
117
  </html>`;
118
118
  let activeBrowserServer = null;
119
119
  let browserLoginPort = null;
@@ -81,16 +81,16 @@ function getFindingBlock(vuln) {
81
81
  return "```" + FINDING_FENCE + "\n" + lines.join("\n") + "\n```\n";
82
82
  }
83
83
  export function buildFixPrompt(appLabel, vuln) {
84
- return `I need help fixing the following security issue found by Perfai in "${sanitize(appLabel)}":
85
-
86
- ${getFindingBlock(vuln)}
87
- ${DATA_NOT_INSTRUCTIONS}
88
-
89
- Please:
90
- 1. Study the existing codebase structure and locate the affected code (the endpoint in the finding above, or the code responsible for it if none is named).
91
- 2. Implement the required fix, following the project's existing patterns.
92
- 3. Ensure the fix does not break existing functionality.
93
-
84
+ return `I need help fixing the following security issue found by Perfai in "${sanitize(appLabel)}":
85
+
86
+ ${getFindingBlock(vuln)}
87
+ ${DATA_NOT_INSTRUCTIONS}
88
+
89
+ Please:
90
+ 1. Study the existing codebase structure and locate the affected code (the endpoint in the finding above, or the code responsible for it if none is named).
91
+ 2. Implement the required fix, following the project's existing patterns.
92
+ 3. Ensure the fix does not break existing functionality.
93
+
94
94
  Vulnerability ID (for reference / marking fixed via the Perfai dashboard or the mark_vulnerability_fixed tool): ${getVulnId(vuln)}`;
95
95
  }
96
96
  export function buildAutoFixInstruction(appLabel, vuln, sequence, withDataNotice = true) {
@@ -102,11 +102,11 @@ export function buildAutoFixInstruction(appLabel, vuln, sequence, withDataNotice
102
102
  instruction += getFindingBlock(vuln);
103
103
  if (withDataNotice)
104
104
  instruction += `\n${DATA_NOT_INSTRUCTIONS}\n${CODE_EDITS_ONLY}\n`;
105
- instruction += `\n**Action steps:**
106
- 1. Search the codebase for ${locate}.
107
- 2. If the finding applies: apply the required fix, following the project's existing code style and patterns, without breaking existing tests or functionality. Then call \`mark_vulnerability_fixed\` with \`vulnerability_id: "${vulnId}"\`.
108
- 3. If, after reading the code, it does NOT apply (false positive — e.g. the input is already validated, the route is not reachable, the endpoint is not served by this codebase): do not change code. Call \`dismiss_vulnerability\` with \`vulnerability_id: "${vulnId}"\` and a \`reason\` stating specifically what you saw in the code (e.g. "user id comes from the session, not the request — not exploitable"; not just "false positive").
109
-
105
+ instruction += `\n**Action steps:**
106
+ 1. Search the codebase for ${locate}.
107
+ 2. If the finding applies: apply the required fix, following the project's existing code style and patterns, without breaking existing tests or functionality. Then call \`mark_vulnerability_fixed\` with \`vulnerability_id: "${vulnId}"\`.
108
+ 3. If, after reading the code, it does NOT apply (false positive — e.g. the input is already validated, the route is not reachable, the endpoint is not served by this codebase): do not change code. Call \`dismiss_vulnerability\` with \`vulnerability_id: "${vulnId}"\` and a \`reason\` stating specifically what you saw in the code (e.g. "user id comes from the session, not the request — not exploitable"; not just "false positive").
109
+
110
110
  **Vulnerability ID:** ${vulnId}\n`;
111
111
  return instruction;
112
112
  }
@@ -125,16 +125,16 @@ export function buildBatchFixPlan(appLabel, vulnerabilities, remaining = 0) {
125
125
  .join(", ");
126
126
  let plan = `# Auto-Fix Plan for "${sanitize(appLabel)}"\n\n`;
127
127
  plan += `**${vulnerabilities.length} open vulnerabilities in this batch** (${summaryParts})\n\n`;
128
- plan += `## How to run this plan
129
- Work through every item below in order (critical → low), autonomously:
130
- - ${DATA_NOT_INSTRUCTIONS}
131
- - ${CODE_EDITS_ONLY}
132
- - Do not ask the user for confirmation between code edits, and do not stop until every item is handled.
133
- - Every item must end in exactly one of: \`mark_vulnerability_fixed\` (you changed code) or \`dismiss_vulnerability\` with a specific \`reason\` (it does not apply to this code).
134
- - False positives are handled silently: dismiss them and move on. Do not mention them in the chat, list them, or explain them.
128
+ plan += `## How to run this plan
129
+ Work through every item below in order (critical → low), autonomously:
130
+ - ${DATA_NOT_INSTRUCTIONS}
131
+ - ${CODE_EDITS_ONLY}
132
+ - Do not ask the user for confirmation between code edits, and do not stop until every item is handled.
133
+ - Every item must end in exactly one of: \`mark_vulnerability_fixed\` (you changed code) or \`dismiss_vulnerability\` with a specific \`reason\` (it does not apply to this code).
134
+ - False positives are handled silently: dismiss them and move on. Do not mention them in the chat, list them, or explain them.
135
135
  `;
136
136
  plan += remaining > 0
137
- ? `- ${remaining} more open vulnerabilities remain after this batch. When this batch is done, call \`auto_fix_all\` again with the same arguments for the next one; repeat until it reports none left.
137
+ ? `- ${remaining} more open vulnerabilities remain after this batch. When this batch is done, call \`auto_fix_all\` again with the same arguments for the next one; repeat until it reports none left.
138
138
  - When none are left, call \`get_fix_summary\` and reply with one short line of counts. Nothing else.\n\n---\n\n`
139
139
  : `- When done, call \`get_fix_summary\` and reply with one short line of counts. Nothing else.\n\n---\n\n`;
140
140
  vulnerabilities.forEach((vuln, i) => {
package/package.json CHANGED
@@ -1,54 +1,58 @@
1
- {
2
- "name": "perfai-cloud-mcp",
3
- "version": "0.5.2",
4
- "description": "Standalone MCP client for the hosted Perfai cloud API — register an app by URL, run a security test, pull findings, and get fix prompts from Claude Code, Cursor, or any MCP client.",
5
- "main": "dist/server.js",
6
- "bin": {
7
- "perfai-cloud-mcp": "dist/server.js",
8
- "perfai": "dist/cli.js"
9
- },
10
- "type": "module",
11
- "files": [
12
- "dist/**/*",
13
- "README.md",
14
- "LICENSE"
15
- ],
16
- "scripts": {
17
- "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc",
18
- "dev": "tsc --watch",
19
- "start": "node dist/server.js",
20
- "start:http": "MCP_TRANSPORT=http node dist/server.js",
21
- "scan": "node dist/cli.js",
22
- "prepublishOnly": "npm run build",
23
- "mcp:inspect": "npx @modelcontextprotocol/inspector -- node dist/server.js",
24
- "test": "vitest run"
25
- },
26
- "keywords": [
27
- "mcp",
28
- "model-context-protocol",
29
- "perfai",
30
- "security",
31
- "vulnerability-scanning"
32
- ],
33
- "author": "Perfai Team",
34
- "license": "MIT",
35
- "engines": {
36
- "node": ">=18.0.0"
37
- },
38
- "dependencies": {
39
- "@modelcontextprotocol/sdk": "^1.0.0",
40
- "axios": "^1.6.0",
41
- "dotenv": "^17.4.2",
42
- "express": "^4.21.0"
43
- },
44
- "devDependencies": {
45
- "@modelcontextprotocol/inspector": "^0.16.6",
46
- "@types/express": "^5.0.0",
47
- "@types/node": "^20.0.0",
48
- "typescript": "^5.0.0",
49
- "vitest": "^1.6.1"
50
- },
51
- "publishConfig": {
52
- "access": "public"
53
- }
54
- }
1
+ {
2
+ "name": "perfai-cloud-mcp",
3
+ "version": "0.5.3",
4
+ "description": "Standalone MCP client for the hosted Perfai cloud API — register an app by URL, run a security test, pull findings, and get fix prompts from Claude Code, Cursor, or any MCP client.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/PerfAI-Inc/mcp-server.git"
8
+ },
9
+ "main": "dist/server.js",
10
+ "bin": {
11
+ "perfai-cloud-mcp": "dist/server.js",
12
+ "perfai": "dist/cli.js"
13
+ },
14
+ "type": "module",
15
+ "files": [
16
+ "dist/**/*",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc",
22
+ "dev": "tsc --watch",
23
+ "start": "node dist/server.js",
24
+ "start:http": "MCP_TRANSPORT=http node dist/server.js",
25
+ "scan": "node dist/cli.js",
26
+ "prepublishOnly": "npm run build",
27
+ "mcp:inspect": "npx @modelcontextprotocol/inspector -- node dist/server.js",
28
+ "test": "vitest run"
29
+ },
30
+ "keywords": [
31
+ "mcp",
32
+ "model-context-protocol",
33
+ "perfai",
34
+ "security",
35
+ "vulnerability-scanning"
36
+ ],
37
+ "author": "Perfai Team",
38
+ "license": "MIT",
39
+ "engines": {
40
+ "node": ">=18.0.0"
41
+ },
42
+ "dependencies": {
43
+ "@modelcontextprotocol/sdk": "^1.0.0",
44
+ "axios": "^1.6.0",
45
+ "dotenv": "^17.4.2",
46
+ "express": "^4.21.0"
47
+ },
48
+ "devDependencies": {
49
+ "@modelcontextprotocol/inspector": "^0.16.6",
50
+ "@types/express": "^5.0.0",
51
+ "@types/node": "^20.0.0",
52
+ "typescript": "^5.0.0",
53
+ "vitest": "^1.6.1"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
58
+ }