Supported Languages & Detection
Relevant source files
The following files were used as context for generating this wiki page:
The lsp-mcp-server provides automated language detection and workspace root discovery to bridge the gap between file paths and specialized Language Server Protocol (LSP) instances. By analyzing file extensions and directory structures, the system ensures that the correct language server is spawned and initialized for any given source file.
This system is central to the "first-touch" wake-up logic, where the server automatically starts the necessary LSP client upon the first tool request for a specific file. It supports a wide array of modern programming languages, from web technologies (TypeScript, JavaScript) to systems languages (Rust, C++, Go) and data-focused formats (SQL, GraphQL).
Sources: SKILL.md:14-16, src/services/document-manager.ts:133-138
Language Identification Logic
The server identifies the programming language of a file primarily through its file extension. This identification is critical because it determines which languageId is sent to the LSP server during the didOpen notification and which configured server should handle the file.
Extension Mapping
The DocumentManagerImpl maintains a comprehensive mapping of file extensions to LSP-standard language identifiers. If an extension is not recognized, the system defaults to plaintext.
Sources: src/services/document-manager.ts:38-84
| Extensions | Language ID |
|---|---|
.ts, .tsx | typescript, typescriptreact |
.js, .jsx, .mjs, .cjs | javascript, javascriptreact |
.py, .pyi | python |
.rs | rust |
.go | go |
.c, .h, .cpp, .hpp, .cc, .cxx | c, cpp |
.rb, .php, .swift, .cs | ruby, php, swift, csharp |
.json, .yaml, .yml, .xml | json, yaml, xml |
.html, .css, .scss, .md | html, css, scss, markdown |
.sql, .graphql, .gql | sql, graphql |
The Detection Flow
When a tool request arrives, the ConnectionManager uses the LanguageDetector to resolve the file's language and then locates or creates the appropriate LSPClient.
The diagram shows the decision flow from a raw file path to an initialized LSP client based on extension mapping.
Sources: src/services/document-manager.ts:89-92, src/services/connection-manager.ts
Workspace Root Detection
For an LSP server to function correctly, it must know the project's root directory to resolve imports and provide workspace-wide intelligence. The ConnectionManager automates this by walking up the directory tree from the target file until it finds specific "root markers."
Root Markers by Language
The detection logic looks for configuration files or directory structures that signify a project boundary.
Sources: CLAUDE.md:104-106, src/types.ts:143-145
- JavaScript/TypeScript:
package.json,tsconfig.json - Rust:
Cargo.toml - Go:
go.mod - Python:
pyproject.toml - Generic:
.gitdirectory
Lifecycle Integration
Workspace detection is integrated into the client retrieval process. If no server is running for a detected (serverId, workspaceRoot) pair, one is automatically started.
Sources: CLAUDE.md:38-40, src/types.ts:206-208
This sequence illustrates how language detection and workspace discovery are prerequisites for retrieving an active LSP client.
Sources: src/services/connection-manager.ts, src/index.ts:742-744
Configuration and Overrides
While detection is automated, it can be steered via environment variables or explicit tool calls.
- Manual Start: The
lsp_start_servertool allows users to explicitly define aserver_idandworkspace_root, bypassing the automated discovery for specific debugging or complex project structures. - Root Override: The
LSP_WORKSPACE_ROOTenvironment variable can be used to force a specific directory as the root for all detection logic. - Configured Servers: The
Configobject defines which servers handle whichlanguageIdsandextensions.
Sources: src/index.ts:515-525, CLAUDE.md:106-107, src/types.ts:121-125
LSPServerConfig Structure
The configuration defines the relationship between the detector's output and the actual server process to spawn.
Sources: src/types.ts:121-149
export interface LSPServerConfig {
id: string; // e.g., "typescript"
extensions: string[]; // ["ts", "tsx"]
languageIds: string[]; // ["typescript", "typescriptreact"]
command: string; // Binary to execute
args: string[]; // CLI arguments
rootPatterns?: string[]; // Custom markers for this server
}
Summary
The Supported Languages & Detection system enables a zero-config experience for the user. By mapping file extensions to languageId strings and scanning for project root markers, the server can dynamically manage multiple LSP instances. This architecture supports polyglot environments by keying server instances to specific workspace roots, allowing for seamless transitions between different languages and sub-projects within a monorepo.
Sources: CLAUDE.md:38-42, src/services/document-manager.ts:38-84