From 12b2f735968315935131c6e6d52dfbaad6c7ebe8 Mon Sep 17 00:00:00 2001 From: EFLKumo <96906415+EFLKumo@users.noreply.github.com> Date: Sat, 19 Sep 2026 16:50:54 +0800 Subject: [PATCH] Add project README --- LICENSE | 21 +++++++++ README.md | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bc01671 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 EFLKumo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3245904 --- /dev/null +++ b/README.md @@ -0,0 +1,131 @@ +# lsp-mcp + +An [MCP](https://modelcontextprotocol.io/) server that exposes a single [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) server to agents as a headless editor. + +`lsp-mcp` starts the language server you provide, keeps its document state in sync with the workspace, and exposes the language server's capabilities through MCP tools and resources. It is written in TypeScript and Effect, and runs directly on Node.js without a build step. + +## Features + +- stdio and Streamable HTTP MCP transports +- Diagnostics exposed both as a tool and subscribable MCP resources +- Preview-by-default edits for rename and formatting, with explicit disk application +- Language-server crash supervision, restart backoff, and document reopening +- Initialization options, workspace settings, language-id mappings, and open-document capacity configuration + +Underlying techniques: + +- On-demand document opening, disk change detection, and an LRU cache of open documents +- 1-based line and column positions designed for agent-facing use +- Capability-aware tool registration: unsupported LSP features are not advertised + +## Requirements + +- Node.js 26+ +- pnpm 12.4.2+ +- An installed language server executable + +## Installation + +```sh +pnpm install +``` + +The repository runs TypeScript directly. From a checkout, invoke the server with `node src/main.ts`. + +## Usage + +The general form is: + +```sh +node src/main.ts [lsp-mcp options] -- [language-server args...] +``` + +The `--` separates `lsp-mcp` options from the executable and arguments passed to the language server. + +### stdio + +stdio is the default transport and is suitable for MCP clients that launch a local server process: + +```sh +node src/main.ts --root /path/to/project -- typescript-language-server --stdio +``` + +For example, an MCP client configuration can point at the checkout like this: + +```json +{ + "mcpServers": { + "typescript": { + "command": "node", + "args": [ + "/path/to/lsp-mcp/src/main.ts", + "--root", + "/path/to/project", + "--", + "typescript-language-server", + "--stdio" + ] + } + } +} +``` + +### Streamable HTTP + +Run the MCP endpoint on a local port with `--http`: + +```sh +node src/main.ts --http 9010 --root ./crate -- rust-analyzer +``` + +The endpoint is available at: + +```text +http://localhost:9010/mcp +``` + +### Configuration examples + +```sh +# Pass JSON initialization options to the language server. +node src/main.ts \ + --init-options '{"typescript":{"useInferredProjectPerProjectRoot":true}}' \ + -- typescript-language-server --stdio + +# Serve workspace/configuration and didChangeConfiguration with JSON settings. +node src/main.ts \ + --settings '{"gopls":{"staticcheck":true}}' \ + -- gopls + +# Add a file-extension to language-id mapping. +node src/main.ts --language vue=vue --root ./web -- vue-language-server --stdio + +# Keep more documents open, and always restart a crashed language server. +node src/main.ts --open-documents 64 --restart always -- clangd +``` + +## Development + +```sh +pnpm test # Run the Vitest suite, including the fixture LSP integration tests +pnpm check # Type-check without emitting JavaScript +pnpm lint # Format and lint with Biome +``` + +The main source layout is: + +```text +src/Model.ts Agent-facing schemas and 1-based positions +src/Tools.ts MCP tool definitions and capability gating +src/Resources.ts MCP resources and notifications +src/Server.ts Effect layer composition and transports +src/main.ts CLI entry point +src/lsp/ LSP process, document, diagnostic, and editor bridge +test/ Unit and integration tests with a fixture language server +``` + +The `vscode-*` packages are intentionally confined to `src/lsp/`; the rest of the application uses the agent-facing schemas and Effect services. + +## License + +MIT