ALCops MCP Server
An MCP server that brings AL code fixes to AI assistants, and re-exposes Microsoft's own AL MCP tools alongside them. Lets Claude, Cursor, and other MCP clients compile Business Central AL projects, browse rules, and apply fixes — all without leaving the conversation.
Microsoft's almcp covers compiling, diagnostics, symbols, publishing, tests and translations, but has no code-fix capability at all (its LSP mode explicitly advertises CodeActionProvider = false) and no way to enumerate rules. Those two gaps are what this server adds; everything else it proxies straight through, so you get one endpoint instead of two.
Quick Start
dotnet tool install -g Microsoft.Dynamics.BusinessCentral.Development.Tools
dotnet tool install -g ALCops.Mcp
Add to your .mcp.json (Claude Code) or claude_desktop_config.json (Claude Desktop):
{
"mcpServers": {
"alcops": {
"command": "alcops-mcp"
}
}
}
Requirements
- .NET 10.0 SDK or Runtime
- BC Development Tools v18.0 or higher from the
Microsoft.Dynamics.BusinessCentral.Development.Tools dotnet tool. Alternatively, point --devtools-path or BCDEVELOPMENTTOOLSPATH at any directory containing the DevTools DLLs (e.g. the AL VS Code extension's bin/<platform> folder).
Note: v16 and earlier are not supported — the BC Development Tools DLLs introduced breaking API changes in v17. almcp also first shipped in v17, so on an older toolchain only the native tools below are available.
Platform support
| OS |
How almcp is launched |
Notes |
| Windows |
Native almcp.exe |
Ships in the nupkg. |
| Linux |
dotnet almcp.dll |
The nupkg has no extension-less launcher; the server falls back to the dotnet host automatically. |
| macOS |
dotnet almcp.dll |
Same as Linux. |
The native tools (list_rules, get_fixes, apply_fix, apply_fix_all) work on every OS regardless of almcp availability. analyze wraps al_compile and therefore needs almcp.
Tools
Native (this server)
| Tool |
Description |
list_rules |
List analyzer rules with metadata (ID, title, severity, category, cop). |
get_fixes |
Get available code fixes for a specific diagnostic at a location. Returns { diagnosticId, filePath, line, column, fixes: [{ equivalenceKey, title, providerName }] }; when nothing matches, the error NotFound with a reason (see Errors). You need a fix's equivalenceKey only when a rule offers several fixes; otherwise apply_fix can be called directly. A listed fix can still be refused by apply_fix / apply_fix_all as NotFound with reason UnsupportedFix when it adds, removes or renames files or edits a file outside the project. |
apply_fix |
Apply a code fix to resolve a diagnostic. equivalenceKey is optional: without it the rule's single fix is applied, and a rule with several distinct fixes is the error Ambiguous with candidates. Returns { applied, dryRun, diagnosticId, fixTitle, equivalenceKey, filePath, changes }: equivalenceKey is the key that was applied and changes lists every file the fix changes as { filePath, diff, truncated } (see Previewing a fix). With dryRun: true nothing is written and applied is false. Writes the fixed content to disk unless the file changed after the fix was computed (error Stale). A fix that edits several files writes all of them or none (Stale if any of them changed); a fix that adds, removes or renames files, or edits a file outside the project, is NotFound with reason: UnsupportedFix and nothing is written; a file that cannot be read, decoded or written is Faulted with reason ReadFailed, UnsupportedEncoding or WriteFailed. The write is atomic (sibling temp file renamed over the target) and keeps the file's encoding, BOM and line endings. |
apply_fix_all |
Apply a code fix to every occurrence of a diagnostic rule across a project or a single file (like VS Code's "Fix all in workspace"). Writes to disk unless dryRun is set. changes ({ filePath, diff, truncated }) describes exactly the files in filesChanged: every computed change on a dry run, the written files otherwise, none after a rolled-back batch, except files the rollback could not restore, which stay in filesChanged; conflicts carry no diff. A rule with several distinct fixes and no equivalenceKey is the error Ambiguous with candidates. Every file the fix changes is written, including side edits to files without an occurrence; a fix that adds, removes or renames files, or edits a file outside the project, is NotFound with reason: UnsupportedFix and nothing is written. A fix-all whose changes include side edits to files without an occurrence is written all or none: if any file has a phase-1 conflict, nothing is written (applied: false, every stale file in conflicts, every occurrence in unfixedDiagnostics). Zero occurrences is a success (applied: false, diagnosticsFound: 0), except a rule the project ruleset suppresses (NotFound with reason: SuppressedByRuleset) or one that no loaded analyzer reports (NotFound with reason: NoAnalyzerForRule). Files that changed on disk mid-operation are skipped and listed in conflicts; the rest are written as one batch — if any write fails, every file already written in that call is restored and nothing from the batch is kept. A batch that fails and is rolled back is a normal (non-isError) result with applied: false, the failure in message and every staged file in conflicts, because the per-file outcome is in the body; only argument, lookup and single-file write failures use the error envelope. |
analyze |
Compile with all configured analyzers and return structured cop + compiler diagnostics (analyzer, hasFix, filters, summary). Wraps al_compile with onlyErrors: false; needs almcp. |
Proxied from Microsoft's almcp
al_compile, al_build, al_getdiagnostics, al_addproject, al_downloadsymbols, al_symbolsearch, al_symbolrelations, al_getpackagedependencies, al_inspectpage, al_publish, al_run_tests, al_searchtranslations, al_writetranslation, al_auth_login, al_auth_logout — the exact set depends on your installed version.
almcp is started in the background, so the native tools are available the moment the server comes up; the al_* tools appear once it has loaded your project (the server sends tools/list_changed, and hosts that don't support it see them on their next tool listing).
Pass --no-proxy to serve only the native tools. Use it when your agent already registers Microsoft's almcp itself, so the al_* tools don't show up twice.
al_compile defaults to onlyErrors: true. Nearly every ALCops rule is a warning, so pass options: { onlyErrors: false } or you will see no cop diagnostics at all. The flag lives inside the options object; a top-level onlyErrors is ignored. The native analyze tool does this for you and adds filtering, sorting and hasFix metadata.
Previewing a fix
Pass dryRun: true to apply_fix or apply_fix_all to see what a fix would change without writing anything. Both tools return the same changes on a real write, so the result always shows what was written. Each entry's diff is a unified diff of hunks only (@@ -a,b +c,d @@ headers with , - and + lines and 3 lines of context, no ---/+++ header since filePath is beside it); lines are compared without their line endings, so an empty diff with the file listed means only line endings changed. A diff longer than 200 KB (200 × 1024 characters) is cut at a line boundary and has truncated: true; a truncated diff keeps its original hunk headers, so their counts can exceed the lines shown, and an empty diff with truncated: true means the first changed line alone exceeds the cap.
Verifying a fix
After apply_fix or apply_fix_all, call analyze (preferred) or al_compile with options.onlyErrors: false to confirm the diagnostic is gone. Both await almcp's internal file watcher, which normally sees the write before the compile starts. The watcher gate is not debounced, so on slow file systems or right after a large apply_fix_all a second call may be needed. Do not use al_getdiagnostics for this: it returns cached compilation results rather than re-analyzing, and will report stale (or empty) diagnostics. al_build does not await the watcher. Only restarting the server gives a fully fresh almcp workspace.
Editing between calls: get_fixes, apply_fix and apply_fix_all re-read .al files that changed on disk before every call (only changed files are re-parsed), so you can edit files between get_fixes and apply_fix, and neither tool will overwrite a file that no longer matches the text its fix was computed from.
How files are written: each fixed file is written to a sibling <file>.al.<id>.alcops.tmp and then renamed over the original, so a crash or a full disk never leaves a truncated .al file. The file's encoding is detected from its byte-order mark and kept: UTF-8 with or without BOM, UTF-16 and UTF-32 come back exactly as they were, and line endings are untouched. Each file is decoded strictly in its detected encoding (UTF-8 when there is no BOM): a file holding bytes that are invalid in that encoding, such as a legacy Windows-1252 file or a stray Windows-1252 byte in a UTF-8 file with BOM, is never re-encoded; the fix is refused with UnsupportedEncoding instead. Every entry in apply_fix_all's conflicts carries a kind (StaleFile, UnsupportedEncoding, ReadFailed, WriteFailed, RolledBack, NotWritten); apply_fix reports StaleFile as the error Stale and the other kinds as Faulted with that kind as reason. No backup files are created. A stray *.alcops.tmp left by an interrupted write is removed the next time the project is loaded or refreshed.
Errors
Every native tool reports a failure the same way: the MCP result has isError: true, and its single text block holds one JSON envelope. A successful result never sets isError. The full JSON stays in the text block, so a client that hides error results still has the message.
{ "error": "NotFound", "message": "No LC0020 at C:\\src\\MyPage.al:12:17; re-run analyze and use its line/column.", "reason": "NoDiagnosticAtPosition", "filePath": "C:\\src\\MyPage.al", "diagnosticId": "LC0020" }
| Field |
Present |
error |
Always; one of the codes below. |
message |
Always; human-readable. |
reason |
For NotFound, Unavailable, and a Faulted write. |
candidates |
For Ambiguous and NotFound / NoFixForEquivalenceKey: [{ equivalenceKey, title, providerName }]. |
filePath, diagnosticId |
When the error concerns one file or rule. |
detail |
For Faulted from an exception (its full type name) and Unavailable / AlmcpCallFailed (the text almcp returned). |
error |
Meaning |
What to do |
reason |
Invalid |
The arguments are unusable as given: unknown scope, missing filePath, limit not positive, a projectPath that is not an AL project folder, or (for analyze and list_rules) not one of the projects the server was started with. |
Fix the call. |
– |
NotFound |
Nothing matched. |
NoDiagnosticAtPosition: re-run analyze and use its line/column. NoFixForEquivalenceKey: pick a key from candidates. UnsupportedFix (the fix adds, removes or renames files, or edits a file outside the project): stop; apply that fix in VS Code or by hand. Otherwise stop; there is nothing to fix. |
NoFixProvider, FileNotInProject, NoAnalyzerForRule, SuppressedByRuleset, SuppressedByPragma, NoDiagnosticAtPosition, NoFixForDiagnostic, NoFixForEquivalenceKey, UnsupportedFix |
Ambiguous |
apply_fix or apply_fix_all was called without equivalenceKey, and the rule offers several distinct fixes; candidates lists them. |
Pass one equivalenceKey verbatim, or ask the user. |
– |
Stale |
The file changed or was deleted after the fix was computed; nothing was written. |
Re-run the call. |
– |