Logo LSP MCP Server

LSP MCP Server

Cộng đồng
Tritlo

An MCP server that lets you interact with LSP servers

Nhà phát hànhTritlo
Kho mãlsp-mcp
Ngôn ngữTypeScript
Bản fork
18
Sao
124
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    LSP MCP Server cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    124 sao và 18 bản fork từ kho mã được liên kết.

LSP MCP Server

An MCP (Model Context Protocol) server for interacting with LSP (Language Server Protocol) interface. This server acts as a bridge that allows LLMs to query LSP Hover and Completion providers.

Overview

The MCP Server works by:

  1. Starting an LSP client that connects to a LSP server
  2. Exposing MCP tools that send requests to the LSP server
  3. Returning the results in a format that LLMs can understand and use

This enables LLMs to utilize LSPs for more accurate code suggestions.

Configuration:

json
{
  "mcpServers": {
    "lsp-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "tritlo/lsp-mcp",
        "<language-id>",
        "<path-to-lsp>",
        "<lsp-args>"
      ]
    }
  }
}

Features

MCP Tools

  • get_info_on_location: Get hover information at a specific location in a file
  • get_completions: Get completion suggestions at a specific location in a file
  • get_code_actions: Get code actions for a specific range in a file
  • open_document: Open a file in the LSP server for analysis
  • close_document: Close a file in the LSP server
  • get_diagnostics: Get diagnostic messages (errors, warnings) for open files
  • start_lsp: Start the LSP server with a specified root directory
  • restart_lsp_server: Restart the LSP server without restarting the MCP server
  • set_log_level: Change the server's logging verbosity level at runtime

MCP Resources

  • lsp-diagnostics:// resources for accessing diagnostic messages with real-time updates via subscriptions
  • lsp-hover:// resources for retrieving hover information at specific file locations
  • lsp-completions:// resources for getting code completion suggestions at specific positions

Additional Features

  • Comprehensive logging system with multiple severity levels
  • Colorized console output for better readability
  • Runtime-configurable log level
  • Detailed error handling and reporting
  • Simple command-line interface

Prerequisites

  • Node.js (v16 or later)
  • npm

For the demo server:

  • GHC (8.10 or later)
  • Cabal (3.0 or later)

Installation

Building the MCP Server

  1. Clone this repository:

    git clone https://github.com/your-username/lsp-mcp.git
    cd lsp-mcp
  2. Install dependencies:

    npm install
  3. Build the MCP server:

    npm run build

Testing

The project includes integration tests for the TypeScript LSP support. These tests verify that the LSP-MCP server correctly handles LSP operations like hover information, completions, diagnostics, and code actions.

Running Tests

To run the TypeScript LSP tests:

npm test

or specifically:

npm run test:typescript

Test Coverage

The tests verify the following functionality:

  • Initializing the TypeScript LSP with a mock project
  • Opening TypeScript files for analysis
  • Getting hover information for functions and types
  • Getting code completion suggestions
  • Getting diagnostic error messages
  • Getting code actions for errors

The test project is located in test/ts-project/ and contains TypeScript files with intentional errors to test diagnostic feedback.

Usage

Run the MCP server by providing the path to the LSP executable and any arguments to pass to the LSP server:

npx tritlo/lsp-mcp <language> /path/to/lsp [lsp-args...]

For example:

npx tritlo/lsp-mcp haskell /usr/bin/haskell-language-server-wrapper lsp

Important: Starting the LSP Server

With version 0.2.0 and later, you must explicitly start the LSP server by calling the start_lsp tool before using any LSP functionality. This ensures proper initialization with the correct root directory, which is especially important when using tools like npx:

json
{
  "tool": "start_lsp",
  "arguments": {
    "root_dir": "/path/to/your/project"
  }
}

Logging

The server includes a comprehensive logging system with 8 severity levels:

  • debug: Detailed information for debugging purposes
  • info: General informational messages about system operation
  • notice: Significant operational events
  • warning: Potential issues that might need attention
  • error: Error conditions that affect operation but don't halt the system
  • critical: Critical conditions requiring immediate attention
  • alert: System is in an unstable state
  • emergency: System is unusable

By default, logs are sent to:

  1. Console output with color-coding for better readability
  2. MCP notifications to the client (via the notifications/message method)

Viewing Debug Logs

For detailed debugging, you can:

  1. Use the claude --mcp-debug flag when running Claude to see all MCP traffic between Claude and the server:

    claude --mcp-debug
  2. Change the log level at runtime using the set_log_level tool:

    json
    {
      "tool": "set_log_level",
      "arguments": {
        "level": "debug"
      }
    }

The default log level is info, which shows moderate operational detail while filtering out verbose debug messages.

API

The server provides the following MCP tools:

get_info_on_location

Gets hover information at a specific location in a file.

Parameters:

  • file_path: Path to the file
  • language_id: The programming language the file is written in (e.g., "haskell")
  • line: Line number
  • column: Column position

Example:

json
{
  "tool": "get_info_on_location",
  "arguments": {
    "file_path": "/path/to/your/file",
    "language_id": "haskell",
    "line": 3,
    "column": 5
  }
}

get_completions

Gets completion suggestions at a specific location in a file.

Parameters:

  • file_path: Path to the file
  • language_id: The programming language the file is written in (e.g., "haskell")
  • line: Line number
  • column: Column position

Example:

json
{
  "tool": "get_completions",
  "arguments": {
    "file_path": "/path/to/your/file",
    "language_id": "haskell",
    "line": 3,
    "column": 10
  }
}

get_code_actions

Gets code actions for a specific range in a file.

Parameters:

  • file_path: Path to the file
  • language_id: The programming language the file is written in (e.g., "haskell")
  • start_line: Start line number
  • start_column: Start column position
  • end_line: End line number
  • end_column: End column position

Example:

json
{
  "tool": "get_code_actions",
  "arguments": {
    "file_path": "/path/to/your/file",
    "language_id": "haskell",
    "start_line": 3,
    "start_column": 5,
    "end_line": 3,
    "end_column": 10
  }
}

start_lsp

Starts the LSP server with a specified root directory. This must be called before using any other LSP-related tools.

Parameters:

  • root_dir: The root directory for the LSP server (absolute path recommended)

Example:

json
{
  "tool": "start_lsp",
  "arguments": {
    "root_dir": "/path/to/your/project"
  }
}

restart_lsp_server

Restarts the LSP server process without restarting the MCP server. This is useful for recovering from LSP server issues or for applying changes to the LSP server configuration.

Parameters:

  • root_dir: (Optional) The root directory for the LSP server. If provided, the server will be initialized with this directory after restart.

Example without root_dir (uses previously set root directory):

json
{
  "tool": "restart_lsp_server",
  "arguments": {}
}

Example with root_dir:

json
{
  "tool": "restart_lsp_server",
  "arguments": {
    "root_dir": "/path/to/your/project"
  }
}

open_document

Opens a file in the LSP server for analysis. This must be called before accessing diagnostics or performing other operations on the file.

Parameters:

  • file_path: Path to the file to open
  • language_id: The programming language the file is written in (e.g., "haskell")

Example:

json
{
  "tool": "open_document",
  "arguments": {
    "file_path": "/path/to/your/file",
    "language_id": "haskell"
  }
}

close_document

Closes a file in the LSP server when you're done working with it. This helps manage resources and cleanup.

Parameters:

  • file_path: Path to the file to close

Example:

json
{
  "tool": "close_document",
  "arguments": {
    "file_path": "/path/to/your/file"
  }
}

get_diagnostics

Gets diagnostic messages (errors, warnings) for one or all open files.

Parameters:

  • file_path: (Optional) Path to the file to get diagnostics for. If not provided, returns diagnostics for all open files.

Example for a specific file:

json
{
  "tool": "get_diagnostics",
  "arguments": {
    "file_path": "/path/to/your/file"
  }
}

Example for all open files:

json
{
  "tool": "get_diagnostics",
  "arguments": {}
}

set_log_level

Sets the server's logging level to control verbosity of log messages.

Parameters:

  • level: The logging level to set. One of: debug, info, notice, warning, error, critical, alert, emergency.

Example:

json
{
  "tool": "set_log_level",
  "arguments": {
    "level": "debug"
  }
}

MCP Resources

In addition to tools, the server provides resources for accessing LSP features including diagnostics, hover information, and code completions:

Diagnostic Resources

The server exposes diagnostic information via the lsp-diagnostics:// resource scheme. These resources can be subscribed to for real-time updates when diagnostics change.

Resource URIs:

  • lsp-diagnostics:// - Diagnostics for all open files
  • lsp-diagnostics:///path/to/file - Diagnostics for a specific file

Important: Files must be opened using the open_document tool before diagnostics can be accessed.

Hover Information Resources

The server exposes hover information via the lsp-hover:// resource scheme. This allows you to get information about code elements at specific positions in files.

Resource URI format:

lsp-hover:///path/to/file?line={line}&column={column}&language_id={language_id}

Parameters:

  • line: Line number (1-based)
  • column: Column position (1-based)
  • language_id: The programming language (e.g., "haskell")

Example:

lsp-hover:///home/user/project/src/Main.hs?line=42&column=10&language_id=haskell

Code Completion Resources

The server exposes code completion suggestions via the lsp-completions:// resource scheme. This allows you to get completion candidates at specific positions in files.

Resource URI format:

lsp-completions:///path/to/file?line={line}&column={column}&language_id={language_id}

Parameters:

  • line: Line number (1-based)
  • column: Column position (1-based)
  • language_id: The programming language (e.g., "haskell")

Example:

lsp-completions:///home/user/project/src/Main.hs?line=42&column=10&language_id=haskell

Listing Available Resources

To discover available resources, use the MCP resources/list endpoint. The response will include all available resources for currently open files, including:

  • Diagnostics resources for all open files
  • Hover information templates for all open files
  • Code completion templates for all open files

Subscribing to Resource Updates

Diagnostic resources support subscriptions to receive real-time updates when diagnostics change (e.g., when files are modified and new errors or warnings appear). Subscribe to diagnostic resources using the MCP resources/subscribe endpoint.

Note: Hover and completion resources don't support subscriptions as they represent point-in-time queries.

Working with Resources vs. Tools

You can choose between two approaches for accessing LSP features:

  1. Tool-based approach: Use the get_diagnostics, get_info_on_location, and get_completions tools for a simple, direct way to fetch information.
  2. Resource-based approach: Use the lsp-diagnostics://, lsp-hover://, and lsp-completions:// resources for a more RESTful approach.

Both approaches provide the same data in the same format and enforce the same requirement that files must be opened first.

Troubleshooting

  • If the server fails to start, make sure the path to the LSP executable is correct
  • Check the log file (if configured) for detailed error messages

License

MIT License

Extensions

The LSP-MCP server supports language-specific extensions that enhance its capabilities for different programming languages. Extensions can provide:

  • Custom LSP-specific tools and functionality
  • Language-specific resource handlers and templates
  • Specialized prompts for language-related tasks
  • Custom subscription handlers for real-time data

Available Extensions

Currently, the following extensions are available:

  • Haskell: Provides specialized prompts for Haskell development, including typed-hole exploration guidance

Using Extensions

Extensions are loaded automatically when you specify a language ID when starting the server:

npx tritlo/lsp-mcp haskell /path/to/haskell-language-server-wrapper lsp

Extension Namespacing

All extension-provided features are namespaced with the language ID. For example, the Haskell extension's typed-hole prompt is available as haskell.typed-hole-use.

Creating New Extensions

To create a new extension:

  1. Create a new TypeScript file in src/extensions/ named after your language (e.g., typescript.ts)

  2. Implement the Extension interface with any of these optional functions:

    • getToolHandlers(): Provide custom tool implementations
    • getToolDefinitions(): Define custom tools in the MCP API
    • getResourceHandlers(): Implement custom resource handlers
    • getSubscriptionHandlers(): Implement custom subscription handlers
    • getUnsubscriptionHandlers(): Implement custom unsubscription handlers
    • getResourceTemplates(): Define custom resource templates
    • getPromptDefinitions(): Define custom prompts for language tasks
    • getPromptHandlers(): Implement custom prompt handlers
  3. Export your implementation functions

The extension system will automatically load your extension when the matching language ID is specified.

Acknowledgments

  • HLS team for the Language Server Protocol implementation
  • Anthropic for the Model Context Protocol specification

Cài đặt

TypingMind
{
  "mcpServers": {
    "lsp-mcp": {
      "command": "npx",
      "args": [
        "tritlo/lsp-mcp",
        "<language-id>",
        "<path-to-lsp>",
        "<lsp-args>"
      ]
    }
  }
}

Dùng MCP LSP MCP Server với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối LSP MCP Server, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm LSP MCP Server làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của LSP MCP Server.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "lsp-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "lsp-mcp-server"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của LSP MCP Server, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của LSP MCP Server.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng LSP MCP Server giúp tôi làm việc này không?
LSP MCP Server
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng LSP MCP Server.

Câu hỏi thường gặp

Máy chủ MCP LSP MCP Server dùng để làm gì?

LSP MCP Server là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP LSP MCP Server với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng LSP MCP Server với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP LSP MCP Server với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối LSP MCP Server, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP LSP MCP Server với TypingMind?

LSP MCP Server hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP LSP MCP Server cung cấp những công cụ nào trong TypingMind?

LSP MCP Server cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP LSP MCP Server không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu LSP MCP Server yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇