perfai-cloud-mcp 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +17 -8
- package/dist/cli.js +42 -42
- package/dist/client/apiClient.d.ts +8 -1
- package/dist/client/apiClient.d.ts.map +1 -1
- package/dist/client/apiClient.js +26 -1
- package/dist/client/authManager.d.ts +11 -1
- package/dist/client/authManager.d.ts.map +1 -1
- package/dist/client/authManager.js +26 -0
- package/dist/client/types.d.ts +16 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -4
- package/dist/server.js +8 -6
- package/dist/tools/index.d.ts +25 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -1
- package/dist/tools/protected/manageOrganizations.d.ts +26 -0
- package/dist/tools/protected/manageOrganizations.d.ts.map +1 -0
- package/dist/tools/protected/manageOrganizations.js +132 -0
- package/dist/utils/formatters.d.ts +2 -1
- package/dist/utils/formatters.d.ts.map +1 -1
- package/dist/utils/formatters.js +15 -0
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 PerfAI Team
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PerfAI Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Perfai Cloud MCP Server
|
|
2
2
|
|
|
3
|
-
A standalone Model Context Protocol (MCP) server for the **hosted
|
|
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
4
|
|
|
5
5
|
|
|
6
6
|
## Authentication
|
|
@@ -8,7 +8,7 @@ A standalone Model Context Protocol (MCP) server for the **hosted PerfAI cloud A
|
|
|
8
8
|
1. **`PERFAI_TOKEN` env var** — if set, the server starts already authenticated, no `login` call needed. This is the same session token the OAuth/browser flows below produce — paste in one you already have.
|
|
9
9
|
2. **Explicit args** — `login {"email": "...", "password": "..."}`
|
|
10
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
|
|
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
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
13
|
|
|
14
14
|
Once you see "Authenticated!" in the browser, call `login` again to confirm the session server-side.
|
|
@@ -35,10 +35,16 @@ See `.env.example` for the full token/OAuth configuration reference.
|
|
|
35
35
|
### Authentication
|
|
36
36
|
| Tool | Description |
|
|
37
37
|
| --- | --- |
|
|
38
|
-
| `login` | Sign in to
|
|
38
|
+
| `login` | Sign in to Perfai. Opens browser or uses provided credentials. |
|
|
39
39
|
| `auth_status` | Check if you're currently authenticated. |
|
|
40
40
|
| `logout` | Sign out and clear session. |
|
|
41
41
|
|
|
42
|
+
### Organization Management
|
|
43
|
+
| Tool | Description |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `manage_organizations` | List the organizations (tenants) your account belongs to and switch between them. Actions: `list` (default), `select` (by `sequence` or `org_id`), `refresh`. |
|
|
46
|
+
|
|
47
|
+
|
|
42
48
|
### App Management
|
|
43
49
|
| Tool | Description |
|
|
44
50
|
| --- | --- |
|
|
@@ -105,6 +111,8 @@ Here are some things you can say to your AI assistant:
|
|
|
105
111
|
| **Fix everything** | *"Auto-fix all vulnerabilities for my current app."* |
|
|
106
112
|
| **Fix one issue** | *"Show me how to fix vulnerability #2."* |
|
|
107
113
|
| **Check progress** | *"Show me the fix summary for my app."* |
|
|
114
|
+
| **List organizations** | *"List my organizations."* |
|
|
115
|
+
| **Switch organization** | *"Switch to the second organization, then list my apps."* |
|
|
108
116
|
| **List my apps** | *"List all my registered apps."* |
|
|
109
117
|
| **Switch apps** | *"Select the app with URL https://other-app.com."* |
|
|
110
118
|
| **Dismiss a finding** | *"Dismiss vulnerability #3 — it's a false positive."* |
|
|
@@ -153,7 +161,7 @@ $env:MCP_TRANSPORT="http"; node dist/server.js
|
|
|
153
161
|
| `PERFAI_EMAIL` | No | — | Auto-login email (for local/stdio mode) |
|
|
154
162
|
| `PERFAI_PASSWORD` | No | — | Auto-login password (for local/stdio mode) |
|
|
155
163
|
| `AUTH0_DOMAIN` | No | `auth.perfai.ai` | Auth0 tenant domain used for OAuth PKCE login and HTTP bearer-token validation |
|
|
156
|
-
| `AUTH0_CLIENT_ID` | No | *(
|
|
164
|
+
| `AUTH0_CLIENT_ID` | No | *(Perfai's public client)* | Auth0 application client ID for the OAuth PKCE browser flow |
|
|
157
165
|
| `AUTH0_AUDIENCE` | No | — | Auth0 API audience, if your tenant requires one |
|
|
158
166
|
| `OAUTH_CALLBACK_PORT` | No | `5173` | Local port the OAuth flow listens on for the Auth0 redirect |
|
|
159
167
|
| `OAUTH_SCOPES` | No | `openid profile email offline_access` | Scopes requested during OAuth login |
|
|
@@ -188,11 +196,12 @@ Opens the Inspector UI at `http://localhost:6274` where you can test tools inter
|
|
|
188
196
|
|
|
189
197
|
## API Mapping
|
|
190
198
|
|
|
191
|
-
Every tool maps directly to a
|
|
199
|
+
Every tool maps directly to a Perfai cloud API endpoint:
|
|
192
200
|
|
|
193
201
|
| Tool | API Endpoint |
|
|
194
202
|
| --- | --- |
|
|
195
203
|
| `login` | `POST /api/v1/auth/token` |
|
|
204
|
+
| `manage_organizations` | `GET /api/v1/org-users/get_users_orgs` (selected org is then sent as the `X-Org-ID` header on app requests) |
|
|
196
205
|
| `register_app` | `POST /v1/apps` |
|
|
197
206
|
| `check_app_status` | `GET /v1/apps/{appId}` |
|
|
198
207
|
| `list_apps` | `GET /v1/apps` |
|
|
@@ -208,7 +217,7 @@ Every tool maps directly to a PerfAI cloud API endpoint:
|
|
|
208
217
|
| `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` |
|
|
209
218
|
| `reopen_vulnerability` | `POST /v1/vulnerabilities/{id}/reopen` |
|
|
210
219
|
| `mark_vulnerability_fixed` | `POST /v1/vulnerabilities/{id}/fix` |
|
|
211
|
-
| `auth_status` / `logout` | Local session state only |
|
|
220
|
+
| `auth_status` / `logout` | Local session state only (`logout` also clears the selected organization) |
|
|
212
221
|
|
|
213
222
|
---
|
|
214
223
|
|
|
@@ -231,7 +240,7 @@ Every tool maps directly to a PerfAI cloud API endpoint:
|
|
|
231
240
|
## Security
|
|
232
241
|
|
|
233
242
|
- Access tokens are transmitted over **HTTPS** only
|
|
234
|
-
- Tokens are validated against the
|
|
243
|
+
- Tokens are validated against the Perfai cloud auth API on every new session
|
|
235
244
|
- Validated tokens are cached server-side for 30 minutes to reduce auth API calls
|
|
236
245
|
- Each MCP session gets its own isolated authentication state
|
|
237
246
|
- No credentials are stored on disk by the MCP server
|
package/dist/cli.js
CHANGED
|
@@ -54,25 +54,25 @@ function openBrowser(url) {
|
|
|
54
54
|
: `xdg-open "${url}"`;
|
|
55
55
|
exec(cmd, () => { });
|
|
56
56
|
}
|
|
57
|
-
const LOGIN_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
58
|
-
<title>
|
|
59
|
-
*{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}
|
|
60
|
-
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);width:100%;max-width:400px}
|
|
61
|
-
.logo{text-align:center;margin-bottom:24px}.logo h1{font-size:24px;color:#111}.logo p{color:#666;font-size:14px;margin-top:4px}
|
|
62
|
-
label{display:block;font-size:14px;font-weight:500;color:#333;margin-bottom:6px}
|
|
63
|
-
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}
|
|
64
|
-
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}
|
|
65
|
-
.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}
|
|
66
|
-
</style></head><body><div class="c"><div class="logo"><h1>
|
|
67
|
-
<form id="f"><label for="e">Email</label><input type="email" id="e" placeholder="you@example.com" required autofocus>
|
|
68
|
-
<label for="p">Password</label><input type="password" id="p" placeholder="Your password" required>
|
|
69
|
-
<div class="err" id="x"></div><button type="submit" id="b">Sign in</button></form>
|
|
70
|
-
<div class="ok" id="s">Authenticated! You can close this tab.</div></div>
|
|
71
|
-
<script>document.getElementById('f').addEventListener('submit',async e=>{e.preventDefault();const b=document.getElementById('b'),x=document.getElementById('x');
|
|
72
|
-
b.disabled=true;b.textContent='Signing in...';x.style.display='none';try{const r=await fetch('/auth',{method:'POST',headers:{'Content-Type':'application/json'},
|
|
73
|
-
body:JSON.stringify({email:document.getElementById('e').value,password:document.getElementById('p').value})});const d=await r.json();
|
|
74
|
-
if(d.ok){document.getElementById('f').style.display='none';document.getElementById('s').style.display='block'}
|
|
75
|
-
else{x.textContent=d.message||'Login failed';x.style.display='block';b.disabled=false;b.textContent='Sign in'}}
|
|
57
|
+
const LOGIN_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
58
|
+
<title>Perfai Login</title><style>
|
|
59
|
+
*{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}
|
|
60
|
+
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);width:100%;max-width:400px}
|
|
61
|
+
.logo{text-align:center;margin-bottom:24px}.logo h1{font-size:24px;color:#111}.logo p{color:#666;font-size:14px;margin-top:4px}
|
|
62
|
+
label{display:block;font-size:14px;font-weight:500;color:#333;margin-bottom:6px}
|
|
63
|
+
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}
|
|
64
|
+
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}
|
|
65
|
+
.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}
|
|
66
|
+
</style></head><body><div class="c"><div class="logo"><h1>Perfai</h1><p>Sign in with your cloud.perfai.ai account</p></div>
|
|
67
|
+
<form id="f"><label for="e">Email</label><input type="email" id="e" placeholder="you@example.com" required autofocus>
|
|
68
|
+
<label for="p">Password</label><input type="password" id="p" placeholder="Your password" required>
|
|
69
|
+
<div class="err" id="x"></div><button type="submit" id="b">Sign in</button></form>
|
|
70
|
+
<div class="ok" id="s">Authenticated! You can close this tab.</div></div>
|
|
71
|
+
<script>document.getElementById('f').addEventListener('submit',async e=>{e.preventDefault();const b=document.getElementById('b'),x=document.getElementById('x');
|
|
72
|
+
b.disabled=true;b.textContent='Signing in...';x.style.display='none';try{const r=await fetch('/auth',{method:'POST',headers:{'Content-Type':'application/json'},
|
|
73
|
+
body:JSON.stringify({email:document.getElementById('e').value,password:document.getElementById('p').value})});const d=await r.json();
|
|
74
|
+
if(d.ok){document.getElementById('f').style.display='none';document.getElementById('s').style.display='block'}
|
|
75
|
+
else{x.textContent=d.message||'Login failed';x.style.display='block';b.disabled=false;b.textContent='Sign in'}}
|
|
76
76
|
catch{x.textContent='Connection error';x.style.display='block';b.disabled=false;b.textContent='Sign in'}});</script></body></html>`;
|
|
77
77
|
function browserLogin(auth) {
|
|
78
78
|
return new Promise((resolve, reject) => {
|
|
@@ -196,7 +196,7 @@ async function scan(url) {
|
|
|
196
196
|
const TOTAL_STEPS = 5;
|
|
197
197
|
const auth = new AuthManager();
|
|
198
198
|
// ── Step 1: Authenticate ──────────────────────────────────────────
|
|
199
|
-
step(1, TOTAL_STEPS, "Authenticate with
|
|
199
|
+
step(1, TOTAL_STEPS, "Authenticate with Perfai");
|
|
200
200
|
if (auth.hasCredentials()) {
|
|
201
201
|
const sp = spinner("Logging in with environment credentials...");
|
|
202
202
|
await auth.login();
|
|
@@ -332,27 +332,27 @@ async function scan(url) {
|
|
|
332
332
|
/* CLI argument parsing */
|
|
333
333
|
/* ------------------------------------------------------------------ */
|
|
334
334
|
function printHelp() {
|
|
335
|
-
log(`
|
|
336
|
-
${BOLD}perfai${RESET} —
|
|
337
|
-
|
|
338
|
-
${BOLD}USAGE${RESET}
|
|
339
|
-
npx perfai scan <url> Scan an app for security vulnerabilities
|
|
340
|
-
npx perfai scan --help Show this help
|
|
341
|
-
|
|
342
|
-
${BOLD}EXAMPLES${RESET}
|
|
343
|
-
npx perfai scan https://api.myapp.com
|
|
344
|
-
npx perfai scan https://staging.example.com
|
|
345
|
-
|
|
346
|
-
${BOLD}AUTHENTICATION${RESET}
|
|
347
|
-
Set environment variables for non-interactive login:
|
|
348
|
-
PERFAI_EMAIL=you@example.com
|
|
349
|
-
PERFAI_PASSWORD=your-password
|
|
350
|
-
|
|
351
|
-
Or omit them — a browser window will open for you to sign in.
|
|
352
|
-
|
|
353
|
-
${BOLD}MORE INFO${RESET}
|
|
354
|
-
https://cloud.perfai.ai
|
|
355
|
-
https://mcp-server.perfai.ai
|
|
335
|
+
log(`
|
|
336
|
+
${BOLD}perfai${RESET} — Perfai Security Scanner CLI v${SERVER_INFO.version}
|
|
337
|
+
|
|
338
|
+
${BOLD}USAGE${RESET}
|
|
339
|
+
npx perfai scan <url> Scan an app for security vulnerabilities
|
|
340
|
+
npx perfai scan --help Show this help
|
|
341
|
+
|
|
342
|
+
${BOLD}EXAMPLES${RESET}
|
|
343
|
+
npx perfai scan https://api.myapp.com
|
|
344
|
+
npx perfai scan https://staging.example.com
|
|
345
|
+
|
|
346
|
+
${BOLD}AUTHENTICATION${RESET}
|
|
347
|
+
Set environment variables for non-interactive login:
|
|
348
|
+
PERFAI_EMAIL=you@example.com
|
|
349
|
+
PERFAI_PASSWORD=your-password
|
|
350
|
+
|
|
351
|
+
Or omit them — a browser window will open for you to sign in.
|
|
352
|
+
|
|
353
|
+
${BOLD}MORE INFO${RESET}
|
|
354
|
+
https://cloud.perfai.ai
|
|
355
|
+
https://mcp-server.perfai.ai
|
|
356
356
|
`);
|
|
357
357
|
}
|
|
358
358
|
async function main() {
|
|
@@ -375,7 +375,7 @@ async function main() {
|
|
|
375
375
|
fail("URL must start with http:// or https://");
|
|
376
376
|
process.exit(1);
|
|
377
377
|
}
|
|
378
|
-
log(`\n${BOLD}
|
|
378
|
+
log(`\n${BOLD}Perfai Security Scanner${RESET} v${SERVER_INFO.version}\n`);
|
|
379
379
|
try {
|
|
380
380
|
await scan(url);
|
|
381
381
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthManager } from "./authManager.js";
|
|
2
|
-
import type { AppListResponse, AppRecord, TaskRecord, VulnerabilityListResponse } from "./types.js";
|
|
2
|
+
import type { AppListResponse, AppRecord, TaskRecord, UserOrganizationsResponse, VulnerabilityListResponse } from "./types.js";
|
|
3
3
|
export interface RegisterAppInput {
|
|
4
4
|
appUrl: string;
|
|
5
5
|
tenantOneCredentials?: Record<string, unknown>;
|
|
@@ -24,4 +24,11 @@ export declare function getVulnerabilities(auth: AuthManager, appId: string, par
|
|
|
24
24
|
export declare function dismissVulnerability(auth: AuthManager, id: string): Promise<unknown>;
|
|
25
25
|
export declare function reopenVulnerability(auth: AuthManager, id: string): Promise<unknown>;
|
|
26
26
|
export declare function fixVulnerability(auth: AuthManager, id: string): Promise<unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Lists the organizations (tenants) this account belongs to, plus whichever
|
|
29
|
+
* one the account was last using. Separate base URL from the rest of the
|
|
30
|
+
* API (lives under /api/v1, not /v1), so this bypasses the shared request()
|
|
31
|
+
* helper rather than fighting its baseURL binding.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getUserOrganizations(auth: AuthManager): Promise<UserOrganizationsResponse>;
|
|
27
34
|
//# sourceMappingURL=apiClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../src/client/apiClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,yBAAyB,EAC1B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"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9E;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D,OAAO,CAAC,yBAAyB,CAAC,CAMpC;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEpF;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnF;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEhF;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAoBhG"}
|
package/dist/client/apiClient.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { API_BASE_URL } from "../config.js";
|
|
2
|
+
import { API_BASE_URL, ORGANIZATIONS_URL } from "../config.js";
|
|
3
3
|
import { ApiError, formatApiError } from "./errors.js";
|
|
4
4
|
async function request(auth, config, allowReauth = true) {
|
|
5
5
|
if (!auth.isAuthenticated()) {
|
|
@@ -18,6 +18,7 @@ async function request(auth, config, allowReauth = true) {
|
|
|
18
18
|
headers: {
|
|
19
19
|
...config.headers,
|
|
20
20
|
Authorization: `Bearer ${auth.getToken()}`,
|
|
21
|
+
...(auth.getSelectedOrgId() ? { "X-Org-ID": auth.getSelectedOrgId() } : {}),
|
|
21
22
|
"Content-Type": "application/json",
|
|
22
23
|
},
|
|
23
24
|
});
|
|
@@ -79,3 +80,27 @@ export function reopenVulnerability(auth, id) {
|
|
|
79
80
|
export function fixVulnerability(auth, id) {
|
|
80
81
|
return request(auth, { method: "POST", url: `/vulnerabilities/${encodeURIComponent(id)}/fix` });
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Lists the organizations (tenants) this account belongs to, plus whichever
|
|
85
|
+
* one the account was last using. Separate base URL from the rest of the
|
|
86
|
+
* API (lives under /api/v1, not /v1), so this bypasses the shared request()
|
|
87
|
+
* helper rather than fighting its baseURL binding.
|
|
88
|
+
*/
|
|
89
|
+
export async function getUserOrganizations(auth) {
|
|
90
|
+
if (!auth.isAuthenticated()) {
|
|
91
|
+
throw new Error("Not authenticated. Run the `login` tool first.");
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const response = await axios.get(ORGANIZATIONS_URL, {
|
|
95
|
+
headers: { Authorization: `Bearer ${auth.getToken()}` },
|
|
96
|
+
timeout: 30_000,
|
|
97
|
+
});
|
|
98
|
+
return response.data;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (axios.isAxiosError(error)) {
|
|
102
|
+
throw new ApiError(formatApiError(error), error.response?.status, error.response?.data);
|
|
103
|
+
}
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VulnerabilityRecord } from "./types.js";
|
|
1
|
+
import type { OrganizationRecord, VulnerabilityRecord } from "./types.js";
|
|
2
2
|
export type AuthMethod = "credentials" | "token" | "oauth" | "none";
|
|
3
3
|
/**
|
|
4
4
|
* Holds the auth token plus the small amount of "current selection" state
|
|
@@ -17,6 +17,8 @@ export declare class AuthManager {
|
|
|
17
17
|
currentTaskId?: string;
|
|
18
18
|
private vulnCache;
|
|
19
19
|
private vulnCacheAppId?;
|
|
20
|
+
private organizations;
|
|
21
|
+
private selectedOrgId?;
|
|
20
22
|
constructor();
|
|
21
23
|
hasCredentials(): boolean;
|
|
22
24
|
setCredentials(email: string, password: string): void;
|
|
@@ -31,6 +33,14 @@ export declare class AuthManager {
|
|
|
31
33
|
getAuthMethod(): AuthMethod;
|
|
32
34
|
login(email?: string, password?: string): Promise<string>;
|
|
33
35
|
logout(): void;
|
|
36
|
+
/** Returns the cached org list (empty until manage_organizations fetches it). */
|
|
37
|
+
getOrganizations(): OrganizationRecord[];
|
|
38
|
+
getSelectedOrgId(): string | undefined;
|
|
39
|
+
/** Selects an org by ID; subsequent API calls send it as X-Org-ID. */
|
|
40
|
+
setSelectedOrgId(orgId: string): void;
|
|
41
|
+
/** Caches the org list from get_users_orgs; auto-selects currentOrgId, or
|
|
42
|
+
* the first org if nothing is selected yet (mirrors login-time default). */
|
|
43
|
+
setOrganizations(organizations: OrganizationRecord[], currentOrgId?: string): void;
|
|
34
44
|
setCurrentApp(appId: string, appUrl?: string): void;
|
|
35
45
|
/** Caches a vulnerability page (keyed by 1-based sequence number) so tools can refer to "#3". */
|
|
36
46
|
cacheVulnerabilities(appId: string, vulnerabilities: VulnerabilityRecord[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authManager.d.ts","sourceRoot":"","sources":["../../src/client/authManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"authManager.d.ts","sourceRoot":"","sources":["../../src/client/authManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAC,CAAwB;IACtC,OAAO,CAAC,QAAQ,CAAC,CAA2B;IAC5C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,kBAAkB,CAAC,CAAS;IACpC,OAAO,CAAC,UAAU,CAAsB;I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AE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAa5F,kFAAkF;IAClF,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;CAKpE"}
|
|
@@ -18,6 +18,8 @@ export class AuthManager {
|
|
|
18
18
|
currentTaskId;
|
|
19
19
|
vulnCache = new Map();
|
|
20
20
|
vulnCacheAppId;
|
|
21
|
+
organizations = [];
|
|
22
|
+
selectedOrgId;
|
|
21
23
|
constructor() {
|
|
22
24
|
// Auto-load PERFAI_TOKEN if set (headless fallback for Replit/Lovable/Bolt).
|
|
23
25
|
// This takes priority over email/password since it's an existing, validated token.
|
|
@@ -102,6 +104,30 @@ export class AuthManager {
|
|
|
102
104
|
this.currentTaskId = undefined;
|
|
103
105
|
this.vulnCache.clear();
|
|
104
106
|
this.vulnCacheAppId = undefined;
|
|
107
|
+
this.organizations = [];
|
|
108
|
+
this.selectedOrgId = undefined;
|
|
109
|
+
}
|
|
110
|
+
/** Returns the cached org list (empty until manage_organizations fetches it). */
|
|
111
|
+
getOrganizations() {
|
|
112
|
+
return this.organizations;
|
|
113
|
+
}
|
|
114
|
+
getSelectedOrgId() {
|
|
115
|
+
return this.selectedOrgId;
|
|
116
|
+
}
|
|
117
|
+
/** Selects an org by ID; subsequent API calls send it as X-Org-ID. */
|
|
118
|
+
setSelectedOrgId(orgId) {
|
|
119
|
+
this.selectedOrgId = orgId;
|
|
120
|
+
}
|
|
121
|
+
/** Caches the org list from get_users_orgs; auto-selects currentOrgId, or
|
|
122
|
+
* the first org if nothing is selected yet (mirrors login-time default). */
|
|
123
|
+
setOrganizations(organizations, currentOrgId) {
|
|
124
|
+
this.organizations = organizations;
|
|
125
|
+
if (currentOrgId) {
|
|
126
|
+
this.selectedOrgId = currentOrgId;
|
|
127
|
+
}
|
|
128
|
+
else if (!this.selectedOrgId && organizations.length > 0) {
|
|
129
|
+
this.selectedOrgId = organizations[0].org_id;
|
|
130
|
+
}
|
|
105
131
|
}
|
|
106
132
|
setCurrentApp(appId, appUrl) {
|
|
107
133
|
this.currentAppId = appId;
|
package/dist/client/types.d.ts
CHANGED
|
@@ -13,6 +13,22 @@ export interface AppRecord {
|
|
|
13
13
|
statusUrl?: string;
|
|
14
14
|
[key: string]: unknown;
|
|
15
15
|
}
|
|
16
|
+
export interface OrganizationRecord {
|
|
17
|
+
org_id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
orgDetails?: {
|
|
20
|
+
name?: string;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
};
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface UserOrganizationsResponse {
|
|
26
|
+
data?: {
|
|
27
|
+
userOrgs?: OrganizationRecord[];
|
|
28
|
+
currentOrg?: string;
|
|
29
|
+
};
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
16
32
|
export interface AppListResponse {
|
|
17
33
|
total: number;
|
|
18
34
|
page: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,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C;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,mBAAmB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/config.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const SERVER_INFO: {
|
|
|
4
4
|
};
|
|
5
5
|
export declare const AUTH_TOKEN_URL: string;
|
|
6
6
|
export declare const API_BASE_URL: string;
|
|
7
|
+
export declare const ORGANIZATIONS_URL: string;
|
|
7
8
|
export declare const PERFAI_EMAIL: string | undefined;
|
|
8
9
|
export declare const PERFAI_PASSWORD: string | undefined;
|
|
9
10
|
export declare const PERFAI_TOKEN: string | undefined;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;CAGvB,CAAC;AAOF,eAAO,MAAM,cAAc,QAA0C,CAAC;AACtE,eAAO,MAAM,YAAY,QAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW;;;CAGvB,CAAC;AAOF,eAAO,MAAM,cAAc,QAA0C,CAAC;AACtE,eAAO,MAAM,YAAY,QAA2B,CAAC;AAIrD,eAAO,MAAM,iBAAiB,QAAwD,CAAC;AAGvF,eAAO,MAAM,YAAY,oBAA2B,CAAC;AACrD,eAAO,MAAM,eAAe,oBAA8B,CAAC;AAI3D,eAAO,MAAM,YAAY,oBAA2B,CAAC;AAKrD,eAAO,MAAM,YAAY,QAA+C,CAAC;AACzE,eAAO,MAAM,eAAe,QAAoE,CAAC;AACjG,eAAO,MAAM,cAAc,QAAmC,CAAC;AAC/D,eAAO,MAAM,mBAAmB,QAA0D,CAAC;AAC3F,eAAO,MAAM,YAAY,QAAoE,CAAC;AAI9F,eAAO,MAAM,aAAa,OAAQ,CAAC;AACnC,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAC3C,eAAO,MAAM,oBAAoB,QAAiB,CAAC;AACnD,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAS3D,eAAO,MAAM,2BAA2B,OAAQ,CAAC;AACjD,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAE/C,eAAO,MAAM,oBAAoB,aAK/B,CAAC;AAEH,eAAO,MAAM,mBAAmB,aAG9B,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
// Server identity reported to MCP clients.
|
|
2
2
|
export const SERVER_INFO = {
|
|
3
3
|
name: "perfai-cloud-mcp",
|
|
4
|
-
version: "0.
|
|
4
|
+
version: "0.2.0",
|
|
5
5
|
};
|
|
6
|
-
// Host for the hosted
|
|
6
|
+
// Host for the hosted Perfai cloud API. Override for on-premise deployments.
|
|
7
7
|
const API_HOST = process.env.PERFAI_API_HOST || "api.perfai.ai";
|
|
8
8
|
// Per docs.perfai.ai/docs/api/overview: token exchange lives under /api/v1,
|
|
9
9
|
// everything else (apps, tasks, vulnerabilities) lives under /v1.
|
|
10
10
|
export const AUTH_TOKEN_URL = `https://${API_HOST}/api/v1/auth/token`;
|
|
11
11
|
export const API_BASE_URL = `https://${API_HOST}/v1`;
|
|
12
|
+
// Multi-tenant accounts (e.g. SuperAdmin/support) belong to more than one
|
|
13
|
+
// org; app requests are scoped by X-Org-ID, resolved from this endpoint.
|
|
14
|
+
export const ORGANIZATIONS_URL = `https://${API_HOST}/api/v1/org-users/get_users_orgs`;
|
|
12
15
|
// Credentials for non-interactive login (recommended for MCP client configs).
|
|
13
16
|
export const PERFAI_EMAIL = process.env.PERFAI_EMAIL;
|
|
14
17
|
export const PERFAI_PASSWORD = process.env.PERFAI_PASSWORD;
|
|
15
18
|
// Pre-existing token for headless environments (Replit, Lovable, Bolt, CI).
|
|
16
|
-
// Users copy this from the
|
|
19
|
+
// Users copy this from the Perfai console after a normal browser login.
|
|
17
20
|
export const PERFAI_TOKEN = process.env.PERFAI_TOKEN;
|
|
18
21
|
// ── OAuth / Auth0 PKCE configuration ───────────────────────────────
|
|
19
22
|
// Used for the browser-based login flow (Cursor, Claude Code, VS Code, etc.).
|
|
20
|
-
// The PKCE flow produces the same id_token that
|
|
23
|
+
// The PKCE flow produces the same id_token that Perfai's API already accepts.
|
|
21
24
|
export const AUTH0_DOMAIN = process.env.AUTH0_DOMAIN ?? "auth.perfai.ai";
|
|
22
25
|
export const AUTH0_CLIENT_ID = process.env.AUTH0_CLIENT_ID ?? "OxipoJS8EIdpN3KzhVQ280zkKxwzGLfI";
|
|
23
26
|
export const AUTH0_AUDIENCE = process.env.AUTH0_AUDIENCE ?? "";
|
package/dist/server.js
CHANGED
|
@@ -11,7 +11,7 @@ import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } f
|
|
|
11
11
|
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
12
12
|
import { SERVER_INFO } from "./config.js";
|
|
13
13
|
import { AuthManager } from "./client/authManager.js";
|
|
14
|
-
import { PUBLIC_TOOLS, PROTECTED_TOOLS, handleLogin, handleAuthStatus, handleLogout, handleRegisterApp, handleCheckAppStatus, handleListApps, handleSelectApp, handleSubmitAppCredentials, handleRunSecurityTest, handleCheckTaskStatus, handleGetVulnerabilities, handleSuggestFix, handleAutoFix, handleAutoFixAll, handleGetFixSummary, handleDismissVulnerability, handleReopenVulnerability, handleMarkVulnerabilityFixed, } from "./tools/index.js";
|
|
14
|
+
import { PUBLIC_TOOLS, PROTECTED_TOOLS, handleLogin, handleAuthStatus, handleLogout, handleManageOrganizations, handleRegisterApp, handleCheckAppStatus, handleListApps, handleSelectApp, handleSubmitAppCredentials, handleRunSecurityTest, handleCheckTaskStatus, handleGetVulnerabilities, handleSuggestFix, handleAutoFix, handleAutoFixAll, handleGetFixSummary, handleDismissVulnerability, handleReopenVulnerability, handleMarkVulnerabilityFixed, } from "./tools/index.js";
|
|
15
15
|
function createMcpServer(auth) {
|
|
16
16
|
const server = new Server(SERVER_INFO, {
|
|
17
17
|
capabilities: { tools: {} },
|
|
@@ -35,6 +35,8 @@ function createMcpServer(auth) {
|
|
|
35
35
|
switch (name) {
|
|
36
36
|
case "logout":
|
|
37
37
|
return await handleLogout(auth);
|
|
38
|
+
case "manage_organizations":
|
|
39
|
+
return await handleManageOrganizations(auth, args);
|
|
38
40
|
case "register_app":
|
|
39
41
|
return await handleRegisterApp(auth, args);
|
|
40
42
|
case "check_app_status":
|
|
@@ -155,7 +157,7 @@ async function startHttp() {
|
|
|
155
157
|
error: {
|
|
156
158
|
code: -32001,
|
|
157
159
|
message: "Unauthorized: Bearer token required. " +
|
|
158
|
-
"Use your
|
|
160
|
+
"Use your Perfai id_token (from OAuth login or PERFAI_TOKEN) as the bearer value.",
|
|
159
161
|
},
|
|
160
162
|
id: null,
|
|
161
163
|
});
|
|
@@ -214,8 +216,8 @@ async function startHttp() {
|
|
|
214
216
|
error: {
|
|
215
217
|
code: -32001,
|
|
216
218
|
message: "Unrecognized token format. Provide either: " +
|
|
217
|
-
"(1) a
|
|
218
|
-
"(2) PERFAI_TOKEN from your
|
|
219
|
+
"(1) a Perfai id_token from OAuth login, or " +
|
|
220
|
+
"(2) PERFAI_TOKEN from your Perfai console.",
|
|
219
221
|
},
|
|
220
222
|
id: null,
|
|
221
223
|
});
|
|
@@ -315,11 +317,11 @@ async function startHttp() {
|
|
|
315
317
|
status: "running",
|
|
316
318
|
mcp_endpoint: "/mcp",
|
|
317
319
|
auth: {
|
|
318
|
-
primary: "Bearer <id_token> — use your
|
|
320
|
+
primary: "Bearer <id_token> — use your Perfai OAuth token",
|
|
319
321
|
headless: "Set PERFAI_TOKEN env var with your token from https://cloud.perfai.ai",
|
|
320
322
|
deprecated: "base64(email:password) still accepted but will be removed",
|
|
321
323
|
},
|
|
322
|
-
docs: "This is a Model Context Protocol (MCP) server for
|
|
324
|
+
docs: "This is a Model Context Protocol (MCP) server for Perfai. Connect to /mcp from any MCP-compatible client (ChatGPT, Cursor, Claude, etc.).",
|
|
323
325
|
});
|
|
324
326
|
});
|
|
325
327
|
// Health-check endpoint
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { handleLogin } from "./public/login.js";
|
|
2
2
|
import { handleAuthStatus } from "./public/authStatus.js";
|
|
3
3
|
import { handleLogout } from "./protected/logout.js";
|
|
4
|
+
import { handleManageOrganizations } from "./protected/manageOrganizations.js";
|
|
4
5
|
import { handleRegisterApp } from "./protected/registerApp.js";
|
|
5
6
|
import { handleCheckAppStatus } from "./protected/checkAppStatus.js";
|
|
6
7
|
import { handleListApps } from "./protected/listApps.js";
|
|
@@ -53,6 +54,29 @@ export declare const PROTECTED_TOOLS: {
|
|
|
53
54
|
readonly additionalProperties: false;
|
|
54
55
|
};
|
|
55
56
|
};
|
|
57
|
+
readonly manage_organizations: {
|
|
58
|
+
readonly name: "manage_organizations";
|
|
59
|
+
readonly description: string;
|
|
60
|
+
readonly inputSchema: {
|
|
61
|
+
readonly type: "object";
|
|
62
|
+
readonly properties: {
|
|
63
|
+
readonly action: {
|
|
64
|
+
readonly type: "string";
|
|
65
|
+
readonly enum: readonly ["list", "select", "refresh"];
|
|
66
|
+
readonly description: string;
|
|
67
|
+
};
|
|
68
|
+
readonly sequence: {
|
|
69
|
+
readonly type: "number";
|
|
70
|
+
readonly description: "Sequence number from the list output (use instead of org_id)";
|
|
71
|
+
};
|
|
72
|
+
readonly org_id: {
|
|
73
|
+
readonly type: "string";
|
|
74
|
+
readonly description: "Organization ID to select directly";
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
readonly additionalProperties: false;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
56
80
|
readonly register_app: {
|
|
57
81
|
readonly name: "register_app";
|
|
58
82
|
readonly description: string;
|
|
@@ -348,5 +372,5 @@ export declare const PROTECTED_TOOLS: {
|
|
|
348
372
|
};
|
|
349
373
|
};
|
|
350
374
|
};
|
|
351
|
-
export { handleLogin, handleAuthStatus, handleLogout, handleRegisterApp, handleCheckAppStatus, handleListApps, handleSelectApp, handleSubmitAppCredentials, handleRunSecurityTest, handleCheckTaskStatus, handleGetVulnerabilities, handleSuggestFix, handleAutoFix, handleAutoFixAll, handleGetFixSummary, handleDismissVulnerability, handleReopenVulnerability, handleMarkVulnerabilityFixed, };
|
|
375
|
+
export { handleLogin, handleAuthStatus, handleLogout, handleManageOrganizations, handleRegisterApp, handleCheckAppStatus, handleListApps, handleSelectApp, handleSubmitAppCredentials, handleRunSecurityTest, handleCheckTaskStatus, handleGetVulnerabilities, handleSuggestFix, handleAutoFix, handleAutoFixAll, handleGetFixSummary, handleDismissVulnerability, handleReopenVulnerability, handleMarkVulnerabilityFixed, };
|
|
352
376
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AA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;;;;;;;;;;;;;;;;;;;;;;;CAkBlB,CAAC;AAEX,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,EACzB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,0BAA0B,EAC1B,yBAAyB,EACzB,4BAA4B,GAC7B,CAAC"}
|
package/dist/tools/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { loginTool, handleLogin } from "./public/login.js";
|
|
2
2
|
import { authStatusTool, handleAuthStatus } from "./public/authStatus.js";
|
|
3
3
|
import { logoutTool, handleLogout } from "./protected/logout.js";
|
|
4
|
+
import { manageOrganizationsTool, handleManageOrganizations } from "./protected/manageOrganizations.js";
|
|
4
5
|
import { registerAppTool, handleRegisterApp } from "./protected/registerApp.js";
|
|
5
6
|
import { checkAppStatusTool, handleCheckAppStatus } from "./protected/checkAppStatus.js";
|
|
6
7
|
import { listAppsTool, handleListApps } from "./protected/listApps.js";
|
|
@@ -20,6 +21,7 @@ export const PUBLIC_TOOLS = {
|
|
|
20
21
|
};
|
|
21
22
|
export const PROTECTED_TOOLS = {
|
|
22
23
|
logout: logoutTool,
|
|
24
|
+
manage_organizations: manageOrganizationsTool,
|
|
23
25
|
register_app: registerAppTool,
|
|
24
26
|
check_app_status: checkAppStatusTool,
|
|
25
27
|
list_apps: listAppsTool,
|
|
@@ -36,4 +38,4 @@ export const PROTECTED_TOOLS = {
|
|
|
36
38
|
reopen_vulnerability: reopenVulnerabilityTool,
|
|
37
39
|
mark_vulnerability_fixed: markVulnerabilityFixedTool,
|
|
38
40
|
};
|
|
39
|
-
export { handleLogin, handleAuthStatus, handleLogout, handleRegisterApp, handleCheckAppStatus, handleListApps, handleSelectApp, handleSubmitAppCredentials, handleRunSecurityTest, handleCheckTaskStatus, handleGetVulnerabilities, handleSuggestFix, handleAutoFix, handleAutoFixAll, handleGetFixSummary, handleDismissVulnerability, handleReopenVulnerability, handleMarkVulnerabilityFixed, };
|
|
41
|
+
export { handleLogin, handleAuthStatus, handleLogout, handleManageOrganizations, handleRegisterApp, handleCheckAppStatus, handleListApps, handleSelectApp, handleSubmitAppCredentials, handleRunSecurityTest, handleCheckTaskStatus, handleGetVulnerabilities, handleSuggestFix, handleAutoFix, handleAutoFixAll, handleGetFixSummary, handleDismissVulnerability, handleReopenVulnerability, handleMarkVulnerabilityFixed, };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AuthManager } from "../../client/authManager.js";
|
|
2
|
+
export declare const manageOrganizationsTool: {
|
|
3
|
+
readonly name: "manage_organizations";
|
|
4
|
+
readonly description: string;
|
|
5
|
+
readonly inputSchema: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly properties: {
|
|
8
|
+
readonly action: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
readonly enum: readonly ["list", "select", "refresh"];
|
|
11
|
+
readonly description: string;
|
|
12
|
+
};
|
|
13
|
+
readonly sequence: {
|
|
14
|
+
readonly type: "number";
|
|
15
|
+
readonly description: "Sequence number from the list output (use instead of org_id)";
|
|
16
|
+
};
|
|
17
|
+
readonly org_id: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
readonly description: "Organization ID to select directly";
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
readonly additionalProperties: false;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function handleManageOrganizations(auth: AuthManager, args: any): Promise<any>;
|
|
26
|
+
//# sourceMappingURL=manageOrganizations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manageOrganizations.d.ts","sourceRoot":"","sources":["../../../src/tools/protected/manageOrganizations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAK1D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;CA6B1B,CAAC;AAUX,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAwG1F"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { getUserOrganizations } from "../../client/apiClient.js";
|
|
2
|
+
import { formatOrganizations } from "../../utils/formatters.js";
|
|
3
|
+
export const manageOrganizationsTool = {
|
|
4
|
+
name: "manage_organizations",
|
|
5
|
+
description: "🏢 List and switch between organizations (tenants) this account belongs to. " +
|
|
6
|
+
"Needed for multi-org accounts (e.g. SuperAdmin/support) — list_apps / select_app / " +
|
|
7
|
+
"register_app / etc. are all scoped to whichever org is currently selected, so an appId " +
|
|
8
|
+
"belonging to a non-selected org will 404 until you select the right org here. " +
|
|
9
|
+
"Use action=select with sequence (number from the list) or org_id.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
action: {
|
|
14
|
+
type: "string",
|
|
15
|
+
enum: ["list", "select", "refresh"],
|
|
16
|
+
description: "list (default): show orgs, fetching them first if not cached yet. " +
|
|
17
|
+
"select: choose org by sequence or org_id. refresh: re-fetch orgs from the API.",
|
|
18
|
+
},
|
|
19
|
+
sequence: {
|
|
20
|
+
type: "number",
|
|
21
|
+
description: "Sequence number from the list output (use instead of org_id)",
|
|
22
|
+
},
|
|
23
|
+
org_id: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Organization ID to select directly",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
async function fetchAndCacheOrganizations(auth) {
|
|
32
|
+
const data = await getUserOrganizations(auth);
|
|
33
|
+
const organizations = data?.data?.userOrgs ?? [];
|
|
34
|
+
const currentOrgId = data?.data?.currentOrg;
|
|
35
|
+
auth.setOrganizations(organizations, currentOrgId);
|
|
36
|
+
return organizations;
|
|
37
|
+
}
|
|
38
|
+
export async function handleManageOrganizations(auth, args) {
|
|
39
|
+
const action = args?.action ?? "list";
|
|
40
|
+
try {
|
|
41
|
+
if (action === "refresh") {
|
|
42
|
+
const organizations = await fetchAndCacheOrganizations(auth);
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: `🔄 Refreshed — found ${organizations.length} organization${organizations.length === 1 ? "" : "s"}.\n\n` +
|
|
48
|
+
formatOrganizations(organizations, auth.getSelectedOrgId()),
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (action === "select") {
|
|
54
|
+
const sequence = args?.sequence;
|
|
55
|
+
const orgId = args?.org_id;
|
|
56
|
+
if (!sequence && !orgId) {
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: "text",
|
|
61
|
+
text: `❌ Provide a sequence number or org_id when using action=select.\n\n` +
|
|
62
|
+
`**Examples**:\n` +
|
|
63
|
+
`• \`manage_organizations {"action": "select", "sequence": 1}\`\n` +
|
|
64
|
+
`• \`manage_organizations {"action": "select", "org_id": "<id>"}\`\n\n` +
|
|
65
|
+
`Run \`manage_organizations\` first to see the list.`,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
let organizations = auth.getOrganizations();
|
|
71
|
+
if (organizations.length === 0) {
|
|
72
|
+
organizations = await fetchAndCacheOrganizations(auth);
|
|
73
|
+
}
|
|
74
|
+
let selectedOrg;
|
|
75
|
+
if (sequence) {
|
|
76
|
+
selectedOrg = organizations[sequence - 1];
|
|
77
|
+
if (!selectedOrg) {
|
|
78
|
+
return {
|
|
79
|
+
content: [
|
|
80
|
+
{
|
|
81
|
+
type: "text",
|
|
82
|
+
text: `❌ Sequence '${sequence}' not found (${organizations.length} org${organizations.length !== 1 ? "s" : ""} available).\n\n` +
|
|
83
|
+
`Run \`manage_organizations\` to see the list.`,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
selectedOrg = organizations.find((org) => org.org_id === orgId);
|
|
91
|
+
if (!selectedOrg) {
|
|
92
|
+
return {
|
|
93
|
+
content: [
|
|
94
|
+
{
|
|
95
|
+
type: "text",
|
|
96
|
+
text: `❌ Organization '${orgId}' not found in the cached list.\n\n` +
|
|
97
|
+
`Run \`manage_organizations {"action": "refresh"}\` to update it.`,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
auth.setSelectedOrgId(selectedOrg.org_id);
|
|
104
|
+
const name = selectedOrg.orgDetails?.name ?? selectedOrg.name ?? selectedOrg.org_id;
|
|
105
|
+
return {
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
type: "text",
|
|
109
|
+
text: `✅ Organization selected: **${name}** (${selectedOrg.org_id})\n\n` +
|
|
110
|
+
`list_apps / select_app / register_app are now scoped to this org.`,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Default action: list (fetch first if nothing cached yet)
|
|
116
|
+
let organizations = auth.getOrganizations();
|
|
117
|
+
if (organizations.length === 0) {
|
|
118
|
+
organizations = await fetchAndCacheOrganizations(auth);
|
|
119
|
+
}
|
|
120
|
+
return { content: [{ type: "text", text: formatOrganizations(organizations, auth.getSelectedOrgId()) }] };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
return {
|
|
124
|
+
content: [
|
|
125
|
+
{
|
|
126
|
+
type: "text",
|
|
127
|
+
text: `❌ Organization management failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AppRecord, TaskRecord, VulnerabilityRecord } from "../client/types.js";
|
|
1
|
+
import type { AppRecord, OrganizationRecord, TaskRecord, VulnerabilityRecord } from "../client/types.js";
|
|
2
2
|
export declare function formatApp(app: AppRecord): string;
|
|
3
3
|
export declare function formatAppList(apps: AppRecord[], total: number, page: number, pageSize: number): string;
|
|
4
|
+
export declare function formatOrganizations(organizations: OrganizationRecord[], selectedOrgId?: string): string;
|
|
4
5
|
export declare function formatTask(task: TaskRecord): string;
|
|
5
6
|
export declare function formatVulnerability(v: VulnerabilityRecord, sequence: number): string;
|
|
6
7
|
export declare function formatVulnerabilityList(vulnerabilities: VulnerabilityRecord[], total: number, page: number, pageSize: number): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/utils/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/utils/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AASzG,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAQhD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAUtG;AAED,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,kBAAkB,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBvG;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEnD;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAapF;AAED,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,mBAAmB,EAAE,EACtC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,MAAM,CAMR"}
|
package/dist/utils/formatters.js
CHANGED
|
@@ -23,6 +23,21 @@ export function formatAppList(apps, total, page, pageSize) {
|
|
|
23
23
|
.join("\n");
|
|
24
24
|
return `${rows}\n\nPage ${page} — ${apps.length} of ${total} total.`;
|
|
25
25
|
}
|
|
26
|
+
export function formatOrganizations(organizations, selectedOrgId) {
|
|
27
|
+
if (organizations.length === 0) {
|
|
28
|
+
return "No organizations found. Try `manage_organizations {\"action\": \"refresh\"}`.";
|
|
29
|
+
}
|
|
30
|
+
const rows = organizations
|
|
31
|
+
.map((org, i) => {
|
|
32
|
+
const name = org.orgDetails?.name ?? org.name ?? org.org_id;
|
|
33
|
+
const marker = org.org_id === selectedOrgId ? "👉" : " ";
|
|
34
|
+
return `${marker} ${i + 1}. **${name}** (org_id: ${org.org_id})`;
|
|
35
|
+
})
|
|
36
|
+
.join("\n");
|
|
37
|
+
return (`🏢 **Organizations** (${organizations.length})\n\n${rows}\n\n` +
|
|
38
|
+
`Currently selected: ${selectedOrgId ?? "none"}\n` +
|
|
39
|
+
`Use \`manage_organizations {"action": "select", "sequence": N}\` to switch — list_apps/select_app/register_app are scoped to whichever org is selected.`);
|
|
40
|
+
}
|
|
26
41
|
export function formatTask(task) {
|
|
27
42
|
return `🧪 Task ${task.taskId}\n State: ${task.state ?? "UNKNOWN"}`;
|
|
28
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perfai-cloud-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
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
5
|
"main": "dist/server.js",
|
|
6
6
|
"bin": {
|