connect MCP language queries to project LSP

This commit is contained in:
2026-09-29 09:21:59 +01:00
parent feb57c5298
commit c1834bad1f
24 changed files with 757 additions and 21 deletions
@@ -125,6 +125,68 @@ symbols reuse the existing project LSP. Other queries/refactoring proposals are
exposed only when supported; returned edits MUST respect project versus read-only
SDK/library scope. No query applies filesystem edits.
### 3.1 Language Query Operations
`studio_language_query` uses the existing project's LSP server via a real client,
not a parallel language implementation or a direct call into compiler semantics.
Its successful value is `{operation, result, limitations}`. `result` is the JSON
projection of the existing LSP response (including null or an empty list when
appropriate); LSP union wrappers are unwrapped. Provider classes remain inside
the application adapter. Studio API/Core use maps, lists and scalar values only.
| Operation | Required parameters beyond projectRoot/taskId |
| --- | --- |
| `diagnostics`, `documentSymbols`, `documentLinks`, `foldingRanges`, `formatting`, `semanticTokens` | `parameters.uri` |
| `hover`, `completion`, `signatureHelp`, `definition`, `references`, `prepareRename`, `prepareCallHierarchy` | `uri`, `position`; references optionally accepts `includeDeclaration` |
| `rename` | `uri`, `position`, `newName` |
| `workspaceSymbols` | optional `query`; no document URI is needed |
| `selectionRanges` | `uri`, nonempty `positions` |
| `codeActions` | `uri`, ordered `range`; diagnostics are obtained from the current saved file |
| `incomingCalls`, `outgoingCalls` | task-local `itemId` from a hierarchy result |
Support MUST be checked against the running server's initialize response before
dispatch. Unknown operations, including currently unsupported type hierarchy,
return `UNSUPPORTED_CAPABILITY`. Context publishes the installed provider's
capabilities, including semantic tokens; hierarchy and rename preparations use
their corresponding server capability. Positions are zero-based UTF-16 offsets,
must fit the saved file and must not split surrogate pairs. Reversed ranges and
missing operation-specific parameters are rejected.
The application lifecycle supplies each open project's bound loopback LSP
endpoint. Studio uses OS-assigned ports so different open projects do not compete
for one fixed port. The public LSP configuration default remains unchanged for
other hosts. A manifest language change requires reopening that project's server;
the adapter MUST NOT send queries to a server bound to another language/root.
Each query uses a short-lived client connection. For document requests, the
adapter opens exactly the saved UTF-8 text and waits for that connection's
published diagnostics before issuing the semantic query. Other dependency files
are read from disk by the existing compiler bridge. A fresh connection prevents
reuse of stale overlays from previous requests or the human editor. Unsaved or
concurrent external writes remain the developer's responsibility.
Queries require the current task, share the project's work admission/cancellation
and DEV operation observation, and do not silently queue behind conflicting work.
Return/reclaim invalidates the task immediately, waits for worker termination,
then clears task-local hierarchy items before manual control is restored. Item
IDs from another task or project cannot be used. Client sockets/listeners close
on success, failure, timeout or cancellation; project-server shutdown closes its
accepted sockets and executor. A lost client does not independently grant control.
The adapter bounds connect time to 2 seconds and the LSP exchange to 10 seconds;
Core bounds the request worker wait to 12 seconds. Documents are limited to 4 MiB
of UTF-8 and task-local hierarchy state to 1024 items. These are adapter resource
guards, unrelated to the runtime's deterministic frame/watchdog semantics.
Document URIs must resolve to known physical project/dependency source files.
Symlink targets are canonicalized before admission. External sources may be
queried, but edit-producing queries on read-only roots are rejected. Every URI in
returned workspace-edit proposals is checked against the same editable/read-only
scope; an unsafe proposal is rejected as a whole. File-operation edits and
executable commands are not offered; `workspace/applyEdit` is always refused.
No query writes a file. Virtual SDK declarations may not have physical definition
locations in the existing LSP; indexed SDK references remain available instead.
## 4. Result, Error and Operation Contracts
Successful tools return `isError:false` with structuredContent
@@ -294,8 +356,8 @@ authentication, Origin, endpoint/method/version handling, tool dispatch, malform
or oversized input, closure, restart and old-token rejection. Provider doubles
exist only in tests. Composition starts/closes transport with Studio.
The production registry composes `studio_project_context` and `studio_reference_read`
as of step 18; other
The production registry composes `studio_project_context`, `studio_reference_read`
and `studio_language_query` as of step 19; other
tools are advertised only when their functional handlers are connected.
DEV configuration-copy stays unavailable until step 21. Passing this transport
gate is not the phase 3 or final external-agent acceptance gate. API/Core and