You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,246 +6,108 @@ This npm package is currently for internal use only. Its contents may change at
6
6
7
7
## Overview
8
8
9
-
This package provides MCP tools for detecting and fixing performance antipatterns in Apex code. It uses a SOLID architecture with clear separation of concerns:
9
+
This package provides MCP tools for the Salesforce Scale Products suite — [ApexGuru](https://help.salesforce.com/s/articleView?id=xcloud.apexguru_overview.htm&type=5), [Scale Test](https://www.salesforce.com/in/platform/application-scaling-performance-testing/) and [Scale Center](https://help.salesforce.com/s/articleView?id=xcloud.scale_center_overview.htm&type=5). The tools help developers and architects identify performance bottlenecks, optimize Apex code, and ensure applications scale reliably under peak loads.
10
10
11
-
-**Detectors**: Identify antipatterns using regex-based static analysis (detection only)
12
-
-**Recommenders**: Convert detections to CodeFix format and provide LLM fix instructions
13
-
-**Antipattern Modules**: Couple detectors and recommenders (recommender is optional)
14
-
-**MCP Tool**: Returns detections with fix instructions for LLM to generate actual fixes
15
11
16
-
## Features
12
+
## Tools
17
13
18
-
### Currently Supported Antipatterns
14
+
### `scan_apex_class_for_antipatterns`
19
15
20
-
#### GGD (Schema.getGlobalDescribe)
21
-
Detects usage of the expensive `Schema.getGlobalDescribe()` method with different severity levels:
Scans an Apex class file (`.cls` or `.trigger`) and returns detected antipatterns grouped by type, each with severity and fix instructions.
24
17
25
-
Provides recommendations to use `Type.forName()` or direct SObject references instead.
18
+
**Detected Antipatterns:**
26
19
27
-
## Architecture
20
+
| Antipattern | What it detects | Example |
21
+
|---|---|---|
22
+
|**GGD**|`Schema.getGlobalDescribe()` calls (higher severity inside loops) | Replace with `Type.forName()` or direct SObject token |
23
+
|**SOQL_NO_WHERE_LIMIT**| SOQL queries missing both `WHERE` and `LIMIT` clauses | Add filtering or row limits to prevent governor limit issues |
24
+
|**SOQL_UNUSED_FIELDS**| SOQL queries selecting fields that are never referenced in code | Remove unused fields to reduce query cost |
28
25
29
-
The package follows SOLID principles with a simplified, focused design:
26
+
**Input Parameters:**
30
27
31
-
-**Single Responsibility**: Each detector/recommender handles one antipattern
32
-
-**Open/Closed**: Easy to add new antipatterns without modifying existing code
33
-
-**Liskov Substitution**: All detectors/recommenders implement base interfaces
34
-
-**Interface Segregation**: Clean, focused interfaces - one registry instead of three
35
-
-**Dependency Inversion**: Depends on abstractions, not concrete implementations
28
+
| Parameter | Required | Description |
29
+
|---|---|---|
30
+
|`className`| Yes | Name of the Apex class (e.g., `AccountController`) |
31
+
|`apexFilePath`| Yes | Absolute path to the `.cls` or `.trigger` file |
32
+
|`directory`| Yes | Absolute path to the working directory (your SFDX project root) |
33
+
|`usernameOrAlias`| No | Salesforce org username or alias for runtime insights (see [Org Setup](#org-setup-for-runtime-insights)) |
34
+
|`identifier`| No | Unique identifier for this scan (defaults to `className`) |
36
35
37
-
### Design Decisions
36
+
**Output:**
38
37
39
-
**Single Registry Pattern**: Uses only `AntipatternRegistry` to manage modules. Removed separate `DetectorRegistry` and `RecommenderRegistry` as they were unused and added unnecessary complexity.
38
+
The tool returns detections grouped by antipattern type. Each group contains a `fixInstruction` (how to fix the antipattern) and an array of `detectedInstances`:
40
39
41
-
**Separation of Concerns**:
42
-
-**Detectors** find antipatterns and report them with metadata (line number, severity, problematic code)
43
-
-**Recommenders** convert detections to CodeFix format and provide LLM fix instructions
44
-
-**LLM** receives the detections + instructions and generates the actual fixes
-**Detection-only**: Just detector → Detections with basic/default instructions
60
+
Each instance includes `severity` (minor / major / critical). When runtime metrics are available, severity is derived from production data and marked with a bulb icon in the formatted output.
49
61
50
-
This architecture ensures:
51
-
- Detectors stay focused on detection
52
-
- Recommenders provide guidance, not implementations
53
-
- LLMs have full context to generate optimal fixes
62
+
## Org Setup for Runtime Insights
54
63
55
-
### Directory Structure
64
+
Without an org connection the tool runs **static analysis only** — it still detects all antipatterns but assigns severity based on code structure (e.g., inside a loop = higher severity).
56
65
57
-
```
58
-
src/
59
-
├── models/ # Data models (DetectionResult, Severity, etc.)
To unlock **runtime-aware severity** powered by ApexGuru, the tool needs access to a Salesforce org. You have two options:
67
67
68
-
## Development Workflow
68
+
1.**Set a default target org** so every invocation uses it automatically:
69
+
```bash
70
+
sf config set target-org myOrg@example.com
71
+
```
69
72
70
-
### Prerequisites
73
+
2.**Pass the org explicitly** by including the username or alias in your prompt when invoking the tool (the `usernameOrAlias` parameter).
71
74
72
-
Ensure you're in the monorepo root or the package directory for these commands.
75
+
> **Prerequisite:** The org must have ApexGuru / the Scale Center suite enabled. If runtime data returns an access-denied error, contact Salesforce Support to enable it.
73
76
74
-
### Essential Commands
77
+
##Severity Levels
75
78
76
-
#### Install Dependencies
77
-
```bash
78
-
# From package directory
79
-
yarn install
79
+
| Level | Meaning |
80
+
|---|---|
81
+
|**Minor**| Low-impact issue; fix when convenient |
82
+
|**Major**| Moderate performance risk; should be addressed |
83
+
|**Critical**| High-impact hotspot; fix with priority |
When runtime metrics are available (org connected + ApexGuru enabled), severity is calculated from actual production execution data rather than static heuristics.
0 commit comments