Using the Salesforce LSP
The salesforce-development plugin hosts a local MCP server named
salesforce-lsp that lazily spawns Salesforce Language Server children and
exposes their semantic capabilities as MCP tools. This skill is the contract
other skills follow when they call those tools, and the answer to "how do I use
the Salesforce LSP?" — what each tool does, how to read its result, what every
error code means, and how to fall back when the host is absent.
This is a documentation/reference skill. It does not author or deploy code; it
tells you (and other skills) how to drive the LSP tools correctly.
This plugin build vendors Apex + SOQL only. The salesforce-lsp host
ships the Apex language server (@salesforce/apex-ls) and the SOQL language
server. The LWC language server is intentionally not bundled in this
plugin — the lwc.* tools are registered by the host but will always return
an unavailable-class envelope here. Treat any lwc.* call as unavailable
and use the fallback (read the component source / deploy-compile).
When to Use This Skill
- A user asks how to use the Salesforce LSP, or which LSP/MCP tools are available.
- A user asks what a specific tool does (
apex.diagnostics, validate_soql,
complete_soql, etc.) or how to read its output.
- An LSP tool returned an error envelope (
lsp_disabled, spawn_timeout,
circuit_open, no_apex_workspace, no_org_connected) and you need to know
what it means and how to recover.
- You're authoring or reviewing another skill that calls an LSP tool and need the
canonical call/fallback pattern.
- The LSP seems broken and you need to debug it (
lsp.health,
${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor, the kill switch).
The Tools
All tools are served by the MCP server salesforce-lsp (invoke names follow
the plugin-prefixed pattern:
mcp__plugin_salesforce-development_salesforce-lsp__<tool_name>, where dots in
tool names become underscores — e.g. apex.diagnostics becomes
mcp__plugin_salesforce-development_salesforce-lsp__apex_diagnostics). Spawning
is lazy: a tool that needs a language server brings the child up on first call (a
one-time cold start of a few seconds for Apex), then reuses it. The pure
static-analysis tools never spawn anything.
Apex (spawns the Apex LSP)
| Tool |
Purpose |
Key input |
Key output |
apex.diagnostics |
Compile-check a .cls/.trigger; surface errors/warnings |
{ filePath } |
{ ok, diagnostics: [{ line, column, severity, message }] } |
apex.hover |
Type/signature at a position |
{ filePath, line, character } |
hover markdown |
apex.documentSymbol |
Outline of a file's symbols |
{ filePath } |
symbol tree |
apex.completion |
Code-completion at a position |
{ filePath, line, character } |
completion items |
SOQL
| Tool |
Purpose |
Spawns? |
Key output |
validate_soql |
Parse a SOQL string for syntax errors |
SOQL LSP |
{ ok, diagnostics: [{ line, column, severity, message }] } |
complete_soql |
Schema-aware completion at a cursor (SObjects, fields, picklist values resolved against the org) |
SOQL LSP |
{ ok, items, expanded, unresolved, hint? } |
extract_soql_from_apex |
Statically pull every inline [SELECT …] out of Apex |
No (pure static) |
{ ok, totalQueries, totalDynamic, files } |
check_soql_selectivity |
Selectivity heuristics (optional org LIMIT-0 probe) |
No by default |
selectivity report |
refresh_org_schema |
Invalidate the cached org describe so completion re-fetches |
No |
{ ok, removed } |
Just deployed a field/object and it won't resolve? When a SOQL or Apex
reference to a freshly-deployed field fails (e.g. No such column 'Foo__c',
or complete_soql doesn't offer it) right after a deploy, the cached org
describe is stale — call refresh_org_schema to invalidate it, then re-run
the check before assuming a code error or renaming anything. This is the lever
for post-deploy schema lag; reach for it before treating the failure as a bug
in your query/class. (It only clears the local cache; it can't speed up
server-side propagation, so if the org itself hasn't finished publishing the
field, re-running after a moment is the fallback.)
LWC — not available in this build
The lwc.* tools (lwc.diagnostics, lwc.hover, lwc.definition,
lwc.completion, lwc.workspace_symbols) are registered by the host but the LWC
language server is not vendored in this plugin. Every lwc.* call returns an
unavailable envelope. For LWC work, fall back to reading the component
source/templates directly or deploy-compiling and reading the CLI errors.
Diagnostics / health
| Tool |
Purpose |
Spawns? |
lsp.health |
Read-only view of kill-switch mode, workspace, per-server state, circuit-breaker state, cold-spawn timing, apex-ls version |
No — never spawns |
Coordinates everywhere are one-based (line/column). validate_soql
diagnostic coordinates are relative to the query string, not a file — when a
query came from extract_soql_from_apex, translate back using that query's range.
The Call / Fallback Contract
Every skill that calls an LSP tool follows the same three rules:
- Prefer the LSP tool over guessing. If a tool exists for the step (validate
a query, compile-check a class, complete against the org schema), call it
before falling back to hand-analysis.
- Treat an error envelope as "unavailable," never as "passed." A tool may
return
{ error: <code> } instead of a result (see Error Codes). On any such
code, record <tool>=unavailable: <code> in your report and continue down the
fallback path — never report the input as valid/clean just because the
check didn't run.
- Degrade, don't fail. The LSP is an accelerator, not a hard dependency. If
the host isn't available at all, the
salesforce-lsp tools simply won't
exist — fall back to the CLI/manual path for that step and say so.
When the LSP host is absent
If the plugin/host isn't available, the MCP tools above are not registered, so a
call to (e.g.) validate_soql will not resolve. Detect this the same way you
detect an error envelope — the tool is unavailable — and use the documented
fallback:
| LSP tool unavailable |
Fallback |
apex.diagnostics |
Deploy/compile via sf project deploy and read CLI errors |
validate_soql |
Smoke-check by running the query read-only via sf data query --json (a parse error surfaces in the CLI error) |
complete_soql |
sf sobject describe --sobject <O> --json for fields; author from the user's stated names |
extract_soql_from_apex |
Read the file(s) and locate [SELECT … ] by hand |
apex.completion / apex.hover |
Read the source directly |
lwc.* (always unavailable here) |
Read the component source/templates directly, or deploy-compile and read CLI errors |
Error Codes
A tool returns { error: <code> } (or, for complete_soql, a hint) instead of
a result. Each maps to a recovery:
| Code |
Meaning |
What to do |
lsp_disabled |
The kill switch (SFDX_LSP) forbids this language |
Use the non-LSP fallback; or re-enable the LSP (see Debugging) |
spawn_timeout |
The language server didn't come up in time |
Retry once; if it persists, fall back and run ${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor |
circuit_open |
Repeated spawn failures tripped the breaker; calls are short-circuited |
Fall back now; investigate with lsp.health / ${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor |
no_apex_workspace |
No classes/*.cls under any package dir — Apex tools won't spawn |
Expected in a non-Apex project; nothing to check |
no_org_connected |
(complete_soql hint) org schema couldn't be resolved |
Keyword completion still works; ask for exact field/object names or connect an org. Do not surface __…_PLACEHOLDER labels as real fields |
The first three are transient/config states shared by every spawning tool; the
rest are expected, healthy states for a particular workspace/org/file context —
not signs of a broken install. (no_lwc_bundles / unsupported_lwc_file are
LWC-only codes; in this build the LWC server is not vendored, so lwc.* returns
unavailable regardless.)
Debugging the LSP
Three layers, cheapest first:
lsp.health (MCP tool). The fastest check — never spawns a child. Reports
the kill-switch mode, resolved workspace, per-server status, circuit-breaker
state, last cold-spawn timing, and the vendored apex-ls version. Ask Claude to
"run lsp.health," or call the lsp.health tool directly.
bin/lsp-doctor (CLI). A deeper, install-level diagnostic for support and
onboarding. Verifies the committed bundles exist, the vendored apex-ls
artifacts resolve, the org-schema cache is parseable, and each LSP child can
actually spawn. Exits 0 when healthy, 1 with structured per-check output
when something is wrong.
"${CLAUDE_PLUGIN_ROOT}"/bin/lsp-doctor # human-readable report
"${CLAUDE_PLUGIN_ROOT}"/bin/lsp-doctor --json # machine-readable
"${CLAUDE_PLUGIN_ROOT}"/bin/lsp-doctor --no-spawn # skip child-spawn probes (CI/restricted)
(In this build lsp-doctor will report the LWC server as missing — that is
expected; only Apex + SOQL are vendored here.)
SFDX_LSP_DEBUG=1. Emits single-line JSON telemetry (spawn timing, cache
hits, circuit events, per-tool latency) to stderr. Off by default (zero
overhead).
The kill switch — SFDX_LSP
The fast way to control or disable the LSP. Set the environment variable:
SFDX_LSP |
Effect |
unset / all |
Every vendored LSP may spawn (default) |
apex-only |
Only the Apex LSP may spawn; SOQL tools return lsp_disabled |
disabled |
No LSP spawns; every LSP tool returns lsp_disabled |
To rule the LSP in or out of a problem, set SFDX_LSP=disabled and re-run: if the
issue persists it isn't the LSP, and skills will have fallen back to their non-LSP
paths automatically. An unknown value defaults to all (with a warning) so a typo
never silently disables the feature.
Pre-deploy diagnostics gate
A PreToolUse hook (bin/lsp-precheck) runs Apex diagnostics on the
.cls/.trigger files a sf project deploy start/validate is about to push,
and emits a decision. It is fail-open: any error (including a missing/slow
LSP) allows the deploy. Mode is controlled by SFDX_LSP_DEPLOY_GATE
(off | warn | block, default warn) — warn surfaces diagnostics without
blocking; block denies a deploy that has Apex compile errors.
Verification
- Asked "how do I use the Salesforce LSP tools?", this skill is the match and lists
the tools, their inputs/outputs, and the fallback contract.
- Appears in the
/skills listing as platform-lsp-integrate.
- Given an error code (e.g.
no_apex_workspace), it explains the meaning and the
correct recovery without treating the unrun check as a pass.
Cross-Skill Integration
| Need |
Delegate to |
| Compile-check + analyze Apex you just wrote |
platform-apex-generate |
Validate inline SOQL in .cls/.trigger |
validate_soql (this skill); fallback: run read-only via sf data query --json |
| Author & run a SOQL query against the org |
complete_soql + sf data query |
| Pre-deploy diagnostics gate behavior |
see "Pre-deploy diagnostics gate" above |
1---2name: platform-lsp-integrate3description: Reference for how to call the Salesforce LSP MCP tools and what to do when they are unavailable. Use when the user asks how to use the Salesforce LSP, which LSP/MCP tools exist, what apex.diagnostics / validate_soql / complete_soql do, why an LSP tool returned an error like lsp_disabled or no_apex_workspace or no_org_connected, how to debug the LSP host, or how to turn the LSP off. Also the contract other skills follow when they call an LSP tool: which tool to prefer, how to read its result, and the fallback when the LSP host is absent. DO NOT TRIGGER for generating or editing Apex/LWC/metadata (use platform-apex-generate), running deploys (use platform-metadata-deploy), or SOQL authoring (use platform-soql-query); this skill is a reference and contract document — use it only when the question is specifically about the LSP layer or its MCP tools.4---5
6# Using the Salesforce LSP
7
8The `salesforce-development` plugin hosts a local MCP server named
9**`salesforce-lsp`** that lazily spawns Salesforce Language Server children and
10exposes their semantic capabilities as MCP tools. This skill is the **contract**
11other skills follow when they call those tools, and the answer to "how do I use
12the Salesforce LSP?" — what each tool does, how to read its result, what every
13error code means, and how to fall back when the host is absent.
14
15This is a documentation/reference skill. It does not author or deploy code; it
16tells you (and other skills) how to drive the LSP tools correctly.
17
18> **This plugin build vendors Apex + SOQL only.** The `salesforce-lsp` host
19> ships the Apex language server (`@salesforce/apex-ls`) and the SOQL language
20> server. The **LWC** language server is intentionally **not** bundled in this
21> plugin — the `lwc.*` tools are registered by the host but will always return
22> an `unavailable`-class envelope here. Treat any `lwc.*` call as unavailable
23> and use the fallback (read the component source / deploy-compile).
24
25## When to Use This Skill
26
27- A user asks how to use the Salesforce LSP, or which LSP/MCP tools are available.
28- A user asks what a specific tool does (`apex.diagnostics`, `validate_soql`,
29 `complete_soql`, etc.) or how to read its output.
30- An LSP tool returned an error envelope (`lsp_disabled`, `spawn_timeout`,
31 `circuit_open`, `no_apex_workspace`, `no_org_connected`) and you need to know
32 what it means and how to recover.
33- You're authoring or reviewing another skill that calls an LSP tool and need the
34 canonical call/fallback pattern.
35- The LSP seems broken and you need to debug it (`lsp.health`,
36 `${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor`, the kill switch).
37
38## The Tools
39
40All tools are served by the MCP server **`salesforce-lsp`** (invoke names follow
41the plugin-prefixed pattern:
42`mcp__plugin_salesforce-development_salesforce-lsp__<tool_name>`, where dots in
43tool names become underscores — e.g. `apex.diagnostics` becomes
44`mcp__plugin_salesforce-development_salesforce-lsp__apex_diagnostics`). Spawning
45is lazy: a tool that needs a language server brings the child up on first call (a
46one-time cold start of a few seconds for Apex), then reuses it. The pure
47static-analysis tools never spawn anything.
48
49### Apex (spawns the Apex LSP)
50
51| Tool | Purpose | Key input | Key output |
52|---|---|---|---|
53| `apex.diagnostics` | Compile-check a `.cls`/`.trigger`; surface errors/warnings | `{ filePath }` | `{ ok, diagnostics: [{ line, column, severity, message }] }` |
54| `apex.hover` | Type/signature at a position | `{ filePath, line, character }` | hover markdown |
55| `apex.documentSymbol` | Outline of a file's symbols | `{ filePath }` | symbol tree |
56| `apex.completion` | Code-completion at a position | `{ filePath, line, character }` | completion items |
57
58### SOQL
59
60| Tool | Purpose | Spawns? | Key output |
61|---|---|---|---|
62| `validate_soql` | Parse a SOQL string for **syntax** errors | SOQL LSP | `{ ok, diagnostics: [{ line, column, severity, message }] }` |
63| `complete_soql` | Schema-aware completion at a cursor (SObjects, fields, picklist values resolved against the org) | SOQL LSP | `{ ok, items, expanded, unresolved, hint? }` |
64| `extract_soql_from_apex` | Statically pull every inline `[SELECT …]` out of Apex | **No** (pure static) | `{ ok, totalQueries, totalDynamic, files }` |
65| `check_soql_selectivity` | Selectivity heuristics (optional org LIMIT-0 probe) | **No** by default | selectivity report |
66| `refresh_org_schema` | Invalidate the cached org describe so completion re-fetches | **No** | `{ ok, removed }` |
67
68> **Just deployed a field/object and it won't resolve?** When a SOQL or Apex
69> reference to a *freshly-deployed* field fails (e.g. `No such column 'Foo__c'`,
70> or `complete_soql` doesn't offer it) right after a deploy, the cached org
71> describe is stale — call **`refresh_org_schema`** to invalidate it, then re-run
72> the check before assuming a code error or renaming anything. This is the lever
73> for post-deploy schema lag; reach for it *before* treating the failure as a bug
74> in your query/class. (It only clears the local cache; it can't speed up
75> server-side propagation, so if the org itself hasn't finished publishing the
76> field, re-running after a moment is the fallback.)
77
78### LWC — not available in this build
79
80The `lwc.*` tools (`lwc.diagnostics`, `lwc.hover`, `lwc.definition`,
81`lwc.completion`, `lwc.workspace_symbols`) are registered by the host but the LWC
82language server is **not vendored** in this plugin. Every `lwc.*` call returns an
83unavailable envelope. For LWC work, fall back to reading the component
84source/templates directly or deploy-compiling and reading the CLI errors.
85
86### Diagnostics / health
87
88| Tool | Purpose | Spawns? |
89|---|---|---|
90| `lsp.health` | Read-only view of kill-switch mode, workspace, per-server state, circuit-breaker state, cold-spawn timing, apex-ls version | **No** — never spawns |
91
92Coordinates everywhere are **one-based** (`line`/`column`). `validate_soql`
93diagnostic coordinates are relative to the **query string**, not a file — when a
94query came from `extract_soql_from_apex`, translate back using that query's range.
95
96## The Call / Fallback Contract
97
98Every skill that calls an LSP tool follows the same three rules:
99
1001. **Prefer the LSP tool over guessing.** If a tool exists for the step (validate
101 a query, compile-check a class, complete against the org schema), call it
102 before falling back to hand-analysis.
1032. **Treat an error envelope as "unavailable," never as "passed."** A tool may
104 return `{ error: <code> }` instead of a result (see Error Codes). On any such
105 code, record `<tool>=unavailable: <code>` in your report and continue down the
106 fallback path — **never** report the input as valid/clean just because the
107 check didn't run.
1083. **Degrade, don't fail.** The LSP is an accelerator, not a hard dependency. If
109 the host isn't available at all, the `salesforce-lsp` tools simply won't
110 exist — fall back to the CLI/manual path for that step and say so.
111
112### When the LSP host is absent
113
114If the plugin/host isn't available, the MCP tools above are not registered, so a
115call to (e.g.) `validate_soql` will not resolve. Detect this the same way you
116detect an error envelope — the tool is unavailable — and use the documented
117fallback:
118
119| LSP tool unavailable | Fallback |
120|---|---|
121| `apex.diagnostics` | Deploy/compile via `sf project deploy` and read CLI errors |
122| `validate_soql` | Smoke-check by running the query read-only via `sf data query --json` (a parse error surfaces in the CLI error) |
123| `complete_soql` | `sf sobject describe --sobject <O> --json` for fields; author from the user's stated names |
124| `extract_soql_from_apex` | Read the file(s) and locate `[SELECT … ]` by hand |
125| `apex.completion` / `apex.hover` | Read the source directly |
126| `lwc.*` (always unavailable here) | Read the component source/templates directly, or deploy-compile and read CLI errors |
127
128## Error Codes
129
130A tool returns `{ error: <code> }` (or, for `complete_soql`, a `hint`) instead of
131a result. Each maps to a recovery:
132
133| Code | Meaning | What to do |
134|---|---|---|
135| `lsp_disabled` | The kill switch (`SFDX_LSP`) forbids this language | Use the non-LSP fallback; or re-enable the LSP (see Debugging) |
136| `spawn_timeout` | The language server didn't come up in time | Retry once; if it persists, fall back and run `${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor` |
137| `circuit_open` | Repeated spawn failures tripped the breaker; calls are short-circuited | Fall back now; investigate with `lsp.health` / `${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor` |
138| `no_apex_workspace` | No `classes/*.cls` under any package dir — Apex tools won't spawn | Expected in a non-Apex project; nothing to check |
139| `no_org_connected` | (`complete_soql` hint) org schema couldn't be resolved | Keyword completion still works; ask for exact field/object names or connect an org. **Do not** surface `__…_PLACEHOLDER` labels as real fields |
140
141The first three are transient/config states shared by every spawning tool; the
142rest are expected, healthy states for a particular workspace/org/file context —
143not signs of a broken install. (`no_lwc_bundles` / `unsupported_lwc_file` are
144LWC-only codes; in this build the LWC server is not vendored, so `lwc.*` returns
145unavailable regardless.)
146
147## Debugging the LSP
148
149Three layers, cheapest first:
150
1511. **`lsp.health` (MCP tool).** The fastest check — never spawns a child. Reports
152 the kill-switch mode, resolved workspace, per-server status, circuit-breaker
153 state, last cold-spawn timing, and the vendored apex-ls version. Ask Claude to
154 "run lsp.health," or call the `lsp.health` tool directly.
155
1562. **`bin/lsp-doctor` (CLI).** A deeper, install-level diagnostic for support and
157 onboarding. Verifies the committed bundles exist, the vendored apex-ls
158 artifacts resolve, the org-schema cache is parseable, and each LSP child can
159 actually spawn. Exits `0` when healthy, `1` with structured per-check output
160 when something is wrong.
161
162 ```bash
163 "${CLAUDE_PLUGIN_ROOT}"/bin/lsp-doctor # human-readable report
164 "${CLAUDE_PLUGIN_ROOT}"/bin/lsp-doctor --json # machine-readable
165 "${CLAUDE_PLUGIN_ROOT}"/bin/lsp-doctor --no-spawn # skip child-spawn probes (CI/restricted)
166 ```
167
168 (In this build `lsp-doctor` will report the LWC server as missing — that is
169 expected; only Apex + SOQL are vendored here.)
170
1713. **`SFDX_LSP_DEBUG=1`.** Emits single-line JSON telemetry (spawn timing, cache
172 hits, circuit events, per-tool latency) to stderr. Off by default (zero
173 overhead).
174
175### The kill switch — `SFDX_LSP`
176
177The fast way to control or disable the LSP. Set the environment variable:
178
179| `SFDX_LSP` | Effect |
180|---|---|
181| unset / `all` | Every vendored LSP may spawn (default) |
182| `apex-only` | Only the Apex LSP may spawn; SOQL tools return `lsp_disabled` |
183| `disabled` | No LSP spawns; every LSP tool returns `lsp_disabled` |
184
185To rule the LSP in or out of a problem, set `SFDX_LSP=disabled` and re-run: if the
186issue persists it isn't the LSP, and skills will have fallen back to their non-LSP
187paths automatically. An unknown value defaults to `all` (with a warning) so a typo
188never silently disables the feature.
189
190## Pre-deploy diagnostics gate
191
192A `PreToolUse` hook (`bin/lsp-precheck`) runs Apex diagnostics on the
193`.cls`/`.trigger` files a `sf project deploy start`/`validate` is about to push,
194and emits a decision. It is **fail-open**: any error (including a missing/slow
195LSP) allows the deploy. Mode is controlled by `SFDX_LSP_DEPLOY_GATE`
196(`off` | `warn` | `block`, default `warn`) — `warn` surfaces diagnostics without
197blocking; `block` denies a deploy that has Apex compile errors.
198
199## Verification
200
201- Asked "how do I use the Salesforce LSP tools?", this skill is the match and lists
202 the tools, their inputs/outputs, and the fallback contract.
203- Appears in the `/skills` listing as `platform-lsp-integrate`.
204- Given an error code (e.g. `no_apex_workspace`), it explains the meaning and the
205 correct recovery without treating the unrun check as a pass.
206
207## Cross-Skill Integration
208
209| Need | Delegate to |
210|---|---|
211| Compile-check + analyze Apex you just wrote | `platform-apex-generate` |
212| Validate inline SOQL in `.cls`/`.trigger` | `validate_soql` (this skill); fallback: run read-only via `sf data query --json` |
213| Author & run a SOQL query against the org | `complete_soql` + `sf data query` |
214| Pre-deploy diagnostics gate behavior | see "Pre-deploy diagnostics gate" above |