LSP Bridge

The LSP Bridge extension connects Mayros agents to language servers via the Language Server Protocol. It provides four agent tools for diagnostics, hover, go-to-definition, and completions — with a Cortex backend as fallback when live servers are unavailable.

Architecture

The bridge manages language server processes through the LspServerManager and stores results in Cortex via the LspCortexBackend. Tools query live servers first, then fall back to Cortex-stored data.

Agent tool call
  └── Try live LSP server (via LspServerManager)
        ├── Success → return result
        └── Failure → fall back to Cortex (via LspCortexBackend)
              └── Query code-indexer triples

Agent tools

lsp_diagnostics

Get errors and warnings for a file or all files.

typescript
{
  uri?: string  // File URI (e.g., "file:///src/index.ts"). Shows all if omitted.
}

Queries the live server first using textDocument/diagnostic. Falls back to Cortex for stored diagnostics. Results include severity, line/character, and message.

lsp_hover

Get type information and documentation for a position.

typescript
{
  uri: string,       // File URI
  line: number,      // 0-based line number
  character: number  // 0-based character offset
}

Sends textDocument/hover to the live server. Returns the hover contents (type signatures, documentation).

lsp_definition

Navigate to the definition of a symbol.

typescript
{
  uri: string,       // File URI
  line: number,      // 0-based line number
  character: number, // 0-based character offset
  name?: string      // Symbol name (for Cortex fallback)
}

Sends textDocument/definition to the live server. Falls back to Cortex code-indexer lookup using the symbol name. Returns file URI, line, and character for each definition location.

lsp_completions

Get completion suggestions at a position.

typescript
{
  uri: string,       // File URI
  line: number,      // 0-based line number
  character: number  // 0-based character offset
}

Sends textDocument/completion to the live server. Returns up to 20 completion items with labels and details.

Server lifecycle

Language servers are configured in the plugin config with their command, arguments, and language ID. The LspServerManager handles:

OperationDescription
start(config)Spawn a language server process
stop(language)Stop a specific server
stopAll()Stop all running servers
isRunning(language)Check if a server is active
sendRequest(language, method, params)Send an LSP request
getStatus()List server status (running/stopped)

Servers are auto-started on session_start and stopped on session_end.

Diagnostic notifications

LSP servers push diagnostics via textDocument/publishDiagnostics notifications. The server manager handles these notifications and stores them in Cortex for later retrieval.

Cortex storage

The LspCortexBackend stores and retrieves LSP data using Cortex triples:

  • Diagnostics: stored by file URI with severity, range, and message
  • Definitions: stored by symbol name with file path, line, and type

This allows Cortex to serve as a persistent cache — agents can query diagnostics even when the LSP server is offline.

Language support

Any language server that implements the LSP specification can be configured. Common examples:

LanguageServerCommand
TypeScripttypescript-language-servertypescript-language-server --stdio
Rustrust-analyzerrust-analyzer
Pythonpylsppylsp
Gogoplsgopls serve

CLI

bash
mayros lsp start [--language ts]  # Start LSP server(s)
mayros lsp stop [--language ts]   # Stop LSP server(s)
mayros lsp status                 # Show running servers
mayros lsp diagnostics [--file f] # Show diagnostics from Cortex