This MCP server provides AI-assisted Java code refactoring capabilities. Ask your AI assistant to analyze, explore, and refactor Java codebases using a collection of specialized tools organized into functional groups.
Before refactoring, your project needs to be configured:
- Discover - The tool detects your build system (Maven, Gradle, etc.)
- Build - Computes the build configuration
- Test - Validates everything is ready
Your AI assistant can guide you through this setup.
The refactoring tools are organized into 7 functional groups:
Purpose: Find and list structural elements in your codebase
Available Tools:
queryTypes- Search for classes, interfaces, and recordsqueryMethods- Find methods by name or characteristicsqueryPackages- List packagesqueryFiles- Find source filesqueryLocalVariablesWithinScope- Find local variablesqueryFqnToPath- Get file paths for types or packages
What You Can Do:
- "Find all classes with 'User' in the name"
- "Show me methods that take zero parameters"
- "List all packages under com.example.service"
- "Find all Service.java files in my project"
- "Where is the UserService class located on disk?"
- "Show me local variables in the processOrder method"
Purpose: Get actual source code and documentation
Available Tools:
queryTypeSources- Get source code for typesqueryMethodSources- Get source code for methodsqueryDocstrings- Get documentation/javadocs
What You Can Do:
- "Show me the source code for UserService and OrderService"
- "Get the implementation of the login method"
- "Show me all the javadoc comments for the Payment class"
- "Read the source code for these specific methods"
Purpose: Understand how code elements relate to each other
Available Tools:
queryTypeDependencies- Find what a type depends onqueryDependentTypes- Find what depends on a typequeryFootprint- Analyze the impact footprint of typesqueryPackagesWithFootprint- Get dependency statistics for packagesqueryExternalLibraries- List external libraries usedqueryExternalLibrariesWithDependantStatistics- See how external libraries are usedqueryCyclesInPackageDependencyGraph- Find circular dependenciesqueryMethodCallGraph- See how methods call each otherqueryAbstractnessInstability- Measure package architecture quality
What You Can Do:
- "What does UserService depend on?"
- "What classes use the User type?"
- "Show me which packages use Spring Framework"
- "Are there any circular dependencies in my package structure?"
- "How does the processPayment method call other methods?"
- "Which packages have poor architecture metrics?"
- "What's the dependency footprint of my authentication module?"
- "Show me all external libraries and how many classes use each one"
Purpose: Compute detailed usage patterns and call paths
Available Tools:
computeTypeUsages- Find all variables, fields, and parameters of a specific typecomputeTypeUsageInBulk- Find usage for multiple types at oncecomputeCallPath- Find call paths between methodscomputeOverviewOfNames- Get naming statistics
What You Can Do:
- "Find every place where the User type is used as a variable or field"
- "Show me usage patterns for User, Order, and Product types"
- "How can I call from the Controller to the saveUser method?"
- "What are the most common variable names in my service layer?"
- "Show me naming patterns for types used in the repository package"
Purpose: Rename and refactor code elements
Available Tools:
Single Element Operations:
renameField- Rename a fieldrenameLocalVariable- Rename a local variablerenameMethod- Rename a methodrenameParameter- Rename a method parameterrenameTypeParameter- Rename a generic type parameterrenameOrMoveType- Rename or move a class/interface/record
Bulk Operations:
bulkRenameField- Rename multiple fields at oncebulkRenameLocalVariable- Rename multiple local variablesbulkRenameParameter- Rename multiple parametersbulkRenameOrMoveType- Rename or move multiple types
Advanced Operations:
clusterTypesIntoPackages- Suggest better package organizationextractInterface- Extract an interface from a classimpactOfExtractInterfaceRequest- See what would happen before extracting
What You Can Do:
- "Rename the userName field to username in the User class"
- "Rename the getData method to getUserData"
- "Move UserService from com.example.old to com.example.new"
- "Rename userName to username in all User-related classes at once"
- "Show me better package organization based on my dependencies"
- "Extract an interface from UserService"
- "What would change if I extract an interface from OrderProcessor?"
Purpose: Handle complex multi-stage refactorings with planning and user review
Available Tools:
computeExtractInterfacePlans- Generate multiple interface extraction optionscomputeGlobalRenameIdentifierPlan- Plan systematic identifier renaminglistPlans- See all computed refactoring plansexecutePlan- Execute a selected plan- Plus UI tools for reviewing and selecting specific steps
What You Can Do:
- "Generate different interface extraction options for my service classes"
- "Create a plan to rename 'data' to 'userData' everywhere in my code"
- "Show me all the refactoring plans you've generated"
- "Let me review the steps in this plan and choose which ones to execute"
- "Execute the interface extraction plan I selected"
How It Works: The Plan Manager creates detailed refactoring plans, lets you review them in a web interface, select which specific steps you want, then executes only your selections. This is ideal for large-scale changes where you want fine-grained control.
Purpose: Monitor and control refactoring operations
Available Tools:
listRuns- See all refactoring runsstatusOfRun- Check the status of a running operationgetRunResult- Get the results when completerejectRun- Reject changes and discard themresetRun- Reset to try againinterruptRun- Stop a long-running operation
What You Can Do:
- "Show me all the refactoring operations that have run"
- "What's the status of the current refactoring?"
- "Is the interface extraction finished yet?"
- "I don't want these changes, reject this run"
- "Stop the current refactoring operation"
- "Reset this run so I can try different parameters"
How It Works: Large refactorings can take time. The Run Manager lets you monitor progress, and when complete, you review and approve changes through a web interface before they're permanently applied.
Before refactoring, understand your code:
-
Find what exists (Code Explorer)
- "Find all classes related to authentication"
- "List all packages in the service layer"
-
Read the code (Source Reader)
- "Show me the source for AuthenticationService"
-
Understand relationships (Dependency Analyzer)
- "What does AuthenticationService depend on?"
- "What classes use the User type?"
Use analysis tools to plan refactoring:
-
Analyze impact (Usage Computer, Dependency Analyzer)
- "Find all usages of the User type"
- "Show me the dependency footprint of this module"
-
Check feasibility (Code Refactor impact tools)
- "What would happen if I extract an interface from UserService?"
Choose based on complexity:
Simple changes (Code Refactor):
- "Rename userName to username"
- "Extract an interface from UserService"
Complex changes (Plan Manager):
- "Generate interface extraction plans for all my services"
- "Create a global rename plan for 'data' to 'userData'"
- Then review plans, select steps, and execute
For operations that take time:
-
Check progress (Run Manager)
- Your AI assistant monitors automatically
- "What's the status of this refactoring?"
-
Review and approve
- Use the web interface to see exact changes
- Approve what you want, reject what you don't