Skip to main content
Glama
famtong8-dev

W3 MCP LSP Server

by famtong8-dev

W3 MCP LSP Server

Python MCP server wrapping TypeScript Language Server for JavaScript/TypeScript code intelligence.

Status: ✅ Working with real LSP protocol (not mock)

Features

  • lsp_goto_definition - Jump to symbol definition location

  • lsp_hover - Get type information and documentation

  • lsp_find_references - Find all references/usages of symbol

Supports JavaScript and TypeScript files via TypeScript Language Server.

Related MCP server: Codex LSP Bridge

Quick Start

1. Clean Setup (Important!)

cd /path/to/w3-mcp-server-lsp

# Remove old lockfile and venv
rm -rf uv.lock .venv venv

# Unset old environment variable
unset VIRTUAL_ENV

2. Install Dependencies

# Install TypeScript Language Server
npm install -g typescript typescript-language-server

# Install Python dependencies (using uv)
uv sync

# Install MCP CLI dependencies
uv pip install 'mcp[cli]'

3. Verify Installation

# Check typescript-language-server
which typescript-language-server
typescript-language-server --version

# Check Python env
uv run python -c "from mcp.server.fastmcp import FastMCP; print('✓ MCP ready')"

4. Test with MCP Inspector

# Start MCP Inspector (interactive web UI)
uv run mcp dev server.py

Opens URL like:

http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=...

Features:

  • ✅ Available tools listed in sidebar

  • ✅ Test each tool interactively with JSON input

  • ✅ Real-time request/response viewing

  • ✅ Server logs and debugging

  • ✅ No extra dependencies needed

Usage

Option A: MCP Inspector (Development)

Best way to test and debug:

cd /path/to/w3-mcp-server-lsp

# Start inspector
uv run mcp dev server.py

Opens web UI at http://localhost:5173:

  • See available tools

  • Test each tool with JSON input

  • View request/response in real-time

  • See server logs

Option B: Direct Python

# Run server (stdio mode)
uv run python server.py

Option C: Claude Code Integration

Install from PyPI:

pip install w3-mcp-server-lsp
# or
uv pip install w3-mcp-server-lsp

Edit ~/.claude/claude_config.json or ~/.mcp.json:

{
  "mcpServers": {
    "w3-lsp": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "--with", "w3-mcp-server-lsp", "w3-mcp-server-lsp"],
      "env": {
        "PROJECT_ROOT": "/path/to/your/project"
      }
    }
  }
}

Advantages:

  • ✅ No need to clone the repo

  • ✅ Easy version management

  • ✅ Automatic dependency isolation

Method 2: From Local Source

Edit ~/.claude/claude_config.json:

{
  "mcpServers": {
    "w3-lsp": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "server.py"],
      "cwd": "/path/to/w3-mcp-server-lsp",
      "env": {
        "PROJECT_ROOT": "/path/to/your/project"
      }
    }
  }
}

Then restart Claude Code.

Tools Documentation

⚠️ IMPORTANT: 0-Indexed Line and Character Numbers

All tools use 0-indexed positioning (start from 0, not 1):

Editor Display

Tool Input

Formula

Ln 5, Col 10

line: 4

lsp_value = editor_value - 1

Ln 1, Col 1

line: 0

character: 0

Ln 10, Col 5

line: 9

character: 4

Quick Reference:

  • Line 1 in editor = line: 0 in tool

  • Column 1 in editor = character: 0 in tool

How to Calculate Character Position:

Given this code line:

const greeting = "Hello";
0123456789...
  • Position at c in constcharacter: 0

  • Position at o in constcharacter: 1

  • Position at g in greetingcharacter: 6

  • Position at H in "Hello"character: 18

In VSCode:

  • Click on a character

  • Look at status bar: Ln X, Col Y

  • Use: line: X-1, character: Y-1


lsp_goto_definition

Jump to definition of symbol at specified position.

Input:

{
  "file_path": "fixtures/sample.js",
  "line": 4,
  "character": 9
}

Output:

/path/to/fixtures/sample.js:5:9

lsp_hover

Get type information and documentation for symbol.

Input:

{
  "file_path": "fixtures/sample.js",
  "line": 5,
  "character": 10
}

Output:

(parameter) a: any

lsp_find_references

Find all references/usages of symbol.

Input:

{
  "file_path": "fixtures/sample.js",
  "line": 4,
  "character": 9
}

Output:

Found 2 references:
/path/to/fixtures/sample.js:5:9
/path/to/fixtures/sample.js:14:22

Configuration

PROJECT_ROOT

Specifies the root directory of your project. Files paths in tool calls are relative to this.

Set via:

  1. Environment variable:

    export PROJECT_ROOT="/path/to/your/project"
    uv run python server.py
  2. Current directory (default):

    cd /path/to/your/project
    uv run python /path/to/w3-mcp-server-lsp/server.py
  3. In .claude/settings.json:

    "env": {
      "PROJECT_ROOT": "/path/to/your/project"
    }

Line and Character Numbers (0-indexed)

LSP uses 0-indexed positions:

  • VSCode shows: Ln 5, Col 10

  • LSP needs: line: 4, character: 9

Formula: lsp_value = vscode_value - 1

Project Structure

w3-mcp-server-lsp/
├── server.py           # MCP server entry point
├── lsp_client.py       # LSP protocol implementation
├── pyproject.toml      # Project config
├── fixtures/
│   └── sample.js       # Sample file for testing
├── test_mcp_server.py  # Integration test
├── test_lsp_debug.py   # Debug test with logging
└── README.md

How It Works

Architecture

MCP Client (Claude, IDE, etc.)
    ↓
MCP Server (server.py)
    ↓
LSP Client (lsp_client.py)
    ↓
TypeScript Language Server (subprocess)

LSP Protocol Flow

  1. Initialization

    • Send: initialize request

    • Receive: server capabilities

    • Send: initialized notification

  2. Document Opening

    • Send: textDocument/didOpen notification

    • Content provided inline

  3. Queries

    • Send: textDocument/definition, textDocument/hover, etc.

    • Receive: results from language server

  4. Details

    • Communication: JSON-RPC over stdin/stdout

    • Binary mode: Avoids text encoding issues

    • Notification handling: Skip server notifications, match message IDs

Testing

uv run mcp dev server.py

Web UI opens at http://localhost:5173:

  • Test tools visually

  • See real-time results

  • View server logs

Direct Server

uv run python server.py

Runs in stdio mode, ready to connect from Claude Code or other MCP clients.

Troubleshooting

TypeScript Language Server not found

# Install
npm install -g typescript typescript-language-server

# Verify
which typescript-language-server

MCP module not found

# Install dependencies
pip install -e .

# Or manually
pip install mcp pydantic

Server hangs on startup

  • Check if TypeScript Language Server is installed

  • Check terminal for error messages

  • Try: typescript-language-server --stdio directly

Tool returns None or error

  • Verify file path is relative to PROJECT_ROOT

  • Check line/character numbers are 0-indexed

  • Check server logs output in terminal

  • Use MCP Inspector (uv run mcp dev server.py) to see requests/responses

Future Enhancements

  • Go support (gopls language server)

  • Python support (pylsp/pyright)

  • Multiple language servers in single MCP server

  • Caching of responses

  • Batch operations

Development

Testing with MCP Inspector

uv run mcp dev server.py

Web UI at http://localhost:5173 shows:

  • Available tools and schemas

  • Real-time request/response

  • Server logs

  • Interactive testing

Running Directly

uv run python server.py

For debugging, check logs output in terminal.

References

License

MIT

Available Tools

3 tools
lsp_find_referencesA
Read-onlyIdempotent

Find all usages/references of symbol at position.

🔴 CRITICAL: Line and character are STRICTLY 0-INDEXED (0, 1, 2...), NOT 1-indexed!

❌ WRONG (what editor displays):
  Editor shows: "Ln 5, Col 10"
  ❌ DON'T use: {"line": 5, "character": 10}

✅ CORRECT (0-indexed):
  ✅ DO use: {"line": 4, "character": 9}
  Formula: lsp_value = editor_value - 1

CHARACTER COUNTING (0-indexed from start of line):
  Line: "const greeting = "Hello";"
  Index: 0123456789...
  • 'c' in const → character: 0
  • 'o' in const → character: 1
  • 'g' in greeting → character: 6
  • 'H' in string → character: 18

Args:
    params (LSPInput): Must provide line and character as 0-indexed values

Returns:
    str: "Found N references:

file:line:column ..." or "No references found"

Example:
    ✅ {"file_path": "src/app.ts", "line": 4, "character": 9}
    → "Found 2 references:

/path/src/app.ts:5:9 /path/src/utils.ts:10:2"

ParametersJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description goes well beyond annotations by emphasizing the strict 0-indexing requirement, providing a conversion formula, and detailing the exact return format with examples. This is critical behavioral information not covered by the readOnlyHint or idempotentHint annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (CRITICAL, WRONG, CORRECT, Example), but it is somewhat lengthy and repeats examples also found in the nested schema. It remains front-loaded with the primary purpose and key constraint.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is comprehensive for this tool: it covers input requirements, output format, and provides a worked example. Given the tool's complexity and the presence of an output schema, this description provides all necessary context for correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description explains each parameter (line, character, file_path) with concrete examples and the conversion formula from editor to LSP indexing. This adds significant meaning beyond the minimal top-level schema description, compensating for the 0% schema description coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with 'Find all usages/references of symbol at position,' which clearly states the tool's function with a specific verb and resource. This distinguishes it from sibling tools like lsp_goto_definition and lsp_hover by its focus on references.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage (finding references) but does not explicitly contrast this tool with alternatives like lsp_goto_definition or lsp_hover, nor does it state when not to use it. Thus, the usage is clear from context but lacks explicit guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

lsp_goto_definitionA
Read-onlyIdempotent

Jump to symbol definition location.

🔴 CRITICAL: Line and character are STRICTLY 0-INDEXED (0, 1, 2...), NOT 1-indexed!

❌ WRONG (what editor displays): Editor shows: "Ln 5, Col 10" ❌ DON'T use: {"line": 5, "character": 10}

✅ CORRECT (0-indexed): ✅ DO use: {"line": 4, "character": 9} Formula: lsp_value = editor_value - 1

CHARACTER COUNTING (0-indexed from start of line): Line: "const greeting = "Hello";" Index: 0123456789... • 'c' in const → character: 0 • 'o' in const → character: 1 • 'g' in greeting → character: 6 • 'H' in string → character: 18

Args: params (LSPInput): Must provide line and character as 0-indexed values

Returns: str: "file:line:column" or "Definition not found"

Example: ✅ {"file_path": "src/app.ts", "line": 4, "character": 9} → "/path/src/app.ts:15:5"

ParametersJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, destructiveHint=false, and idempotentHint=true, covering the safety profile. The description adds valuable behavioral context: the strict 0-indexing requirement, the return format ('file:line:column' or 'Definition not found'), and an example. This goes beyond what annotations convey.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-organized with headers, a critical warning, examples, and a return type. It is longer than minimal but justified by the tricky 0-indexing nuance. Some redundancy exists (e.g., repeated indexing formulas), but the structure and front-loaded purpose keep it effective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With annotations covering safety and an output schema presumably present, the description thoroughly covers purpose, parameters, return value, and a detailed example. It even explains edge-case conversion. It is complete for a tool of this complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite the schema having descriptive parameter entries, the context indicates 0% schema description coverage. The description fully compensates by explicitly stating the 0-indexing requirement, providing conversion formulas, and offering a concrete example with file_path. It clearly explains how to interpret and provide each parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description starts with a clear and specific verb+resource phrase: 'Jump to symbol definition location.' This precisely distinguishes it from sibling tools like lsp_hover (show info) and lsp_find_references (find usages). The purpose is unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description clearly implies the use case (navigate to a symbol's definition) but does not explicitly state when to prefer this over alternatives or mention exclusions. Sibling tools exist but are not referenced, so the guidance is implied rather than explicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

lsp_hoverA
Read-onlyIdempotent

Get type information and documentation for symbol at position.

🔴 CRITICAL: Line and character are STRICTLY 0-INDEXED (0, 1, 2...), NOT 1-indexed!

❌ WRONG (what editor displays): Editor shows: "Ln 5, Col 10" ❌ DON'T use: {"line": 5, "character": 10}

✅ CORRECT (0-indexed): ✅ DO use: {"line": 4, "character": 9} Formula: lsp_value = editor_value - 1

CHARACTER COUNTING (0-indexed from start of line): Line: "const greeting = "Hello";" Index: 0123456789... • 'c' in const → character: 0 • 'o' in const → character: 1 • 'g' in greeting → character: 6 • 'H' in string → character: 18

Args: params (LSPInput): Must provide line and character as 0-indexed values

Returns: str: Type signature like "(parameter) name: string" or "No info available"

Example: ✅ {"file_path": "src/app.ts", "line": 4, "character": 9} → "(parameter) greeting: string"

ParametersJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds substantial behavioral context beyond the annotations: it emphasizes the critical 0-indexing requirement, shows the exact return format ('(parameter) name: string' or 'No info available'), and explains the formula for converting editor values. The annotations already state readOnly, idempotent, and non-destructive, so the description enriches rather than repeats them. No contradictions found.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a critical warning at the top, clear do/don't examples, and a character indexing diagram. It is somewhat repetitive—the 0-indexing rule is repeated across the warning, character counting section, and schema—but the repetition reinforces a crucial point. It earns a 4 because while not maximally concise, it prioritizes the most important information and remains scannable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is highly complete: it covers the tool's purpose, input parameters with exhaustive indexing guidance, return value format, and a concrete usage example. The output schema is provided, so return value details do not need to be over-explained. Given the potential for off-by-one errors, this description fully equips an agent to invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description goes far beyond the schema by providing detailed 0-indexing examples, a character-counting illustration, and the conversion formula (lsp_value = editor_value - 1). This adds substantial meaning to the 'line' and 'character' parameters beyond what the schema's descriptions offer. It also clarifies the file_path parameter as relative to the project root. The abundant examples make the parameter usage crystal clear.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb+resource: 'Get type information and documentation for symbol at position.' This clearly distinguishes it from sibling tools like lsp_goto_definition (jump to definition) and lsp_find_references (find references). The purpose is unambiguous and immediately understandable.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for use by explaining how to convert editor 1-based positions to 0-based values and includes a concrete example. It does not explicitly state when not to use it or contrast with alternatives, but the purpose and critical indexing instructions implicitly guide usage. No exclusion criteria are mentioned, so it scores a 4 rather than a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

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

  1. 3 tool updatesv0.1.5
    • First observedlsp_find_references
    • First observedlsp_goto_definition
    • First observedlsp_hover

TDQS

A4.4/5.0

Scored across 3 tools

Disambiguation5/5

Each tool targets a distinct LSP operation: definition lookup, hover information, and reference search. There is no overlap in their purposes, making selection unambiguous.

Naming Consistency4/5

All tools share the 'lsp_' prefix and follow an action-oriented naming pattern. However, 'lsp_hover' lacks the object component found in 'lsp_goto_definition' and 'lsp_find_references', creating a minor structural inconsistency.

Tool Count5/5

The three tools represent a focused, minimal set of LSP navigation features. Each earns its place without unnecessary bloat, and the count falls within the well-scoped range.

Completeness3/5

The core navigation operations (definition, hover, references) are covered, providing a usable foundation. However, other common LSP features such as document symbols, implementation, or code completion are missing, which could require workarounds for certain tasks.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Exposes Language Server Protocol (LSP) features as MCP tools, enabling IDE-grade semantic navigation including go-to-definition, find references, hover info, and symbols across multiple programming languages (Python, Rust, C/C++, TypeScript/JavaScript, React, HTML, CSS).
    3
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    A lightweight MCP server that provides 40 tools for TypeScript/JavaScript refactoring and code intelligence, directly mapping to TypeScript's tsserver protocol commands for accurate structural changes and workspace analysis.
    40
    20 npm
    3
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Self-contained MCP server providing type-aware code intelligence for TypeScript, JavaScript, and Vue files, exposing tools like hover, definition, references, and diagnostics to Claude Code without requiring global language server installations.
    MIT