An intelligent Model Context Protocol (MCP) server for querying and analyzing Java language server codebases, specifically designed for the Ballerina Language Server project.
- Claude Desktop
- Git (for cloning repositories)
- uv - Easier way to run Python scripts :)
- Clone this repository
- Install dependencies: Using uv
uv sync- Update
claude_desktop_config.jsonto include the MCP server path, to use this MCP server with Claude Desktop . It should be located at:
/Users/[your_username]/Library/Application Support/Claude/claude_desktop_config.json
- Add the following entry in
claude_desktop_config.json:
{
"mcpServers": {
"ballerina-language-server": {
"command": "uv",
"args": [
"--directory",
"<PATH_TO_BALLERINA_LS_MCP_SERVER>",
"run",
"--active",
"run.py"
],
"env": {
"BALLERINA_REPO_PATH": "<PATH_TO_BALLERINA_LANGUAGE_SERVER_REPO>"
}
}
}
}- Restart Claude Desktop to apply the changes.
After setting up, you can use the MCP server with Claude Desktop to query and analyze the Ballerina Language Server codebase. You can verify that Claude Desktop recognizes the MCP server by clicking on the Search and tools button and observing the ballerina-language-server MCP server listed in the menu.
Enhanced fuzzy search through the codebase with relevance scoring and multi-word matching.
Example:
Query: "completion provider"
Returns: Ranked results for completion-related classes and methods
Get detailed information about a specific class including all methods and fields.
Example:
Query: "CompletionProvider"
Returns: Full class definition, methods, and context
Get comprehensive statistics about the indexed repository.
Returns:
- File count and distribution
- Top packages by class count
- Largest classes by line count
- Indexing health metrics
Find methods with similar names using phonetic matching algorithms.
Example:
Query: "getCompletion"
Returns: getCompletion, getCompletions, findCompletion, etc.
Find implementations of specific LSP protocol methods or search for common LSP patterns.
Example:
Query: "textDocument/hover"
Returns: All hover-related implementations
Analyze what LSP capabilities are implemented in the server.
Returns:
- List of implemented LSP features
- Corresponding implementation classes
- Coverage analysis
Find classes that handle LSP protocol messages (Handlers, Providers, Services, Managers).
Find what classes/methods a given class depends on and what depends on it.
Example:
Query: "DocumentSymbolProvider"
Returns: Classes that reference or use this provider
Identify common design patterns in the codebase.
Supported Patterns:
factory: Factory, Creator, Builder patternsobserver: Observer, Listener, Event, Handler patternssingleton: Singleton pattern implementationsadapter: Adapter, Wrapper patternsdecorator: Decorator patternsvisitor: Visitor pattern implementationsstrategy: Strategy, Policy patternscommand: Command, Action, Execute patterns
Find method overrides, implementations, and inheritance hierarchy.
Find configuration files, properties, and setup code.
Get an overview of the repository file structure and package organization.
Analyze code complexity metrics including method sizes and control structures.
Find error handling patterns and exception usage throughout the codebase.
Re-index the repository to pick up new changes.
-
JavaCodeIndexer: Core indexing engine with hybrid parsing approach
- Primary: Regex-based Java parsing for reliable code analysis
- Fallback: Tree-sitter AST parsing for complex scenarios
- Extracts classes, methods, fields, and imports with full metadata
- Stores structured data in SQLite with proper indexing
-
ServerConfig: Configuration management system
- Environment variable handling with validation
- Default value management and type safety
- Repository path and database configuration
-
FastMCP Tools: Comprehensive tool suite (15+ tools)
- Search Tools: Enhanced fuzzy search with relevance scoring
- Analysis Tools: Repository metrics, complexity analysis, dependency mapping
- LSP Tools: Protocol discovery, capability analysis, handler detection
- Quality Tools: Design pattern recognition, error handling analysis
- Management Tools: Re-indexing and repository maintenance
-
Output Management: Smart response handling
- Pagination for large result sets
- Configurable limits to prevent overwhelming responses
- Truncation indicators and summary statistics
- Relevance-based result ranking
The server uses SQLite with the following main tables:
files: File metadata and contentclasses: Class definitions and hierarchymethods: Method signatures and implementationsfields: Field declarationsimports: Import statements and dependencies
- Initial indexing time: Depends on repository size (typically 30-60 seconds for large repos)
- Incremental updates: Only changed files are re-processed
- Hash-based change detection: Efficient file modification tracking
- Database migration: Automatic schema updates for compatibility
- Indexed searches: Fast lookups on names, content, and metadata
- Relevance-based ranking: Multi-word fuzzy search with scoring
- Configurable result limits: Prevent overwhelming responses (default 10-15 results)
- LRU query caching: Frequently accessed data cached in memory
- Pagination support: Large result sets handled efficiently
- SQLite storage: Efficient disk-based indexing with minimal memory footprint
- Regex parsing: Lower memory usage compared to full AST parsing
- Output truncation: Long content automatically shortened with indicators
- Streaming results: Large queries processed incrementally
- Output length management: Automatic pagination and truncation
- Smart summarization: Key information highlighted in responses
- Progress indicators: Clear feedback on result completeness
- Error boundaries: Graceful handling of parsing and query errors
-
"Repository not indexed" error
- Ensure
BALLERINA_REPO_PATHis set correctly - Check that the path exists and contains Java files
- Verify read permissions on the directory
- Ensure
-
Slow indexing
- Large repositories may take several minutes to index initially
- Consider excluding test directories if not needed
- Monitor disk space for the SQLite database
-
Missing search results
- Try re-indexing with
reindex_repository() - Check if files have been recently modified
- Verify file extensions are supported (.java)
- Try re-indexing with
-
Tool output too long
- All tools now have built-in pagination and output limits
- Use
limitparameters to control result count - Responses automatically truncate with clear indicators
-
Parsing errors
- Server uses robust regex-based parsing as primary method
- Automatic fallback handling for complex code structures
- Database schema automatically migrates for compatibility
The server uses Python's standard logging module. Set log level:
import logging
logging.getLogger("ballerina-mcp").setLevel(logging.DEBUG)- Extend the
JavaCodeIndexerclass with new methods - Add corresponding MCP tool functions
- Update database schema if needed
- Add tests for new functionality
- Add new Tree-sitter language parsers
- Update
ServerConfig.supported_extensions - Modify parsing logic in
JavaCodeIndexer
- FastMCP - MCP server framework
- Tree-sitter - Code parsing library
- Ballerina Language Server - Target language server