Using the Salesforce LSP
The
plugin hosts a local MCP server named
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
host
ships the Apex language server (
) and the SOQL language
server. The
LWC language server is intentionally
not bundled in this
plugin — the
tools are registered by the host but will always return
an
-class envelope here. Treat any
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 (, ,
, etc.) or how to read its output.
- An LSP tool returned an error envelope (, ,
, , ) 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 (,
${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor
, the kill switch).
The Tools
All tools are served by the MCP server
(invoke names follow
the plugin-prefixed pattern:
mcp__plugin_salesforce-development_salesforce-lsp__<tool_name>
, where dots in
tool names become underscores — e.g.
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 |
|---|
| Compile-check a /; surface errors/warnings | | { ok, diagnostics: [{ line, column, severity, message }] }
|
| Type/signature at a position | { filePath, line, character }
| hover markdown |
| Outline of a file's symbols | | symbol tree |
| Code-completion at a position | { filePath, line, character }
| completion items |
SOQL
| Tool | Purpose | Spawns? | Key output |
|---|
| Parse a SOQL string for syntax errors | SOQL LSP | { ok, diagnostics: [{ line, column, severity, message }] }
|
| Schema-aware completion at a cursor (SObjects, fields, picklist values resolved against the org) | SOQL LSP | { ok, items, expanded, unresolved, hint? }
|
| Statically pull every inline out of Apex | No (pure static) | { ok, totalQueries, totalDynamic, files }
|
| Selectivity heuristics (optional org LIMIT-0 probe) | No by default | selectivity report |
| Invalidate the cached org describe so completion re-fetches | No | |
Just deployed a field/object and it won't resolve? When a SOQL or Apex
reference to a
freshly-deployed field fails (e.g.
,
or
doesn't offer it) right after a deploy, the cached org
describe is stale — call
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
tools (
,
,
,
,
) are registered by the host but the LWC
language server is
not vendored in this plugin. Every
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? |
|---|
| 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 (
/
).
diagnostic coordinates are relative to the
query string, not a file — when a
query came from
, 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 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 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.)
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 |
|---|
| Deploy/compile via and read CLI errors |
| Smoke-check by running the query read-only via (a parse error surfaces in the CLI error) |
| sf sobject describe --sobject <O> --json
for fields; author from the user's stated names |
| Read the file(s) and locate by hand |
| / | Read the source directly |
| (always unavailable here) | Read the component source/templates directly, or deploy-compile and read CLI errors |
Error Codes
A tool returns
(or, for
, a
) instead of
a result. Each maps to a recovery:
| Code | Meaning | What to do |
|---|
| The kill switch () forbids this language | Use the non-LSP fallback; or re-enable the LSP (see Debugging) |
| The language server didn't come up in time | Retry once; if it persists, fall back and run ${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor
|
| Repeated spawn failures tripped the breaker; calls are short-circuited | Fall back now; investigate with / ${CLAUDE_PLUGIN_ROOT}/bin/lsp-doctor
|
| No under any package dir — Apex tools won't spawn | Expected in a non-Apex project; nothing to check |
| ( hint) org schema couldn't be resolved | Keyword completion still works; ask for exact field/object names or connect an org. Do not surface 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. (
/
are
LWC-only codes; in this build the LWC server is not vendored, so
returns
unavailable regardless.)
Debugging the LSP
Three layers, cheapest first:
-
(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
tool directly.
-
(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
when healthy,
with structured per-check output
when something is wrong.
bash
"${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
will report the LWC server as missing — that is
expected; only Apex + SOQL are vendored here.)
-
. Emits single-line JSON telemetry (spawn timing, cache
hits, circuit events, per-tool latency) to stderr. Off by default (zero
overhead).
The kill switch —
The fast way to control or disable the LSP. Set the environment variable:
| Effect |
|---|
| unset / | Every vendored LSP may spawn (default) |
| Only the Apex LSP may spawn; SOQL tools return |
| No LSP spawns; every LSP tool returns |
To rule the LSP in or out of a problem, set
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
(with a warning) so a typo
never silently disables the feature.
Pre-deploy diagnostics gate
A
hook (
) runs Apex diagnostics on the
/
files a
/
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
(
|
|
, default
) —
surfaces diagnostics without
blocking;
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 listing as .
- Given an error code (e.g. ), 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 | |
| Validate inline SOQL in / | (this skill); fallback: run read-only via |
| Author & run a SOQL query against the org | + |
| Pre-deploy diagnostics gate behavior | see "Pre-deploy diagnostics gate" above |