MCP Hub
Back to servers

JavaLens

Requires Setup

63 semantic Java analysis tools via Eclipse JDT: navigation, refactoring, code intelligence.

Registrynpm271/wk
Stars
12
Forks
5
Updated
Apr 8, 2026
Validated
Apr 10, 2026

Quick Install

npx -y javalens-mcp

JavaLens: AI-First Code Analysis for Java

GitHub release License: MIT Java 21

An MCP server providing 63 semantic analysis tools for Java, built directly on Eclipse JDT for compiler-accurate code understanding.

Built for AI Agents

JavaLens exists because AI systems need compiler-accurate insights that reading source files cannot provide. When an AI uses grep or Read to find usages of a method, it cannot distinguish:

  • A method call from a method with the same name in an unrelated class
  • A field read from a field write
  • An interface implementation from an unrelated class
  • A cast to a type from other references to that type

This leads to incorrect refactorings, missed usages, and incomplete understanding of code behavior.

Compiler-Accurate Analysis

JavaLens provides compiler-accurate code analysis through Eclipse JDT—the same engine that powers Eclipse IDE. Unlike text search, JDT understands:

  • Type resolution across inheritance hierarchies
  • Method overloading and overriding
  • Generic type arguments
  • Import resolution and classpath dependencies

Example: Finding all places where UserService.save() is called:

ApproachResult
grep "save("Returns 47 matches including orderService.save(), saveButton, comments
find_referencesReturns exactly 12 calls to UserService.save()

AI Training Bias Warning

⚠️ Important for AI developers and users

AI models may exhibit trained bias toward native tools (Grep, Read, LSP) over MCP server tools, even when semantic analysis provides better results. This happens because:

  1. Training data contains extensive grep/text-search patterns
  2. Native tools are "always available" in the model's experience
  3. The model may not recognize when semantic analysis is superior

To get the best results:

Add guidance to your project instructions or system prompt (e.g., CLAUDE.md for Claude Code):

## Code Analysis Preferences

For Java code analysis, prefer JavaLens MCP tools over text search:
- Use `find_references` instead of grep for finding usages
- Use `find_implementations` instead of text search for implementations
- Use `analyze_type` to understand a class before modifying it
- Use refactoring tools (rename_symbol, extract_method) for safe changes

Semantic analysis from JDT is more accurate than text-based search,
especially for overloaded methods, inheritance, and generic types.

What is JavaLens?

JavaLens is an MCP server that gives AI assistants deep understanding of Java codebases. It provides semantic analysis, navigation, refactoring, and code intelligence tools that go beyond simple text search.

Why Not LSP?

Language Server Protocol was designed for IDE autocomplete and basic navigation—not for AI agent workflows that require deep semantic analysis.

CapabilityNative LSPJavaLens
Find all @Annotation usages
Find all new Type() instantiations
Find all casts to a type
Distinguish field reads from writes
Detect circular package dependencies
Calculate cyclomatic complexity
Find unused private methods
Detect possible null pointer bugs

JavaLens wraps Eclipse JDT Core directly via OSGi, providing:

  • 16 fine-grained reference types: Find specifically casts, annotations, throws clauses, catch blocks, instanceof checks, method references, type arguments
  • Read vs write access distinction: Track where fields are mutated vs just read
  • Indexed search: 10x faster than AST walking for large codebases
  • Full AST access: Direct manipulation for complex refactorings

Installation

Prerequisites

  • Java 21 or later (must be on PATH or set JAVA_HOME)

JavaLens is an analytical server, not a compiler. It uses Eclipse JDT 2024-09 to parse and understand Java source code from version 1.1 through 23. Java 21 is required only as the server runtime.

Install via npm

{
  "mcpServers": {
    "javalens": {
      "command": "npx",
      "args": ["-y", "javalens-mcp"],
      "env": {
        "JAVA_PROJECT_PATH": "/path/to/your/java/project"
      }
    }
  }
}

The distribution (~19 MB) is downloaded and cached on first run.

Download

Download from Releases:

PlatformFile
All platformsjavalens.zip or javalens.tar.gz

Extract to a location of your choice (e.g., /opt/javalens or C:\javalens).

Configure MCP Client

Add to your MCP configuration (e.g., .mcp.json for Claude Code):

{
  "mcpServers": {
    "javalens": {
      "command": "java",
      "args": ["-jar", "/path/to/javalens/javalens.jar", "-data", "/path/to/javalens-workspaces"]
    }
  }
}

The -data argument specifies where JavaLens stores its workspace metadata. See How Workspaces Work below.

Auto-Load a Project

Set JAVA_PROJECT_PATH to auto-load a project when the server starts:

{
  "mcpServers": {
    "javalens": {
      "command": "java",
      "args": ["-jar", "/path/to/javalens/javalens.jar", "-data", "/path/to/javalens-workspaces"],
      "env": {
        "JAVA_PROJECT_PATH": "/path/to/your/java/project"
      }
    }
  }
}

Note: Project loading happens asynchronously in the background. The MCP server responds immediately while the project loads. Use health_check to monitor loading status—it will show "project.status": "loading" until complete, then "loaded" when ready.

How Workspaces Work

Unlike in-memory code models, Eclipse JDT requires a workspace directory to store:

  • Search indexes for fast symbol lookup
  • Compilation state and caches
  • Project metadata

Workspaces Are Outside Your Source

JavaLens creates its workspace outside your source project to keep your codebase clean:

Your Java Project (unchanged)
├── src/main/java/
├── pom.xml
└── (no Eclipse files added)

JavaLens Workspace (specified by -data)
└── {session-uuid}/
    ├── .metadata/          <- JDT indexes and state
    └── javalens-project/   <- Links to your source (not copies)

Why this matters:

  1. No pollution: Your source tree stays clean—no .project or .classpath files
  2. No conflicts: Works alongside any build system without interference
  3. Session isolation: Each MCP session gets its own workspace, enabling concurrent analysis

Session Lifecycle

  1. JavaLens starts and creates a unique workspace: {base}/{uuid}/
  2. load_project creates linked folders pointing to your source
  3. JDT builds indexes in the workspace (not in your project)
  4. When the session ends, the workspace is cleaned up

Tools

Navigation (10 tools)

ToolDescription
search_symbolsSearch types, methods, fields by glob pattern
go_to_definitionNavigate to symbol definition
find_referencesFind all usages of a symbol
find_implementationsFind interface/class implementations
get_type_hierarchyGet inheritance chain
get_document_symbolsGet all symbols in a file
get_symbol_infoGet detailed symbol information at position
get_type_at_positionGet type details at cursor
get_method_at_positionGet method details at cursor
get_field_at_positionGet field details at cursor

Fine-Grained Reference Search (9 tools)

These use JDT's unique reference type constants—not available through LSP:

ToolDescription
find_annotation_usagesFind all @Annotation usages
find_type_instantiationsFind all new Type() calls
find_castsFind all (Type) expr casts
find_instanceof_checksFind all x instanceof Type
find_throws_declarationsFind all throws Exception in signatures
find_catch_blocksFind all catch(Exception e) blocks
find_method_referencesFind all Type::method expressions
find_type_argumentsFind all List<Type> usages
find_reflection_usageFind Class.forName(), Method.invoke(), and other reflection calls

Analysis (16 tools)

ToolDescription
get_diagnosticsGet compilation errors and warnings
validate_syntaxFast syntax-only validation
get_call_hierarchy_incomingFind all callers of a method
get_call_hierarchy_outgoingFind all methods called by a method
find_field_writesFind where fields are mutated
find_testsDiscover JUnit/TestNG test methods
find_unused_codeFind unused private members
find_possible_bugsDetect null risks, empty catches, resource leaks
get_hover_infoGet documentation/signature for symbol
get_javadocGet parsed Javadoc
get_signature_helpGet method signature at call site
get_enclosing_elementGet containing method/class at position
analyze_change_impactBlast radius — all files and call sites affected by changing a symbol
analyze_data_flowVariable read/write/declaration tracking within a method
analyze_control_flowBranching, loops, return/throw points, nesting depth
get_di_registrationsFind Spring DI registrations (@Component, @Bean, @Autowired, @Inject)

Compound Analysis (4 tools)

Combine multiple queries to reduce round-trips:

ToolDescription
analyze_fileGet imports, types, diagnostics in one call
analyze_typeGet members, hierarchy, usages, diagnostics
analyze_methodGet signature, callers, callees, overrides
get_type_usage_summaryGet instantiations, casts, instanceof counts

Refactoring (10 tools)

All refactoring tools return text edits rather than applying changes directly:

ToolDescription
rename_symbolRename across entire project
organize_importsSort and clean imports
extract_variableExtract expression to local variable
extract_methodExtract code block to new method
extract_constantExtract to static final field
extract_interfaceCreate interface from class methods
inline_variableReplace variable with its initializer
inline_methodReplace call with method body
change_method_signatureModify params/return, update all callers
convert_anonymous_to_lambdaConvert anonymous class to lambda

Quick Fixes (3 tools)

ToolDescription
suggest_importsFind import candidates for unresolved type
get_quick_fixesList available fixes for problem at position
apply_quick_fixApply fix by ID (add import, remove import, add throws, try-catch)

Metrics (5 tools)

ToolDescription
get_complexity_metricsCyclomatic/cognitive complexity, LOC per method
get_dependency_graphPackage/type dependencies as nodes and edges
find_circular_dependenciesDetect package cycles using Tarjan's SCC algorithm
find_large_classesFind types exceeding method/field/line count thresholds
find_naming_violationsCheck against Java naming conventions

Project & Infrastructure (6 tools)

ToolDescription
health_checkServer status and capabilities
load_projectLoad Maven/Gradle/Bazel/plain Java project
get_project_structureGet package hierarchy
get_classpath_infoGet classpath entries
get_type_membersGet members by type name
get_super_methodFind overridden method in superclass

Usage

Basic Workflow

1. load_project(projectPath="/path/to/java/project")
2. search_symbols(query="*Service", kind="Class")
3. find_references(filePath="...", line=10, column=15)
4. analyze_type(typeName="com.example.UserService")

Coordinate System

All line/column parameters are zero-based:

  • Line 0, Column 0 = first character of file

Path Handling

  • Response paths are relative by default
  • All paths use forward slashes for cross-platform consistency
  • Input paths can be relative or absolute

Important Notes

No Live File Watching

JavaLens analyzes code at load time and does not watch for file changes. This is by design—the AI coding agent is responsible for maintaining synchronization:

EventAgent Action
After writing/editing filesCall load_project to refresh indexes
Before complex refactoringCall load_project to ensure fresh state
After external changes (git pull, etc.)Call load_project to resync

Why not automatic watching?

  1. AI agents make discrete edits with clear boundaries—auto-sync adds complexity without benefit
  2. The agent controls when analysis should reflect changes
  3. Avoids race conditions between file writes and index updates

Recommended pattern:

1. Use JavaLens tools to analyze
2. Write changes to files
3. Call load_project to refresh
4. Use JavaLens tools to verify changes

Refactoring Returns Edits

Refactoring tools return text edits but don't modify files. This gives visibility into what would change before applying.

Session Isolation

Each MCP session is independent with its own workspace UUID. Multiple sessions can analyze the same project concurrently.

Build System Support

SystemDetection
Mavenpom.xml
Gradlebuild.gradle / build.gradle.kts
BazelMODULE.bazel / WORKSPACE.bazel / WORKSPACE
Plain Javasrc/ directory

Configuration

Environment VariableDescriptionDefault
JAVA_PROJECT_PATHAuto-load project on startup(none)
JAVALENS_TIMEOUT_SECONDSOperation timeout30
JAVALENS_LOG_LEVELTRACE/DEBUG/INFO/WARN/ERRORINFO
JAVA_TOOL_OPTIONSJVM options, e.g. -Xmx2g for large projects(default: 512m via eclipse.ini)

Building from Source

git clone https://github.com/pzalutski-pixel/javalens-mcp.git
cd javalens-mcp
./mvnw clean verify

Distributions are output to org.javalens.product/target/products/.

Build Requirements

  • Java 21+ (server runtime)
  • Maven 3.9+ (wrapper included)

Architecture

┌─────────────────────────────────────────────────────────┐
│                      MCP Client                          │
└─────────────────────────────────────────────────────────┘
                            │ JSON-RPC over stdio
┌─────────────────────────────────────────────────────────┐
│  org.javalens.mcp                                        │
│    McpProtocolHandler → ToolRegistry → 56 Tools          │
└─────────────────────────────────────────────────────────┘
                            │
┌─────────────────────────────────────────────────────────┐
│  org.javalens.core                                       │
│    JdtServiceImpl → WorkspaceManager, SearchService      │
└─────────────────────────────────────────────────────────┘
                            │
┌─────────────────────────────────────────────────────────┐
│  Eclipse JDT Core (via OSGi/Equinox)                     │
│    IWorkspace, IJavaProject, SearchEngine, ASTParser     │
└─────────────────────────────────────────────────────────┘

License

MIT License - see LICENSE for details.

Reviews

No reviews yet

Sign in to write a review