perfai-cloud-mcp 0.5.2 → 0.7.2
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 +289 -285
- package/dist/auth/bearerAuth.js +103 -19
- package/dist/auth/oauthFlow.js +10 -10
- package/dist/auth/tokenValidator.js +3 -2
- package/dist/cli.js +46 -46
- package/dist/client/apiClient.js +33 -9
- package/dist/client/authManager.js +28 -0
- package/dist/client/errors.js +11 -0
- package/dist/client/relay.js +61 -0
- package/dist/config.js +19 -1
- package/dist/http.js +125 -0
- package/dist/mcpServer.js +129 -0
- package/dist/server.js +18 -207
- package/dist/tools/protected/autoFix.js +4 -3
- package/dist/tools/protected/autoFixAll.js +15 -7
- package/dist/tools/protected/getFixSummary.js +2 -2
- package/dist/tools/protected/getVulnerabilities.js +51 -11
- package/dist/tools/protected/registerApp.js +3 -1
- package/dist/tools/protected/runSecurityTest.js +51 -6
- package/dist/tools/public/login.js +87 -87
- package/dist/utils/clientInfo.js +8 -0
- package/dist/utils/promptBuilder.js +29 -23
- package/dist/utils/testInfo.js +63 -0
- package/package.json +58 -54
package/README.md
CHANGED
|
@@ -1,285 +1,289 @@
|
|
|
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 "
|
|
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
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
|
211
|
-
|
|
|
212
|
-
| `
|
|
213
|
-
| `GET` | `/
|
|
214
|
-
| `
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
|
234
|
-
|
|
|
235
|
-
| `
|
|
236
|
-
| `
|
|
237
|
-
| `
|
|
238
|
-
| `
|
|
239
|
-
| `
|
|
240
|
-
| `
|
|
241
|
-
| `
|
|
242
|
-
| `
|
|
243
|
-
| `
|
|
244
|
-
| `
|
|
245
|
-
| `
|
|
246
|
-
| `
|
|
247
|
-
| `
|
|
248
|
-
| `
|
|
249
|
-
| `
|
|
250
|
-
| `
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
|
260
|
-
|
|
|
261
|
-
| **
|
|
262
|
-
|
|
|
263
|
-
| **
|
|
264
|
-
| **
|
|
265
|
-
|
|
|
266
|
-
|
|
|
267
|
-
| **
|
|
268
|
-
|
|
|
269
|
-
| **`
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
-
|
|
279
|
-
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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. Free-plan findings hidden beyond the top 5 are left out and counted. |
|
|
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 "Perfai is setting up <App> and will run its first test automatically. This takes up to 20 minutes.", then where the completion email goes (when the session knows the email) and 'Say "perfai status" to check.' |
|
|
73
|
+
| `perfai test` (onboarded app) | Starts a new security test. Replies "Test started — ID <id>.", the last test's open issue count, and "Perfai emails the app's owner when it finishes." |
|
|
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 under "Last test: <YYYY-MM-DD HH:mm UTC> · Open: N (c critical, h high, m medium, l low)", or "No completed test yet.". While a test runs: "A test is running now. Last completed test: <date>." (the findings show when it finishes). During onboarding: "A test is running now. Last completed test: none." once the first test has started, else that the app is still onboarding. On the free plan only the top 5 are listed in full, followed by "+N more open issues are hidden on the free plan." |
|
|
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
|
+
| `MCP_RESOURCE_URL` | No | — | HTTP only. This server's public MCP URL (`https://mcp.perfai.ai/mcp` on prod, `https://mcp-server.perfai.ai/mcp` on dev). Turns on OAuth sign-in for MCP clients such as Lovable: the protected-resource metadata, the `WWW-Authenticate` challenge, and access tokens whose audience is this URL. Unset: OAuth sign-in is off |
|
|
199
|
+
| `WEBUI_CLIENT_IDS` | No | — | HTTP only. Comma-separated audience(s) of the Perfai web app's id_tokens (WebApp-API's `AUTH0_AUDIENCE`). Only these JWTs, besides MCP access tokens, are accepted as a bearer. Unset: web-app id_tokens are refused |
|
|
200
|
+
|
|
201
|
+
### Deploy with Docker
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
docker build -t perfai-mcp .
|
|
205
|
+
docker run -p 3000:3000 -e MCP_TRANSPORT=http perfai-mcp
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Endpoints (HTTP mode)
|
|
209
|
+
|
|
210
|
+
| Method | Path | Description |
|
|
211
|
+
| --- | --- | --- |
|
|
212
|
+
| `POST` | `/mcp` | MCP JSON-RPC requests |
|
|
213
|
+
| `GET` | `/mcp` | SSE stream (server-initiated messages) |
|
|
214
|
+
| `DELETE` | `/mcp` | Session termination |
|
|
215
|
+
| `GET` | `/.well-known/oauth-protected-resource` (also `…/mcp`) | OAuth protected-resource metadata (RFC 9728): where MCP clients sign in. No auth. Only when `MCP_RESOURCE_URL` is set |
|
|
216
|
+
| `GET` | `/health` | Health check — `{"status":"ok"}` only |
|
|
217
|
+
| `GET` | `/` | `{"status":"ok"}` only. The running version is in the MCP `initialize` reply (`serverInfo.version`). |
|
|
218
|
+
|
|
219
|
+
### Test with MCP Inspector
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npm run mcp:inspect
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Opens the Inspector UI at `http://localhost:6274` where you can test tools interactively.
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## API Mapping
|
|
230
|
+
|
|
231
|
+
Every tool maps directly to a Perfai cloud API endpoint:
|
|
232
|
+
|
|
233
|
+
| Tool | API Endpoint |
|
|
234
|
+
| --- | --- |
|
|
235
|
+
| `login` | `POST /api/v1/auth/token` |
|
|
236
|
+
| `manage_organizations` | `GET /api/v1/org-users/get_users_orgs` (selected org is then sent as the `X-Org-ID` header on app requests) |
|
|
237
|
+
| `register_app` | `POST /v1/apps` |
|
|
238
|
+
| `check_app_status` | `GET /v1/apps/{appId}` |
|
|
239
|
+
| `list_apps` | `GET /v1/apps` |
|
|
240
|
+
| `select_app` | `GET /v1/apps/{appId}` |
|
|
241
|
+
| `submit_app_credentials` | `POST /v1/apps/{appId}/account-setup` |
|
|
242
|
+
| `run_security_test` | `POST /v1/apps/{appId}/security-agent` |
|
|
243
|
+
| `check_task_status` | `GET /v1/tasks/{taskId}` |
|
|
244
|
+
| `get_vulnerabilities` | `GET /v1/apps/{appId}/vulnerabilities` (`status` → `isFixed` / `isDismissed`) |
|
|
245
|
+
| `suggest_fix` | Local prompt builder (no API call) |
|
|
246
|
+
| `auto_fix` | Local prompt builder (no API call) |
|
|
247
|
+
| `auto_fix_all` | `GET /v1/apps/{appId}/vulnerabilities` + local prompt builder |
|
|
248
|
+
| `get_fix_summary` | `GET /v1/apps/{appId}/vulnerabilities` — default (with `dismissedCount`), `isFixed=true` and `isDismissed=true` — merged locally |
|
|
249
|
+
| `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` (`reason` → `comment`) |
|
|
250
|
+
| `reopen_vulnerability` | `POST /v1/vulnerabilities/{id}/reopen` |
|
|
251
|
+
| `mark_vulnerability_fixed` | `POST /v1/vulnerabilities/{id}/fix` |
|
|
252
|
+
| `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` |
|
|
253
|
+
| `auth_status` / `logout` | Local session state only (`logout` also clears the selected organization) |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Troubleshooting
|
|
258
|
+
|
|
259
|
+
| Problem | Solution |
|
|
260
|
+
| --- | --- |
|
|
261
|
+
| **Can't connect from ChatGPT** | Make sure the URL ends with `/mcp`: `https://mcp-server.perfai.ai/mcp` |
|
|
262
|
+
| **401 Unauthorized** | Regenerate your access token — make sure email and password are correct |
|
|
263
|
+
| **No tools visible after connecting** | Check that the access token is valid; try refreshing the connection |
|
|
264
|
+
| **"Authentication required" on every tool** | Call `login` first, or verify credentials are set |
|
|
265
|
+
| **`check_app_status` says still onboarding** | Normal for first-time onboarding — it runs in the background; check again later |
|
|
266
|
+
| **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 |
|
|
267
|
+
| **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 |
|
|
268
|
+
| **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 |
|
|
269
|
+
| **`run_security_test` says the app is still onboarding** | Onboarding runs the first security test itself — check again later, then say `perfai issues` |
|
|
270
|
+
| **429 rate limit errors** | Wait for the `Retry-After` duration and try again |
|
|
271
|
+
| **`suggest_fix` / `auto_fix` says "not found"** | Call `get_vulnerabilities` first in the same session to load the findings |
|
|
272
|
+
| **`MCP error -32000: Connection closed`** | Ensure you ran `npm run build` — clients need `dist/server.js`, not `src/` |
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Security
|
|
277
|
+
|
|
278
|
+
- Access tokens are transmitted over **HTTPS** only
|
|
279
|
+
- Every HTTP request is checked: a `pfk_` API key is forwarded to the Perfai API, which validates it; a JWT must be signed by Perfai's Auth0 tenant (RS256), unexpired, from issuer `https://auth.perfai.ai/`, and meant for this server (an MCP access token with the `tests:run` and `issues:read` scopes) or for the Perfai web app. Any other token is refused
|
|
280
|
+
- Validated tokens are cached server-side for up to 30 minutes, never past their expiry
|
|
281
|
+
- Each MCP session gets its own isolated authentication state, bound to its user (OAuth) or its API key. An OAuth session keeps working when the client refreshes its token
|
|
282
|
+
- Without `issues:write`, an OAuth session cannot mark, dismiss or reopen findings
|
|
283
|
+
- No credentials are stored on disk by the MCP server
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
MIT
|