lsp-mcp
The LSP MCP Server is a Model Context Protocol server designed for interacting with the Language Server Protocol interface. This server acts as a bridge, enabling large language models (LLMs) to query LSP hover and completion providers. By doing so, LLMs can obtain more accurate code suggestions, enhancing their utility in code development and analysis.
GitHub Stars
70
User Rating
Not Rated
Favorites
0
Views
31
Forks
10
Issues
3
Installation
Difficulty
IntermediateEstimated Time
10-20 minutes
Requirements
Node.js (v16 or later)npmInstallation
Installation
Prerequisites
Please specify required software and versions:Node.js: 16.0.0 or higher
npm: Latest version
Installation Steps
1. Clone Repository
bash
git clone https://github.com/Tritlo/lsp-mcp.git
cd lsp-mcp
2. Install Dependencies
bash
npm install
3. Build MCP Server
bash
npm run build
Troubleshooting
Common Issues
Issue: Server won't start Solution: Check Node.js version and reinstall dependencies. Issue: Tests fail Solution: Verify the test environment and ensure all necessary dependencies are correctly installed.Configuration
Configuration
Basic Configuration
MCP Server Setup
Add the following configuration tomcp_config.json:
json
{
"mcpServers": {
"lsp-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"tritlo/lsp-mcp",
"",
"",
""
]
}
}
}
Advanced Configuration
Environment Variables
Set the following environment variables as needed:bash
export LSP_PATH="/path/to/lsp"
export LOG_LEVEL="info"
Configuration Example
Basic Configuration Example
json
{
"mcpServers": {
"lsp-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"tritlo/lsp-mcp",
"typescript",
"/path/to/typescript-lsp",
"--arg1 value1"
]
}
}
}
Examples
Examples
Basic Usage
Here are basic usage examples for the MCP server:Programmatic Usage
javascript
// JavaScript example (Node.js)
const { MCPClient } = require('@modelcontextprotocol/client');
const client = new MCPClient();
await client.connect();
// Execute tool
const result = await client.callTool('get_completions', {
parameter1: 'value1'
});
console.log(result);
Advanced Examples
Automation Script
bash
#!/bin/bash
Batch processing example
for file in *.js; do
mcp-tool analyze "$file"
done
API Integration
python
Python example
import requests
def call_mcp_tool(tool_name, params):
response = requests.post(
'http://localhost:3000/mcp/call',
json={
'tool': tool_name,
'parameters': params
}
)
return response.json()
Usage example
result = call_mcp_tool('get_info_on_location', {
'file': 'example.js',
'position': {'line': 10, 'character': 5}
})
Use Cases
Retrieve hover information for a specific line of code, displaying descriptions of functions or variables.
Enhance code editor autocomplete features, providing real-time suggestions as users type.
Obtain code actions for specific ranges during code refactoring.
Collect diagnostic information for a project, displaying errors and warnings to help developers resolve issues quickly.