Skip to content

Commit 4003642

Browse files
SamarthAroraashuchita-singhiowillhoit
authored
@W-20397755@ [Scale products] Prompt cleanup + minor documentation changes (#396)
* added scale mcp init code * added coverage to be above 95% * added separate resource for adding fix instructions. added readme for devs * removed redundant comment * added SME aligned few shot prompts for antipatterns * added parser based detection with tests * added scale mcp init code * feat: Add SOQL No WHERE/LIMIT clause antipattern detector - Implemented AST-based detector for SOQL queries lacking WHERE or LIMIT clauses - Added SOQLAstUtils for robust query extraction and analysis - Created comprehensive fix instructions with severity levels and code examples - Registered new detector in scan-apex-antipatterns-tool * test: Add comprehensive test coverage for SOQL No WHERE/LIMIT antipattern - Add unit tests for SOQLAstUtils (soql-ast-utils.test.ts) - Add unit tests for SOQLNoWhereLimitDetector (soql-no-where-limit-detector.test.ts) - Add unit tests for SOQLNoWhereLimitRecommender (soql-no-where-limit-recommender.test.ts) - Cover edge cases: multi-line queries, nested subqueries, SOQL in loops, comments, complex WHERE clauses * feat: add SOQL unused fields detector with AST-based analysis * Added test cases * consolidate SOQL utilities into soql-ast-utils.ts * Minor change * refactor: remove unused ast-analyzer.ts - ast-analyzer.ts was not used anywhere in the codebase - All AST operations are handled directly by @apexdevtools/apex-parser - Reduces unnecessary code complexity * style: minor cleanup changes * added tool descriptions in README.md * skipped flapping test for windows * added runtime data enrichment * added telemetry and removed redundant comments * fixed tests * fixed test failures * added directory path and username params to lock active org to the right context. * added dynamic api versioning * removed implicit org assignment * resolve windows errors * added test coverage * minor label changes according to CX feedback * updates tests * Adding validation for file extension to only allow apex files * Minor prompt tweak for a feature enhancement * Prompt enhancement for better CX * updated README.md for scale toolset * change state to GA * tweaked readme to reflect all scale products * documentation changes * nit: documentation update * Use backticks instead of string interpolation for a cleaner prompt. * 1. Removed redundant severity legend 2. Removed a stray '\' * Update Best Practices wording in README --------- Co-authored-by: shuchita-singh <shuchita.singh@salesforce.com> Co-authored-by: Willhoit <iowillhoit@users.noreply.github.com>
1 parent ed455c3 commit 4003642

File tree

2 files changed

+72
-70
lines changed

2 files changed

+72
-70
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,22 @@ To unlock **runtime-aware severity** powered by ApexGuru, the tool needs access
7878

7979
| Level | Meaning |
8080
|---|---|
81-
| **Minor** | Low-impact issue; fix when convenient |
82-
| **Major** | Moderate performance risk; should be addressed |
83-
| **Critical** | High-impact hotspot; fix with priority |
81+
| **Minor** | Deviates from quality standards; fix when convenient |
82+
| **Major** | Reduces usability or causes a crucial part of your software to fail |
83+
| **Critical** | Highest priority; issues with run time, count, and other factors that result in software failure |
8484

8585
When runtime metrics are available (org connected + ApexGuru enabled), severity is calculated from actual production execution data rather than static heuristics.
8686

87+
## Best Practices
88+
89+
If your MCP client isn't calling the Scale tools you expect, try these tips:
90+
91+
1. **Scope tool execution.** Use the `--toolsets scale-products` argument in your MCP config files to improve tool resolution. Too many registered tools make it difficult for your MCP host to resolve the correct one. Disable any tools you don't actively use.
92+
93+
2. **Reference tools explicitly.** Reference the tool by name in your prompt so the LLM knows exactly which tool to invoke. For example:
94+
95+
> *Scan MyClass.cls for performance antipatterns using the `scan_apex_class_for_antipatterns` MCP tool.*
96+
8797
## Development
8898

8999
Ensure you are in the monorepo root or the package directory.

packages/mcp-provider-scale-products/src/tools/scan-apex-antipatterns-tool.ts

Lines changed: 59 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,16 @@ export class ScanApexAntipatternsTool extends McpTool<InputArgsShape, OutputArgs
118118
public getConfig(): McpToolConfig<InputArgsShape, OutputArgsShape> {
119119
return {
120120
title: "Scan Apex Class for Antipatterns",
121-
description:
122-
"Apex Code Scan Tool: Invoke (alongside other code scan tools if needed) whenever the user intends to scan or analyze an Apex class. " +
123-
"Analyzes an Apex class file for performance antipatterns and provides " +
124-
"recommendations for fixing them. Currently detects: " +
125-
"1) Schema.getGlobalDescribe() usage with optimized alternatives " +
126-
"2) SOQL queries without WHERE or LIMIT clauses " +
127-
"3) SOQL queries with unused fields (with fix generation). " +
128-
"Distinguishes between different severity levels (e.g., usage in loops vs. ordinary usage). " +
129-
"When authenticated to an org with ApexGuru enabled, severity is calculated from actual runtime metrics. " +
130-
"IMPORTANT: If the user does not mention an org alias or username in the request, call #get_username tool to resolve the default org username. " +
131-
"Requires an absolute path to the Apex class file. " +
132-
"\n" +
133-
"==== PRESENTATION INSTRUCTIONS ====" +
134-
"\n1. ALWAYS start with a clear header indicating whether runtime analysis from production org was used:" +
135-
" - If runtime metrics were used: '🔬 LEVERAGING YOUR ORG'S RUNTIME INTELLIGENCE VIA APEXGURU: Analyzing with Production Metrics from [OrgId]'" +
136-
"\n2. Display this LEGEND prominently at the beginning of your response:" +
137-
" ╔════════════════════════════════════════════════════════╗\n" +
138-
" ║ SEVERITY LEGEND ║\n" +
139-
" ╠════════════════════════════════════════════════════════╣\n" +
140-
" ║ 🟡 = Minor Severity Antipattern ║\n" +
141-
" ║ 🟠 = Major Severity Antipattern ║\n" +
142-
" ║ 🔴 = Critical Severity Antipattern ║\n" +
143-
" ║ 💡 = Severity from Production Metrics ║\n" +
144-
" ╚════════════════════════════════════════════════════════╝\n",
121+
description: `Apex Code Scan Tool: Invoke (alongside other code scan tools if needed) whenever the user intends to scan or analyze an Apex class.
122+
Analyzes an Apex class file for performance antipatterns and provides recommendations for fixing them. Currently detects:
123+
1) Schema.getGlobalDescribe() usage with optimized alternatives
124+
2) SOQL queries without WHERE or LIMIT clauses
125+
3) SOQL queries with unused fields (with fix generation).
126+
Distinguishes between different severity levels (e.g., usage in loops vs. ordinary usage).
127+
When authenticated to an org with ApexGuru enabled, severity is calculated from actual runtime metrics.
128+
IMPORTANT: If the user does not mention an org alias or username in the request, call #get_username tool to resolve the default org username.
129+
Requires an absolute path to the Apex class file.
130+
`,
145131
inputSchema: scanApexInputSchema.shape,
146132
outputSchema: undefined,
147133
annotations: {
@@ -449,51 +435,57 @@ export class ScanApexAntipatternsTool extends McpTool<InputArgsShape, OutputArgs
449435
0
450436
);
451437

452-
let response = "";
453-
454-
// Add header based on runtime analysis status
455-
if (runtimeDataStatus === RuntimeDataStatus.SUCCESS) {
456-
response += `# 🔬 Leveraging Your Org's Runtime Intelligence via ApexGuru\n\n`;
457-
}
458-
// Add severity legend
459-
response += `╔════════════════════════════════════════════════════════╗\n`;
460-
response += `║ SEVERITY LEGEND ║\n`;
461-
response += `╠════════════════════════════════════════════════════════╣\n`;
462-
response += `║ 🟡 = Minor Severity Antipattern ║\n`;
463-
response += `║ 🟠 = Major Severity Antipattern ║\n`;
464-
response += `║ 🔴 = Critical Severity Antipattern ║\n`;
465-
response += `║ 💡 = Severity from Production Metrics ║\n`;
466-
response += `╚════════════════════════════════════════════════════════╝\n\n`;
467-
468-
response += `## Antipattern Scan Results for '${className}'\n\n`;
469-
response += `Found ${totalIssues} issue(s) across ${scanResult.antipatternResults.length} antipattern type(s).\n`;
470-
471-
response += this.getRuntimeDataMessage(runtimeDataStatus);
472-
response += `\n`;
473-
474-
response += `## Scan Results\n\n`;
475-
response += "Results are grouped by antipattern type. Each type has:\n";
476-
response += "- **fixInstruction**: How to fix this antipattern type (applies to all instances)\n";
477-
response += "- **detectedInstances**: All detected instances of this type\n\n";
478-
479-
// Transform results to add bulb icon for runtime-derived severity
438+
const runtimeHeader = runtimeDataStatus === RuntimeDataStatus.SUCCESS
439+
? `# 🔬 Maximizing Organizational Runtime Intelligence with ApexGuru\n\n`
440+
: "";
441+
480442
const displayResult = this.addSeverityIcons(scanResult);
481443

482-
response += "```json\n";
483-
response += JSON.stringify(displayResult, null, 2);
484-
response += "\n```\n\n";
485-
486-
response += `## Instructions for Code Fixes\n\n`;
487-
response += `When applying fixes in code, include the following in comments:\n`;
488-
response += `- For each antipattern, include the appropriate severity dot (🟡/🟠/🔴)\n`;
489-
response += `- Add 💡 next to severity dot when runtime metrics were used to calculate severity\n\n`;
490-
response += `The scan result contains multiple antipattern types. For each type:\n`;
491-
response += `1. Read the \`fixInstruction\` - this explains how to fix this antipattern\n`;
492-
response += `2. For each instance in \`detectedInstances\`:\n`;
493-
response += ` - Examine \`codeBefore\` (the problematic code)\n`;
494-
response += ` - Consider \`severity\` (critical/major/minor)\n`;
495-
response += ` - Generate the fixed code following the instruction\n\n`;
496-
response += `Generate fixes for all detected instances across all antipattern types.\n`;
444+
const response = `==== PRESENTATION INSTRUCTIONS ====
445+
1. ALWAYS start with a clear header indicating whether runtime analysis from production org was used:
446+
- If runtime metrics were used: '🔬 Analyzing with Production Metrics from [OrgId]'
447+
- Otherwise: do not use the runtime header.
448+
2. Display the SEVERITY LEGEND prominently at the beginning of your response.
449+
450+
${runtimeHeader}
451+
**SEVERITY LEGEND**
452+
- 🟡 Minor: Deviates from quality standards
453+
- 🟠 Major: Reduces usability or causes failure
454+
- 🔴 Critical: Highest priority, causes failure
455+
- 💡 Severity from Production Metrics
456+
457+
**Presentation:** Be concise, conversational, direct, and positive. Address the reader as "you." Use a casual tone but avoid jargon and slang. Avoid "please" and "sorry"; use exclamation points sparingly. Design text for easy scanning.
458+
459+
## Antipattern Scan Results for '${className}'
460+
461+
Found ${totalIssues} issue(s) across ${scanResult.antipatternResults.length} antipattern type(s).
462+
${this.getRuntimeDataMessage(runtimeDataStatus)}
463+
464+
## Scan Results
465+
466+
Results are grouped by antipattern type. Each type has:
467+
- **fixInstruction**: How to fix this antipattern type (applies to all instances)
468+
- **detectedInstances**: All detected instances of this type
469+
470+
\`\`\`json
471+
${JSON.stringify(displayResult, null, 2)}
472+
\`\`\`
473+
474+
## Instructions for Code Fixes
475+
476+
When applying fixes in code, include the following in comments:
477+
- For each antipattern, include the appropriate severity dot (🟡/🟠/🔴)
478+
- Add 💡 next to severity dot when runtime metrics were used to calculate severity
479+
480+
The scan result contains multiple antipattern types. For each type:
481+
1. Read the \`fixInstruction\` - this explains how to fix this antipattern
482+
2. For each instance in \`detectedInstances\`:
483+
- Examine \`codeBefore\` (the problematic code)
484+
- Consider \`severity\` (critical/major/minor)
485+
- Generate the fixed code following the instruction
486+
487+
Generate fixes for all detected instances across all antipattern types.
488+
`;
497489

498490
return response;
499491
}

0 commit comments

Comments
 (0)