LSP multiplexer that sits between a client and multiple language servers, fanning out requests and merging responses
README.md

lsp-mux #

Go Report Card MIT Go Reference builds.sr.ht status Built with Nix

LSP multiplexer that sits between a client and multiple language servers, fanning out requests and merging responses.

Features #

  • Transparent proxy for any LSP server over stdio
  • Fan-out requests to multiple servers concurrently
  • Merge strategies per method type:
    • Array concat with deduplication: definition, references, documentSymbol, codeAction, etc.
    • First-wins: hover, signatureHelp, rename, formatting
    • Completion merge: handles both CompletionList and CompletionItem[] formats
  • Code action tagging: actions prefixed with [serverName] and routed back to the originating server on resolve
  • Crash recovery: restarts dead servers (up to 3 attempts), replays initialize + open documents
  • Diagnostic deduplication: merges diagnostics from all servers per URI, deduplicates by range + message
  • Profile-based configuration via ~/.config/lsp-mux/config.yaml
  • Per-profile log file and log level (global defaults with per-profile overrides)
  • Configurable timeouts and circuit-breaker degradation (skip unresponsive servers, probe for recovery)
  • Server-initiated request routing with ID remapping
  • Structured logging with context-based attributes (client name, server name, mux PID, profile)

Usage #

# Inline server flags
lsp-mux --server gopls --server golangci-lint-langserver

# Named profile from config file
lsp-mux --profile ruby

# Profile from a custom config path
lsp-mux --profile ruby --config /path/to/config.yaml

# With debug logging to a file
lsp-mux --profile go --log /tmp/lsp-mux.log --debug

Pass either --server (repeatable) or --profile. They are mutually exclusive. Each --server value is a command string split by whitespace (supports arguments).

The --log flag writes logs to a file instead of stderr. The --debug flag sets the log level to DEBUG. Both can be set in the config file per-profile, and CLI flags override config values.

Configuration #

Create ~/.config/lsp-mux/config.yaml to define named profiles:

profiles:
  go:
    servers:
      - gopls
      - golangci-lint-langserver
  nix:
    servers:
      - nil
      - nixd
  ruby:
    servers:
      - bundle exec srb tc --lsp
      - ruby-lsp
      - solargraph stdio
  ruby-standardrb:
    servers:
      - bundle exec srb tc --lsp
      - ruby-lsp
      - solargraph stdio
      - standardrb --lsp

Each profile lists the server commands to multiplex. Server commands with arguments (e.g. solargraph stdio, bundle exec srb tc --lsp) are a single string, split by whitespace at runtime.

If a requested profile is missing, lsp-mux exits with an error listing the available profiles.

Logging #

Log file and level can be set globally or per-profile. Per-profile settings override global ones, and CLI flags (--log, --debug) override both.

logFile: /tmp/lsp-mux.log
logLevel: info

profiles:
  ruby:
    servers:
      - ruby-lsp
    logFile: /tmp/lsp-mux-ruby.log
    logLevel: debug
  go:
    servers:
      - gopls
      - golangci-lint-langserver

Valid log levels: debug, info, warn, error (case-insensitive).

Timeouts and degradation #

Request timeouts and a circuit-breaker mechanism are configurable at the global and per-profile level. When a server times out repeatedly, lsp-mux marks it as degraded and stops sending it requests until a recovery probe succeeds.

requestTimeout: 10s
degradationThreshold: 3

profiles:
  ruby:
    servers:
      - ruby-lsp
      - solargraph stdio
    initializeTimeout: 20s
    degradationThreshold: 2
    recoveryInterval: 60s
Setting What it controls Default
initializeTimeout Deadline for the initialize handshake 30s
requestTimeout Deadline for regular LSP requests 10s
degradationThreshold Consecutive timeouts before a server is skipped 3
recoveryInterval Cooldown before probing a degraded server 30s

Profile-level values override global ones. Notifications (e.g. didOpen, didClose) are always broadcast to every server, including degraded ones, so document state stays consistent. If every server is degraded, lsp-mux falls back to sending to all of them rather than returning an error.

Duration values use Go's time.ParseDuration format: 10s, 500ms, 1m30s, etc.

Writing your own profiles #

Add an entry under profiles: with a list of servers:. Any profile name works, and you can combine any servers.

For example, a Python profile:

profiles:
  python:
    servers:
      - pyright-langserver --stdio
      - ruff server

Then run: lsp-mux --profile python.

Project-level configuration #

Place a .lsp-mux/config.yaml in a project's root directory to override settings from the user config. lsp-mux looks for this file in the current working directory.

# .lsp-mux/config.yaml
profiles:
  go:
    servers:
      - gopls
    requestTimeout: 5s

Merge semantics:

  • Profiles in the project config replace same-named profiles in the user config wholesale. Server lists are overridden, not concatenated.
  • Profiles that exist only in the user config are preserved.
  • Profiles that exist only in the project config are added.
  • Top-level scalars (logFile, logLevel, timeouts, degradationThreshold) from the project config override user config values. Zero-value fields in the project config do not clobber user config values.

To disable project config discovery, pass --no-project-config.

Security note: project config files can specify arbitrary server commands. A malicious .lsp-mux/config.yaml in a cloned repository could execute arbitrary code on your machine. This is the same trust model as .envrc or .vscode/settings.json.

Editor configuration #

Claude Code #

The repo ships generic entrypoint plugins for common languages. Each plugin maps file extensions to a named profile. You choose which LSP servers to run by editing ~/.config/lsp-mux/config.yaml.

1. Add the marketplace and install plugins for your languages:

/plugin marketplace add git@git.sr.ht:~jcmuller/lsp-mux
/plugin install lsp-mux-<language>@lsp-mux

Available plugins:

Plugin Profile Extensions
lsp-mux-c c .c, .h
lsp-mux-cpp cpp .cc, .cpp, .cxx, .h, .hpp, .hxx
lsp-mux-css css .css, .less, .scss
lsp-mux-elixir elixir .ex, .exs, .heex
lsp-mux-go go .go
lsp-mux-go-nix go .go (installs lsp-mux via nix)
lsp-mux-html html .htm, .html
lsp-mux-java java .java
lsp-mux-json json .json, .jsonc
lsp-mux-kotlin kotlin .kt, .kts
lsp-mux-lua lua .lua
lsp-mux-nix nix .nix
lsp-mux-nix-nix nix .nix
lsp-mux-python python .py, .pyi
lsp-mux-ruby ruby .rb, .rbi, .rake, .gemspec
lsp-mux-ruby-standardrb ruby-standardrb .rb, .rbi, .rake, .gemspec
lsp-mux-rust rust .rs
lsp-mux-swift swift .swift
lsp-mux-terraform terraform .tf, .tfvars
lsp-mux-typescript typescript .ts, .tsx, .js, .jsx
lsp-mux-yaml yaml .yaml, .yml
lsp-mux-zig zig .zig

2. Create ~/.config/lsp-mux/config.yaml with a matching profile. See the Configuration section for examples.

Custom plugins #

If the marketplace plugins don't fit your setup, create your own plugin with a .lsp.json file. See the Claude Code plugin docs for the full reference.

Example .lsp.json for a custom Go plugin:

{
  "go-mux": {
    "command": "lsp-mux",
    "args": ["--profile", "go"],
    "extensionToLanguage": {
      ".go": "go"
    }
  }
}

You can also use inline --server flags instead of a profile:

{
  "ruby-mux": {
    "command": "lsp-mux",
    "args": [
      "--server",
      "ruby-lsp",
      "--server",
      "solargraph stdio",
      "--server",
      "bundle exec srb tc --lsp"
    ],
    "extensionToLanguage": {
      ".rb": "ruby",
      ".rbi": "ruby"
    }
  }
}

Helix #

In ~/.config/helix/languages.toml:

[language-server.go-mux]
command = "lsp-mux"
args = ["--profile", "go"]

[[language]]
name = "go"
language-servers = ["go-mux"]

[language-server.ruby-mux]
command = "lsp-mux"
args = ["--profile", "ruby-standardrb"]

[[language]]
name = "ruby"
language-servers = ["ruby-mux"]

Neovim #

Using the built-in LSP client:

vim.lsp.config('go-mux', {
  cmd = { 'lsp-mux', '--profile', 'go' },
  filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
  root_markers = { 'go.mod', 'go.work', '.git' },
})
vim.lsp.enable('go-mux')

vim.lsp.config('ruby-mux', {
  cmd = { 'lsp-mux', '--profile', 'ruby-standardrb' },
  filetypes = { 'ruby' },
  root_markers = { 'Gemfile', '.git' },
})
vim.lsp.enable('ruby-mux')

Installation #

Run directly with nix #

nix run sourcehut:~jcmuller/lsp-mux -- --profile go

Add to a flake #

{
  inputs.lsp-mux.url = "sourcehut:~jcmuller/lsp-mux";
}

The flake exposes three outputs:

  • packages.<system>.default: the lsp-mux binary.
  • overlays.default: adds pkgs.lsp-mux to nixpkgs.
  • homeManagerModules.default: a home-manager module.

Overlay #

Apply the overlay so pkgs.lsp-mux is available everywhere:

nixpkgs.overlays = [inputs.lsp-mux.overlays.default];

Home-manager module #

The module manages ~/.config/lsp-mux/config.yaml declaratively. It installs the package and generates the config from your profile definitions.

{
  imports = [inputs.lsp-mux.homeManagerModules.default];

  programs.lsp-mux = {
    enable = true;

    # Global settings (inherited by all profiles unless overridden).
    logFile = "/tmp/lsp-mux.log";
    logLevel = "info";
    requestTimeout = "10s";
    degradationThreshold = 3;

    profiles = {
      go = {
        enable = true;
        # uses catalog defaults: gopls, golangci-lint-langserver
      };
      nix = {
        enable = true;
        # uses catalog defaults: nil, nixd
      };
      ruby = {
        enable = true;
        servers = ["ruby-lsp" "solargraph stdio"];
        logFile = "/tmp/lsp-mux-ruby.log";
        logLevel = "debug";
        degradationThreshold = 2;  # solargraph can be slow
        recoveryInterval = "60s";
      };
    };
  };
}

Each profile must set enable = true to be included in the generated config. When servers is empty, the module pulls defaults from the built-in catalog. If the profile name doesn't match any catalog entry and no servers are given, evaluation fails with a list of known profiles.

Run lsp-mux catalog to see all built-in profiles and their defaults.

Build from source #

go build -o lsp-mux .

Or with nix:

nix build

Development #

nix develop
go test ./...

License #

MIT