Skip to content

Commit 01825c3

Browse files
committed
Merge branch 'main' into ashreya/devops-mcp-wi
2 parents eaed04c + 1beae01 commit 01825c3

File tree

8 files changed

+124
-220
lines changed

8 files changed

+124
-220
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ packages/EXAMPLE-MCP-PROVIDER/ @salesforcecli/dx-mcp-owners
1111

1212
packages/mcp-provider-code-analyzer/ @salesforcecli/mcp-provider-code-analyzer
1313
packages/mcp-provider-devops/ @salesforcecli/mcp-provider-devops
14+
packages/mcp-provider-metadata-enrichment/ @salesforcecli/mcp-provider-metadata-enrichment
1415
packages/mcp-provider-mobile-web/ @salesforcecli/mcp-provider-mobile
1516

1617

packages/mcp-provider-scale-products/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.0.4](https://github.com/salesforcecli/mcp/compare/mcp-provider-scale-products@0.0.3...mcp-provider-scale-products@0.0.4) (2026-02-18)
2+
3+
4+
15
## [0.0.3](https://github.com/salesforcecli/mcp/compare/mcp-provider-scale-products@0.0.2...mcp-provider-scale-products@0.0.3) (2026-02-06)
26

37

packages/mcp-provider-scale-products/README.md

Lines changed: 67 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -6,246 +6,108 @@ This npm package is currently for internal use only. Its contents may change at
66

77
## Overview
88

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.
1010

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
1511

16-
## Features
12+
## Tools
1713

18-
### Currently Supported Antipatterns
14+
### `scan_apex_class_for_antipatterns`
1915

20-
#### GGD (Schema.getGlobalDescribe)
21-
Detects usage of the expensive `Schema.getGlobalDescribe()` method with different severity levels:
22-
- **MEDIUM**: Regular invocations
23-
- **HIGH**: Invocations inside loops (for, while, do-while)
16+
Scans an Apex class file (`.cls` or `.trigger`) and returns detected antipatterns grouped by type, each with severity and fix instructions.
2417

25-
Provides recommendations to use `Type.forName()` or direct SObject references instead.
18+
**Detected Antipatterns:**
2619

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 |
2825

29-
The package follows SOLID principles with a simplified, focused design:
26+
**Input Parameters:**
3027

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`) |
3635

37-
### Design Decisions
36+
**Output:**
3837

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`:
4039

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
40+
```json
41+
{
42+
"antipatternResults": [
43+
{
44+
"antipatternType": "GGD",
45+
"fixInstruction": "## Fix Schema.getGlobalDescribe() ...",
46+
"detectedInstances": [
47+
{
48+
"className": "MyClass",
49+
"methodName": "myMethod",
50+
"lineNumber": 5,
51+
"codeBefore": "Schema.SObjectType t = Schema.getGlobalDescribe().get('Account');",
52+
"severity": "major"
53+
}
54+
]
55+
}
56+
]
57+
}
58+
```
4559

46-
**Optional Recommenders**: Antipattern modules support detection-only workflows:
47-
- **Full workflow**: Detector + Recommender → Detections with detailed LLM fix instructions
48-
- **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.
4961

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
5463

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).
5665

57-
```
58-
src/
59-
├── models/ # Data models (DetectionResult, Severity, etc.)
60-
├── detectors/ # Antipattern detection logic
61-
├── recommenders/ # Recommendation generation logic
62-
├── antipatterns/ # Modules coupling detectors + recommenders
63-
├── tools/ # MCP tool implementations
64-
├── provider.ts # MCP provider registration
65-
└── index.ts # Package exports
66-
```
66+
To unlock **runtime-aware severity** powered by ApexGuru, the tool needs access to a Salesforce org. You have two options:
6767

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+
```
6972

70-
### Prerequisites
73+
2. **Pass the org explicitly** by including the username or alias in your prompt when invoking the tool (the `usernameOrAlias` parameter).
7174

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.
7376
74-
### Essential Commands
77+
## Severity Levels
7578

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 |
8084

81-
# Or from monorepo root
82-
yarn workspace @salesforce/mcp-provider-scale-products install
83-
```
85+
When runtime metrics are available (org connected + ApexGuru enabled), severity is calculated from actual production execution data rather than static heuristics.
8486

85-
#### Build
86-
```bash
87-
# From package directory
88-
node node_modules/typescript/lib/tsc.js --build tsconfig.build.json --verbose
87+
## Development
8988

90-
# Or from monorepo root
91-
yarn workspace @salesforce/mcp-provider-scale-products build
92-
```
89+
Ensure you are in the monorepo root or the package directory.
9390

94-
#### Run Tests
9591
```bash
96-
# From package directory
97-
node node_modules/vitest/vitest.mjs run
92+
# Install
93+
yarn install
9894

99-
# With coverage
100-
node node_modules/vitest/vitest.mjs run --coverage
95+
# Build
96+
yarn workspace @salesforce/mcp-provider-scale-products build
10197

102-
# Or from monorepo root
98+
# Test
10399
yarn workspace @salesforce/mcp-provider-scale-products test
104-
```
105100

106-
#### Lint
107-
```bash
108-
# From package directory
109-
node node_modules/eslint/bin/eslint.js **/*.ts
101+
# Test with coverage
102+
node node_modules/vitest/vitest.mjs run --coverage
110103

111-
# Or from monorepo root
104+
# Lint
112105
yarn workspace @salesforce/mcp-provider-scale-products lint
113-
```
114106

115-
#### Clean
116-
```bash
117-
# From package directory
118-
node node_modules/typescript/lib/tsc.js --build tsconfig.build.json --clean
119-
120-
# Or from monorepo root
107+
# Clean
121108
yarn workspace @salesforce/mcp-provider-scale-products clean
122109
```
123110

124-
### Adding a New Antipattern
125-
126-
#### Option 1: Full Detection + Recommendation
127-
128-
1. **Create Detector** (`src/detectors/your-detector.ts`):
129-
```typescript
130-
export class YourDetector implements BaseDetector {
131-
getAntipatternType(): AntipatternType {
132-
return AntipatternType.YOUR_TYPE;
133-
}
134-
135-
detect(className: string, apexCode: string): Detection[] {
136-
// Detection logic using regex or other static analysis
137-
}
138-
}
139-
```
140-
141-
2. **Create Recommender** (`src/recommenders/your-recommender.ts`):
142-
```typescript
143-
export class YourRecommender implements BaseRecommender {
144-
getAntipatternType(): AntipatternType {
145-
return AntipatternType.YOUR_TYPE;
146-
}
147-
148-
generateRecommendation(detection: Detection): CodeFix {
149-
// Generate detailed code fix with before/after examples
150-
}
151-
152-
getPromptInstruction(): string {
153-
// Return comprehensive LLM prompt with examples
154-
}
155-
}
156-
```
157-
158-
3. **Register Module** (in `src/tools/scan-apex-antipatterns-tool.ts`):
159-
```typescript
160-
const yourModule = new AntipatternModule(
161-
new YourDetector(),
162-
new YourRecommender() // Include recommender
163-
);
164-
registry.register(yourModule);
165-
```
166-
167-
#### Option 2: Detection-Only
168-
169-
For simpler antipatterns that don't need detailed recommendations:
170-
171-
1. **Create Detector** (same as above)
172-
173-
2. **Register Module** (without recommender):
174-
```typescript
175-
const yourModule = new AntipatternModule(
176-
new YourDetector()
177-
// No recommender - will use basic code fixes
178-
);
179-
registry.register(yourModule);
180-
```
181-
182-
The module will automatically generate basic code fixes without LLM prompts.
183-
184-
#### Testing & Building
185-
186-
4. **Add Tests**:
187-
- `test/detectors/your-detector.test.ts`
188-
- `test/recommenders/your-recommender.test.ts` (if using recommender)
189-
- `test/antipatterns/` (integration tests)
190-
191-
5. **Run Tests and Build**:
192-
```bash
193-
node node_modules/vitest/vitest.mjs run --coverage
194-
node node_modules/typescript/lib/tsc.js --build tsconfig.build.json
195-
```
196-
197-
## Usage
198-
199-
### As an MCP Tool
200-
201-
The tool `scan_apex_class_for_antipatterns` accepts:
202-
203-
**Input:**
204-
- `className` (string): Name of the Apex class
205-
- `apexCode` (string): Full Apex class source code
206-
- `identifier` (string, optional): Unique identifier for this scan
207-
208-
**Output:**
209-
- JSON detection results with code fixes
210-
- LLM prompt instructions for generating recommendations
211-
212-
**Example:**
213-
```json
214-
{
215-
"_id": "org:MyClass:0:GGD",
216-
"antipatternType": "GGD",
217-
"detectedInstances": [{
218-
"className": "MyClass",
219-
"methodName": "myMethod",
220-
"lineNumber": 5,
221-
"codeBefore": "Schema.SObjectType t = Schema.getGlobalDescribe().get('Account');",
222-
"severity": "medium",
223-
"fixInstruction": "# Fix Schema.getGlobalDescribe() at line 5\n\n## Problem\n...\n\n## Fix Strategies\n..."
224-
}]
225-
}
226-
```
227-
228-
Each `detectedInstance` has its own context-aware `fixInstruction` that the LLM uses to generate the fix.
229-
230-
## Test Coverage
231-
232-
Current coverage: **94.26%** (36 tests passing)
233-
234-
- All detectors: Comprehensive test cases
235-
- All recommenders: Recommendation generation tests
236-
- Antipattern modules: Integration tests (including detection-only)
237-
- MCP tool: End-to-end tests
238-
239-
## Contributing
240-
241-
When adding features:
242-
243-
1. Follow existing patterns and SOLID principles
244-
2. Write tests first (TDD approach recommended)
245-
3. Ensure all tests pass: `node node_modules/vitest/vitest.mjs run --coverage`
246-
4. Maintain or improve code coverage (target: >85%)
247-
5. Update this README with new antipatterns
248-
249111
## License
250112

251113
Apache-2.0

packages/mcp-provider-scale-products/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/mcp-provider-scale-products",
33
"description": "(For Internal Use Only) MCP Provider for Salesforce Scale Products - Apex antipattern detection and recommendations",
4-
"version": "0.0.3",
4+
"version": "0.0.4",
55
"author": "Salesforce",
66
"license": "Apache-2.0",
77
"type": "module",

0 commit comments

Comments
 (0)