@W-21102094 - Add PMD XPath custom rule creation tool with AST prompt generation#381
@W-21102094 - Add PMD XPath custom rule creation tool with AST prompt generation#381aruntyagiTutu wants to merge 28 commits intomainfrom
Conversation
* extractAstNodes from xml implementation * optimize the method using regex * extract ast nodes from xml
* mcp tool added in provider * add GenerateXpathPromptMcpTool in test * update test
* get metadata of ast nodes of apex langugae * pmd apex ast cache
* implemented create custom rule tool * test update
* add validation that this implementation supports pmd only for now * update prompt - optimize for output size * refactor create tool * file name santization * updated action name * update prompt * update prompt optimize for simple xpath * fix tests * fix test with mock
…y methods (#386) * langugae in ruleset template * update telemetry on success * xpath is optional * clean chuncky methods
packages/mcp-provider-code-analyzer/src/tools/create_custom_rule.ts
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,99 @@ | |||
| import { XMLParser } from "fast-xml-parser"; | |||
There was a problem hiding this comment.
This is missing from your package.json dependencies. It is probably getting pulled in as a transitive dependency, but it is best to depend on it explicitly
There was a problem hiding this comment.
Also, make sure it is a least 5.3.5 or higher. Earlier versions have a known vuln
| title: "Create Custom Rule", | ||
| description: DESCRIPTION, | ||
| inputSchema: inputSchema.shape, | ||
| outputSchema: outputSchema.shape |
There was a problem hiding this comment.
Add annotations here. I think this is right, confirm:
annotations: {
readOnlyHint: false, // Writes ruleset XML and code-analyzer.yml
destructiveHint: false, // Does not delete anything
openWorldHint: false, // Local file operations only
},
| configPath: output.configPath | ||
| }); | ||
| } | ||
| return { |
There was a problem hiding this comment.
Add isError if the response is an error
isError: output.status !== "success",
| import { getApexAstNodeMetadataByNames, type ApexAstNodeMetadata } from "../ast/metadata/apex-ast-reference.js"; | ||
| import { LANGUAGE_NAMES } from "../constants.js"; | ||
|
|
||
| export type EngineName = "pmd"; |
There was a problem hiding this comment.
Does this need to be exported? I ask because this collides with export type EngineName = typeof ENGINE_NAMES[number]; defined in packages/mcp-provider-code-analyzer/src/constants.ts
| inputSchema: inputSchema.shape, | ||
| outputSchema: outputSchema.shape, | ||
| annotations: { | ||
| readOnlyHint: true |
There was a problem hiding this comment.
Can you confirm readOnlyHint: true is correct? If I am following this correctly, it looks like this generates some temp files in PmdCliAstXmlAdapter
What does this PR do?
@W-21102094@
What issues does this PR fix or reference?
This PR introduces an end‑to‑end flow for creating PMD XPath custom rules. It generates PMD AST XML from sample Apex code, extracts AST nodes and cached metadata, builds a high‑signal prompt for XPath generation, and then writes a PMD ruleset XML plus updates code-analyzer.yml (with relative custom ruleset paths). It also adds engine strategies/pipeline/adapters to keep the workflow extensible for future engines, along with tests and tool registration updates.
Notes / Future Work
The Apex AST reference JSON is cached locally in the provider to enable prompt enrichment in phase 1. This is a temporary placement and will move into the PMD engine implementation in core once the engine plugin owns AST metadata.
PMD CLI integration is used to generate AST XML in phase 1. This will be replaced by a PMD engine API in core (Java SDK or internal API) so we can avoid external process execution and share logic across tools.