Claude Code Configuration
Relevant source files
The following files were used as context for generating this wiki page:
Claude Code Configuration refers to the orchestration of environment variables, JSON configuration files, and workspace-level discovery settings that allow the lsp-mcp-server to bridge Claude Code to various Language Server Protocol (LSP) implementations. This configuration ensures that the Model Context Protocol (MCP) server can correctly identify workspace boundaries, manage server lifecycles, and enforce security constraints.
The system relies on a combination of automatic detection (e.g., finding root markers like package.json) and explicit user overrides via environment variables. This setup enables semantic code intelligence capabilities such as go-to-definition, workspace symbol search, and diagnostics across multiple programming languages within a single or multi-root workspace environment.
Sources: CLAUDE.md:5-10, CLAUDE.md:144-150
Server Environment and Initialization
The server's behavior is primarily influenced by environment variables that define where configuration files are located and how the workspace is structured.
Environment Variables
| Variable | Description | Source |
|---|---|---|
LSP_CONFIG_PATH | Path to the JSON file containing language server configurations. | CLAUDE.md:144-145 |
LSP_WORKSPACE_ROOT | Manual override for the project root directory. | CLAUDE.md:149-150 |
Workspace Discovery Logic
When LSP_WORKSPACE_ROOT is not provided, the server attempts to auto-detect the root by traversing upward from the current file path. It looks for specific "root markers" indicative of project boundaries:
- JavaScript/TypeScript:
package.json,tsconfig.json - Rust:
Cargo.toml - Go:
go.mod - Python:
pyproject.toml - Version Control:
.git
Sources: CLAUDE.md:147-150
Core Configuration Components
The configuration facilitates the lifecycle management of language servers through the ConnectionManager and DocumentManager.
Server Instance Keying
Servers are uniquely identified using a "Server Key" generated from the pair (serverId, workspaceRoot). This design choice is critical for supporting monorepos, allowing each sub-workspace to maintain its own independent language server instance.
Sources: CLAUDE.md:38-40
Security and Resource Limits
Configuration enforces several hard limits to ensure system stability and security:
- Path Validation: All paths must be absolute and are validated using
src/schemas/tool-schemas.ts. - Workspace Boundary: File modifications (rename, format) are restricted to the detected workspace root to prevent unauthorized writes.
- File Size: A limit of
MAX_FILE_SIZE_BYTES(10 MB) is enforced to prevent memory exhaustion. - Execution: Language servers are spawned with
shell: falseto mitigate command injection risks.
Sources: CLAUDE.md:133-142
Data Flow and Tool Interaction
The configuration dictates how MCP tool calls are processed and routed to the underlying LSP servers.
Request Processing Flow
The following diagram illustrates the flow from an incoming MCP request to the LSP response, guided by the configuration and tool context.
The prepareFile utility is the central junction for this flow, validating paths and ensuring the target document is synchronized with the appropriate LSP client.
Sources: CLAUDE.md:56-65, src/tools/utils.ts:37-56
Language Mapping and Synchronization
The DocumentManager uses a configuration map to translate file extensions into LSP-recognized language identifiers. This is essential for the textDocument/didOpen notification.
Language ID Mapping (Partial)
| Extension | Language ID |
|---|---|
.ts, .tsx | typescript, typescriptreact |
.py, .pyi | python |
.rs | rust |
.go | go |
.c, .cpp | c, cpp |
.rb | ruby |
Sources: src/services/document-manager.ts:34-62
Diagnostic Configuration
Diagnostics in the lsp-mcp-server are push-based rather than pull-based. The server configures a DiagnosticsCache to store notifications sent by the LSP servers.
- Warm-up Requirement: Because diagnostics only reflect opened files, a "warm-up" step via
lsp_index_filesis often required before global workspace diagnostics become visible. - Notification Handling: The
ConnectionManagerwires thepublishDiagnosticsnotifications from each LSP client directly into the global cache.
Sources: CLAUDE.md:42-45, src/index.ts:333-338, SKILL.md:99-110
Summary
Claude Code Configuration for the lsp-mcp-server provides a robust, security-conscious environment for semantic code analysis. By leveraging absolute path enforcement, workspace boundary validation, and a centralized ToolContext, the server ensures that Claude Code can interact with diverse language servers reliably. The system's ability to auto-detect workspace roots while allowing for manual overrides via environment variables makes it adaptable to both simple projects and complex monorepo structures.