Skip to main content
Glama

LSP MCP Server

An LSP (Language Server Protocol) MCP (Model Context Protocol) server that provides refactoring tools through LSP integration. This server exposes refactoring capabilities as MCP tools that can be used by MCP clients like Claude Code.

Installation

From npm (when published)

npm install -g lsp-mcp-server

Local Development Setup

  1. Clone the repository:

    git clone <repository-url>
    cd lsp-mcp-server
  2. Install dependencies:

    pnpm install
  3. Build the project:

    pnpm run build
  4. Link for global use:

    npm link

    After linking, you can use the mcp-lsp command globally.

  5. Alternative: Use without linking:

    # Run directly
    pnpm start
    
    # Or build and run
    pnpm run dev

Related MCP server: ts-mcp

Prerequisites

The server requires these language servers to be installed for full functionality:

TypeScript/JavaScript

npm install -g typescript-language-server typescript

Python

# Default LSP server for type checking and refactoring
npm install -g pyright

# Optional: For linting (when using serverType: 'lint')
pip install ruff

Usage

With Claude Code

If you have the server installed globally:

/mcp add lsp-mcp

Using the Tools in Claude Code

Once connected, you can ask Claude Code to use the refactoring tools:

  • "Rename the calculateTotal function to computeSum in src/utils.ts on line 45"

  • "Find all references to the UserService class in src/services/user.ts line 12"

  • "Extract lines 20-35 from src/components/Header.tsx into a new function called renderNavigation"

  • "Move the validateEmail function from src/utils/validation.ts line 8 to src/utils/email.ts"

  • "Rename the file src/old-name.ts to src/new-name.ts"

Claude Code will automatically use the appropriate LSP refactoring tools based on your requests.

Manual MCP Server Usage

The server can also be used directly by other MCP clients via stdio:

mcp-lsp

Available Tools

  1. rename_file - Rename files/folders using LSP rename capabilities

  2. move_function - Move functions between files using LSP refactoring

  3. extract_function - Extract code selections into new functions

  4. find_references - Find all references to symbols

  5. rename_symbol - Rename symbols across all files

Example Tool Usage

Each tool accepts parameters specific to the refactoring operation:

  • rename_symbol: Requires file, line, newName, and optionally character and language

  • find_references: Requires file, line, and optionally character and language

  • extract_function: Requires file, startLine, endLine, functionName, and optionally character positions and language

Supported Languages

  • TypeScript/JavaScript

  • Python

Development

Commands

  • pnpm install - Install dependencies

  • pnpm run build - Compile TypeScript to dist/

  • pnpm start - Run the compiled server

  • pnpm run dev - Build and run in one command

  • pnpm run type-check - Check types without building

  • pnpm run lint - Check code with ESLint

  • pnpm run lint:fix - Auto-fix linting issues

  • pnpm run format - Format code with Prettier

  • pnpm run clean - Remove dist/ directory

Architecture

The server consists of:

  • LSPRefactorServer: Main server class implementing MCP interface

  • LSP Client Management: Manages connections to language servers

  • Tool Implementations: Each refactoring operation communicates with LSP servers

Protocol Communication

  • MCP Protocol: Server ↔ MCP clients via stdio

  • LSP Protocol: Server ↔ Language servers via JSON-RPC over stdio

Available Tools

5 tools
extract_functionC

Extract selected code into a new function

Inputs: file (required), startLine (required), endLine (required), functionName (required), +3 more.

find_referencesC

Find all references to a symbol using LSP

Inputs: file (required), line (required), character, language.

move_functionB

Move a function to a different file using LSP refactoring

Inputs: sourceFile (required), targetFile (required), functionName (required), line (required), +2 more.

rename_fileC

Rename a file or folder using LSP rename capabilities

Inputs: oldPath (required), newPath (required), language.

rename_symbolB

Rename a symbol (variable, function, class, etc.) across all files

Inputs: file (required), line (required), newName (required), character, +1 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no overlap: extract_function creates new functions, find_references locates symbol usage, move_function relocates functions between files, rename_file handles file/folder renaming, and rename_symbol renames symbols across files. The descriptions make it impossible to confuse one tool for another.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern (e.g., extract_function, find_references, move_function, rename_file, rename_symbol). The naming is perfectly uniform with no deviations in style or convention.

    Tool Count5/5

    With 5 tools, this server is well-scoped for LSP-based code refactoring and navigation. Each tool earns its place by covering distinct refactoring operations without being too sparse or bloated.

    Completeness4/5

    The toolset covers key LSP refactoring operations (extract, move, rename) and symbol navigation (find references), but lacks tools for other common LSP features like code completion, diagnostics, or formatting. However, the provided tools form a coherent subset for core refactoring tasks.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables coding agents to perform safe, project-wide Python refactoring (rename, move, extract, inline, change signature, organize imports, etc.) with a dry-run safety contract and LSP-coordinate addressing.
      15
      MIT
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables AI assistants to navigate and edit TypeScript/JavaScript source by named declarations, reading symbols, imports, diagnostics, and replacing code via the TypeScript AST.
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI coding agents to perform structural code operations on TypeScript/TSX projects—finding symbols and references and renaming them semantically while preserving source.
      27 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to navigate and refactor a codebase through an AST index, offering project overviews, symbol and usage search, module dependency exploration, and LSP-backed operations such as rename, go-to-definition, diagnostics, and extract-method. Supports TypeScript/JavaScript and C# with automatic reindexing and watch mode.
      MIT