@performance-agent/mcp-server 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +503 -0
  2. package/dist/index.d.ts +13 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +300 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/tools/code-analyzer/analyzers/javascript-analyzer.d.ts +36 -0
  7. package/dist/tools/code-analyzer/analyzers/javascript-analyzer.d.ts.map +1 -0
  8. package/dist/tools/code-analyzer/analyzers/javascript-analyzer.js +241 -0
  9. package/dist/tools/code-analyzer/analyzers/javascript-analyzer.js.map +1 -0
  10. package/dist/tools/code-analyzer/analyzers/python-analyzer.d.ts +30 -0
  11. package/dist/tools/code-analyzer/analyzers/python-analyzer.d.ts.map +1 -0
  12. package/dist/tools/code-analyzer/analyzers/python-analyzer.js +142 -0
  13. package/dist/tools/code-analyzer/analyzers/python-analyzer.js.map +1 -0
  14. package/dist/tools/code-analyzer/git-helper.d.ts +52 -0
  15. package/dist/tools/code-analyzer/git-helper.d.ts.map +1 -0
  16. package/dist/tools/code-analyzer/git-helper.js +124 -0
  17. package/dist/tools/code-analyzer/git-helper.js.map +1 -0
  18. package/dist/tools/code-analyzer/index.d.ts +45 -0
  19. package/dist/tools/code-analyzer/index.d.ts.map +1 -0
  20. package/dist/tools/code-analyzer/index.js +213 -0
  21. package/dist/tools/code-analyzer/index.js.map +1 -0
  22. package/dist/tools/code-analyzer/types.d.ts +54 -0
  23. package/dist/tools/code-analyzer/types.d.ts.map +1 -0
  24. package/dist/tools/code-analyzer/types.js +5 -0
  25. package/dist/tools/code-analyzer/types.js.map +1 -0
  26. package/dist/tools/function-profiler/index.d.ts +11 -0
  27. package/dist/tools/function-profiler/index.d.ts.map +1 -0
  28. package/dist/tools/function-profiler/index.js +192 -0
  29. package/dist/tools/function-profiler/index.js.map +1 -0
  30. package/dist/tools/function-profiler/javascript-profiler.d.ts +27 -0
  31. package/dist/tools/function-profiler/javascript-profiler.d.ts.map +1 -0
  32. package/dist/tools/function-profiler/javascript-profiler.js +141 -0
  33. package/dist/tools/function-profiler/javascript-profiler.js.map +1 -0
  34. package/dist/tools/function-profiler/python-profiler.d.ts +31 -0
  35. package/dist/tools/function-profiler/python-profiler.d.ts.map +1 -0
  36. package/dist/tools/function-profiler/python-profiler.js +212 -0
  37. package/dist/tools/function-profiler/python-profiler.js.map +1 -0
  38. package/dist/tools/function-profiler/types.d.ts +41 -0
  39. package/dist/tools/function-profiler/types.d.ts.map +1 -0
  40. package/dist/tools/function-profiler/types.js +5 -0
  41. package/dist/tools/function-profiler/types.js.map +1 -0
  42. package/package.json +51 -0
package/README.md ADDED
@@ -0,0 +1,503 @@
1
+ # Performance Agent MCP Server
2
+
3
+ A Model Context Protocol (MCP) server that provides 3 core development tools for VS Code and GitHub Copilot.
4
+
5
+ ## 🎯 Features
6
+
7
+ | Tool | Description |
8
+ |------|-------------|
9
+ | **generateJMXFromSwagger** | Convert Swagger/OpenAPI specs to JMeter performance test scripts |
10
+ | **analyzeCodeComplexity** | Analyze cyclomatic complexity in local git repositories |
11
+ | **profileFunctionPerformance** | Profile function execution time and identify slow functions |
12
+
13
+ ---
14
+
15
+ ## 📦 Installation
16
+
17
+ ### Prerequisites
18
+ - Node.js 18+
19
+ - npm or yarn
20
+ - Git
21
+ - VS Code with GitHub Copilot
22
+
23
+ ### Install Dependencies
24
+
25
+ ```bash
26
+ cd mcp-server
27
+ npm install
28
+ npm run build
29
+ ```
30
+
31
+ ### Optional: Enhanced Python Analysis
32
+
33
+ For more accurate Python complexity analysis:
34
+
35
+ ```bash
36
+ pip install radon
37
+ ```
38
+
39
+ > **Note:** JavaScript/TypeScript analysis works out-of-the-box using `escomplex` (pure npm, no Python needed).
40
+
41
+ ---
42
+
43
+ ## 🔧 Configuration
44
+
45
+ ### 🏠 LOCAL Development Setup
46
+
47
+ For local development and testing:
48
+
49
+ #### Step 1: Create/Edit `.vscode/mcp.json`
50
+
51
+ ```json
52
+ {
53
+ "servers": {
54
+ "performance-agent": {
55
+ "command": "node",
56
+ "args": [
57
+ "/Users/amanraj/Documents/CodeWorkspace/Performance-Agent/mcp-server/dist/index.js"
58
+ ],
59
+ "env": {
60
+ "PERFORMANCE_AGENT_API_URL": "http://127.0.0.1:8000"
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ > **Replace** `/absolute/path/to/` with your actual path.
68
+
69
+ #### Step 2: Start Backend API (for JMX generation)
70
+
71
+ ```bash
72
+ cd /path/to/Performance-Agent
73
+ python app.py
74
+ ```
75
+
76
+ #### Step 3: Restart VS Code
77
+
78
+ Press `Cmd+Shift+P` → "Developer: Reload Window"
79
+
80
+ #### Verify Installation
81
+
82
+ - Open GitHub Copilot Chat
83
+ - Type: "Analyze the complexity of my last commit"
84
+
85
+ ---
86
+
87
+ ### 🚀 PRODUCTION Deployment
88
+
89
+ For distributing to end users:
90
+
91
+ #### Option 1: npm Package (Recommended)
92
+
93
+ **Publish to npm:**
94
+
95
+ ```bash
96
+ npm publish --access public
97
+ ```
98
+
99
+ **User Installation:**
100
+
101
+ ```bash
102
+ npm install -g @performance-agent/mcp-server
103
+ ```
104
+
105
+ **User Configuration (`.vscode/mcp.json`):**
106
+
107
+ ```json
108
+ {
109
+ "servers": {
110
+ "performance-agent": {
111
+ "command": "performance-agent-mcp",
112
+ "env": {
113
+ "PERFORMANCE_AGENT_API_URL": "https://your-backend.azure.com",
114
+ "PERFORMANCE_AGENT_API_KEY": "your-api-key"
115
+ }
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ #### Option 2: Standalone Executable
122
+
123
+ Package as standalone binary (no Node.js required):
124
+
125
+ ```bash
126
+ npm install -g pkg
127
+ pkg . --targets node18-macos-x64,node18-linux-x64,node18-win-x64
128
+ ```
129
+
130
+ Distribute the generated binaries via GitHub Releases.
131
+
132
+ #### Option 3: Private npm (Enterprise)
133
+
134
+ ```bash
135
+ npm publish --access restricted
136
+ ```
137
+
138
+ Or use Azure Artifacts for private distribution.
139
+
140
+ ---
141
+
142
+ ## 🛠️ Usage
143
+
144
+ ### Tool 1: Generate JMX from Swagger
145
+
146
+ **In GitHub Copilot Chat:**
147
+
148
+ ```
149
+ Generate JMX script from my swagger.json file
150
+ ```
151
+
152
+ **Parameters:**
153
+
154
+ | Parameter | Type | Required | Description |
155
+ |-----------|------|----------|-------------|
156
+ | `repo_name` | string | No | Repository name for the script |
157
+ | `swagger_content` | object | Yes | Swagger/OpenAPI JSON specification |
158
+
159
+ **Example Response:**
160
+
161
+ ```json
162
+ {
163
+ "success": true,
164
+ "jmx_script": "<?xml version=\"1.0\"...",
165
+ "local_file": "api-test_generated.jmx",
166
+ "message": "JMX script generated successfully"
167
+ }
168
+ ```
169
+
170
+ ---
171
+
172
+ ### Tool 2: Analyze Code Complexity
173
+
174
+ **In GitHub Copilot Chat:**
175
+
176
+ ```
177
+ Analyze the complexity of my last commit
178
+ ```
179
+
180
+ ```
181
+ Check complexity of staged changes with threshold 15
182
+ ```
183
+
184
+ ```
185
+ What's the complexity of my uncommitted Python code?
186
+ ```
187
+
188
+ **Parameters:**
189
+
190
+ | Parameter | Type | Required | Default | Description |
191
+ |-----------|------|----------|---------|-------------|
192
+ | `repo_path` | string | Yes | - | Absolute path to git repo |
193
+ | `mode` | string | No | `last_commit` | `staged`, `last_commit`, `uncommitted`, `commit_sha` |
194
+ | `commit_sha` | string | If mode=commit_sha | - | Specific commit SHA |
195
+ | `threshold` | number | No | `10` | Complexity threshold |
196
+ | `language` | string | No | `all` | `python`, `javascript`, `typescript`, `all` |
197
+
198
+ **Example Response:**
199
+
200
+ ```json
201
+ {
202
+ "success": true,
203
+ "repo_path": "/Users/you/project",
204
+ "commit_sha": "abc123",
205
+ "mode": "last_commit",
206
+ "files_analyzed": 3,
207
+ "total_functions": 12,
208
+ "avg_complexity": 4.2,
209
+ "max_complexity": 15,
210
+ "threshold_violations": 2,
211
+ "summary": {
212
+ "low_risk": 8,
213
+ "medium_risk": 2,
214
+ "high_risk": 2,
215
+ "very_high_risk": 0
216
+ },
217
+ "recommendations": [
218
+ "⚠️ Found 2 function(s) exceeding complexity threshold of 10",
219
+ "🔴 1. process_request (app.py:145) - Complexity: 15"
220
+ ]
221
+ }
222
+ ```
223
+
224
+ ---
225
+
226
+ ---
227
+
228
+ ### Tool 3: Profile Function Performance
229
+
230
+ **In GitHub Copilot Chat:**
231
+
232
+ ```
233
+ Profile the performance of my functions
234
+ ```
235
+
236
+ ```
237
+ How fast is my process_data function?
238
+ ```
239
+
240
+ ```
241
+ Profile functions in my last commit
242
+ ```
243
+
244
+ **Parameters:**
245
+
246
+ | Parameter | Type | Required | Default | Description |
247
+ |-----------|------|----------|---------|-------------|
248
+ | `repo_path` | string | Yes | - | Absolute path to git repo |
249
+ | `mode` | string | No | `last_commit` | `staged`, `last_commit`, `uncommitted`, `file` |
250
+ | `file_path` | string | If mode=file | - | Specific file to profile |
251
+ | `function_name` | string | No | - | Profile only a specific function |
252
+ | `iterations` | number | No | `10` | Number of times to run each function |
253
+ | `threshold_ms` | number | No | `100` | Time threshold in milliseconds |
254
+ | `language` | string | No | `all` | `python`, `javascript`, `typescript`, `all` |
255
+
256
+ **Example Response:**
257
+
258
+ ```json
259
+ {
260
+ "success": true,
261
+ "repo_path": "/Users/you/project",
262
+ "mode": "last_commit",
263
+ "files_profiled": 3,
264
+ "functions_profiled": 8,
265
+ "slow_functions": 2,
266
+ "profiles": [
267
+ {
268
+ "file": "utils.py",
269
+ "function": "process_data",
270
+ "line": 45,
271
+ "avg_time_ms": 250.5,
272
+ "min_time_ms": 180.2,
273
+ "max_time_ms": 320.1,
274
+ "performance_level": "slow"
275
+ }
276
+ ],
277
+ "recommendations": [
278
+ "⚠️ Found 2 slow function(s) exceeding 100ms threshold"
279
+ ]
280
+ }
281
+ ```
282
+
283
+ ---
284
+
285
+ ## 📊 Complexity Thresholds
286
+
287
+ | Score | Risk Level | Recommendation |
288
+ |-------|------------|----------------|
289
+ | 1-4 | ✅ Low | Good, maintainable code |
290
+ | 5-9 | 👍 Medium | Acceptable |
291
+ | 10-19 | ⚠️ High | Consider refactoring |
292
+ | 20+ | 🔴 Very High | Refactor required |
293
+
294
+ ---
295
+
296
+ ## ⏱️ Performance Thresholds
297
+
298
+ | Avg Time | Performance Level | Recommendation |
299
+ |----------|-------------------|----------------|
300
+ | < 50ms | 🟢 Fast | Excellent performance |
301
+ | 50-100ms | 🔵 Acceptable | Good performance |
302
+ | 100-200ms | 🟡 Slow | Consider optimization |
303
+ | > 200ms | 🔴 Very Slow | Optimization required |
304
+
305
+ ---
306
+
307
+ ## 💡 Common Use Cases
308
+
309
+ ### Pre-Commit Quality Check
310
+
311
+ ```
312
+ Check complexity of my staged changes
313
+ ```
314
+
315
+ If violations found, refactor before committing.
316
+
317
+ ### Post-Commit Review
318
+
319
+ ```
320
+ Analyze the complexity of my last commit
321
+ ```
322
+
323
+ Create follow-up tasks for high-complexity functions.
324
+
325
+ ### Code Review Helper
326
+
327
+ ```
328
+ Analyze complexity for commit abc123def
329
+ ```
330
+
331
+ Identify functions needing extra attention.
332
+
333
+ ### API Load Testing
334
+
335
+ ```
336
+ Generate JMX script from swagger.json
337
+ ```
338
+
339
+ Run the generated script with JMeter.
340
+
341
+ ### Performance Profiling
342
+
343
+ ```
344
+ Profile the performance of my functions
345
+ ```
346
+
347
+ Identify slow functions and get optimization recommendations.
348
+
349
+ ---
350
+
351
+ ## 🏗️ Architecture
352
+
353
+ ```
354
+ ┌─────────────────┐
355
+ │ VS Code │
356
+ │ GitHub Copilot│
357
+ └────────┬────────┘
358
+ │ MCP Protocol
359
+
360
+ ┌─────────────────┐
361
+ │ MCP Server │ ← This package
362
+ │ (Node.js) │
363
+ │ │
364
+ │ ┌───────────┐ │
365
+ │ │ Complexity│ │ ← Runs locally (escomplex/radon)
366
+ │ │ Analyzer │ │
367
+ │ └───────────┘ │
368
+ │ ┌───────────┐ │
369
+ │ │ Function │ │ ← Runs locally (timeit/performance.now)
370
+ │ │ Profiler │ │
371
+ │ └───────────┘ │
372
+ │ ┌───────────┐ │
373
+ │ │ JMX Gen │──┼──► Backend API (Flask)
374
+ │ └───────────┘ │
375
+ └─────────────────┘
376
+ ```
377
+
378
+ ---
379
+
380
+ ## 📁 Project Structure
381
+
382
+ ```
383
+ mcp-server/
384
+ ├── src/
385
+ │ ├── index.ts # Main MCP server
386
+ │ └── tools/
387
+ │ ├── code-analyzer/
388
+ │ │ ├── index.ts # Analyzer entry point
389
+ │ │ ├── types.ts # TypeScript interfaces
390
+ │ │ ├── git-helper.ts # Git operations
391
+ │ │ └── analyzers/
392
+ │ │ ├── python-analyzer.ts # Python (radon)
393
+ │ │ └── javascript-analyzer.ts # JS/TS (escomplex)
394
+ │ └── function-profiler/
395
+ │ ├── index.ts # Profiler entry point
396
+ │ ├── types.ts # TypeScript interfaces
397
+ │ ├── python-profiler.ts # Python (timeit)
398
+ │ └── javascript-profiler.ts # JS/TS profiler
399
+ ├── dist/ # Compiled JavaScript
400
+ ├── package.json
401
+ ├── tsconfig.json
402
+ └── README.md
403
+ ```
404
+
405
+ ---
406
+
407
+ ## 🔧 Development
408
+
409
+ ```bash
410
+ # Development mode with hot reload
411
+ npm run dev
412
+
413
+ # Build TypeScript
414
+ npm run build
415
+
416
+ # Run tests
417
+ npm test
418
+ ```
419
+
420
+ ---
421
+
422
+ ## 🐛 Troubleshooting
423
+
424
+ ### MCP Server Not Loading
425
+
426
+ 1. Check `.vscode/mcp.json` exists with correct path
427
+ 2. Restart VS Code: `Cmd+Shift+P` → "Developer: Reload Window"
428
+ 3. Check Output panel: View → Output → MCP: performance-agent
429
+
430
+ ### "radon not installed" Warning
431
+
432
+ ```bash
433
+ pip install radon
434
+ ```
435
+
436
+ > The analyzer has a regex fallback, but radon provides better accuracy.
437
+
438
+ ### JMX Generation Fails
439
+
440
+ Ensure backend API is running:
441
+
442
+ ```bash
443
+ # Local
444
+ python app.py
445
+ curl http://localhost:8000/health
446
+
447
+ # Production: Check API URL and key in env config
448
+ ```
449
+
450
+ ### No Functions Detected
451
+
452
+ - Ensure files are tracked by git
453
+ - Check file extensions (.py, .js, .ts, .tsx)
454
+ - Try with `mode: "uncommitted"` for untracked files
455
+
456
+ ---
457
+
458
+ ## 🔐 Security
459
+
460
+ - All complexity analysis runs **locally** - no code sent externally
461
+ - Backend API keys stored in environment variables
462
+ - HTTPS in production for JMX generation API calls
463
+ - No sensitive data logged
464
+
465
+ ---
466
+
467
+ ## 📝 Environment Variables
468
+
469
+ | Variable | Local | Production | Description |
470
+ |----------|-------|------------|-------------|
471
+ | `PERFORMANCE_AGENT_API_URL` | `http://localhost:8000` | `https://your-api.azure.com` | Backend API URL |
472
+ | `PERFORMANCE_AGENT_API_KEY` | _(empty)_ | Your API key | Authentication key |
473
+
474
+ ---
475
+
476
+ ## 📞 Support
477
+
478
+ - **Issues**: Create GitHub issue
479
+ - **Logs**: View → Output → MCP: performance-agent
480
+
481
+ ---
482
+
483
+ ## 📄 License
484
+
485
+ MIT License
486
+
487
+ ---
488
+
489
+ ## ✅ Quick Checklist
490
+
491
+ ### Local Setup
492
+ - [ ] `npm install && npm run build` in mcp-server
493
+ - [ ] Create `.vscode/mcp.json` with local config
494
+ - [ ] Optional: `pip install radon` for Python analysis
495
+ - [ ] Start backend: `python app.py`
496
+ - [ ] Restart VS Code
497
+ - [ ] Test: "Analyze my last commit"
498
+
499
+ ### Production Setup
500
+ - [ ] `npm publish` to npm registry
501
+ - [ ] Deploy backend API to Azure
502
+ - [ ] User installs: `npm install -g @performance-agent/mcp-server`
503
+ - [ ] User configures `.vscode/mcp.json` with production URL/key
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Performance Agent MCP Server
4
+ *
5
+ * This MCP server provides 3 core tools:
6
+ * 1. Generate JMX scripts from Swagger/OpenAPI specifications
7
+ * 2. Analyze code complexity in local git repositories
8
+ * 3. Profile function execution time and identify slow functions
9
+ *
10
+ * Focused on local development and code quality.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG"}