AL icon indicating copy to clipboard operation
AL copied to clipboard

AL MCP: warnings from code cops missing

Open matthiasrabus opened this issue 7 months ago • 1 comments

1. Describe the bug I'm working with Claude and the AL language MCP. When building the project and fetching the diagnostics, I only get the output of the compiler warnings (AL), not the output of the configured code cops.

2. To Reproduce Install claude, AL MCP and open a project with multiple warnings.

Claude called the al_compile tool like that: { "options": { "enableCodeAnalysis": true, "codeAnalyzers": ["${CodeCop}", "${PerTenantExtensionCop}", "${UICop}"], "maxDiagnosticsPerCompilation": 2500 } }

Then it called al_getdiagnostics: { "projectPath": "c:\\pathtomyproject\\app", "limit": 500 } The behavior is somewhat similar to VS Code. If I build the project, in the output view, I see all warnings from the compiler and all code analyzer tools, but in the problems view, I only see the warnings from the compiler.

3. Expected behavior I expect the MCP to include the diagnostics from the code cops as well as the problems view in VS code to include the warnings from the code cops.

4. Actual behavior asking claude for the number of warnings grouped by code, shows only AL warnings

Image

Doing the same in VS code, I get more warnings regarding code cops that are not shown in the MCP.

5. Versions:

  • AL Language: 18.0.2293710
  • Visual Studio Code: current insider build
  • Business Central: current BC28
  • List of Visual Studio Code extensions that you have installed: does not apply for the question
  • Operating System:
    • [x] Windows
    • [ ] Linux
    • [ ] MacOS

Final Checklist

Please remember to do the following:

  • [x] Search the issue repository to ensure you are reporting a new issue
  • [x] Reproduce the issue after disabling all extensions except the AL Language extension
  • [x] Simplify your code around the issue to better isolate the problem

matthiasrabus avatar Apr 23 '26 20:04 matthiasrabus

We hit the same symptom with the dotnet tool MCP server and can narrow the root cause: analyzer aliases and relative ruleset paths are silently ignored; absolute paths work.

Environment: microsoft.dynamics.businesscentral.development.tools 18.0.37.11445-beta (dotnet tool), al launchmcpserver, stdio transport, Windows 11, net10.0.

Repro matrix

Project with a guaranteed CodeCop hit (unused local variable → AA0137), compiled via al_compile with {"options":{"enableCodeAnalysis":true,"onlyErrors":false}}:

--codeanalyzers value at launch Cop diagnostics
CodeCop none (silent)
${CodeCop} (quoted, reaches the process literally) none (silent)
per-call "codeAnalyzers": ["${CodeCop}"] none (silent)
C:\...\tools\net10.0\any\Microsoft.Dynamics.Nav.CodeCop.dll (absolute path) AA0137 + full CodeCop output
per-call absolute path works too

In all failing cases the compile succeeds and the diagnostics array is simply empty — no warning or error anywhere (stderr, log file at default level, or tool response) that the analyzer reference failed to resolve. The startup banner even echoes the unresolved values back as accepted configuration.

The same silent-ignore applies to --ruleset:

--ruleset value Effect
al.ruleset.json (relative to server CWD; echoed in startup banner) not applied — cop diagnostics return at raw default severities
absolute path to the same file applied correctly (Hidden/None/Warning actions all honored)

Suggested fixes

  1. Resolve ${CodeCop}-style well-known aliases in the MCP server the same way the VS Code extension does (the per-call codeAnalyzers parameter description explicitly documents '${CodeCop}' as a supported value, so today the documented value silently does nothing).
  2. Resolve relative --ruleset / --codeanalyzers paths against the server working directory (or the workspace root) instead of dropping them.
  3. Until then: emit a warning to stderr/log when an analyzer reference or ruleset path fails to resolve — the silent no-op makes this very hard to diagnose (it reads as "project is clean").

One more data point for triage: when CodeCop is loaded via absolute path, ~5 individual rules fail with AD0001 (System.IO.FileNotFoundException: Could not load 'Microsoft.Dynamics.Nav.Analyzers.Common'), even though that assembly sits in the same directory — looks like an assembly-load-context issue specific to path-based loading. The remaining rules run fine.

FBakkensen avatar Jun 12 '26 03:06 FBakkensen