idea-mcp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseIntelliJ IDEA MCP Skill
IntelliJ IDEA MCP Skill
MCP is self-describing - this skill only documents known pitfalls and best practices not covered by MCP descriptions.
MCP 是自描述的——本Skill仅记录MCP描述未涵盖的已知陷阱和最佳实践。
🚨 Critical Pitfalls (MCP Doesn't Warn You)
🚨 关键陷阱(MCP 未发出警告)
Connection Requirements
连接要求
- IDEA MUST be running with MCP server connected
- Commands fail silently if IDEA is not running - no clear error message
- 必须运行IDEA且已连接MCP服务器
- 如果IDEA未运行,命令会静默失败——没有明确的错误提示
Path Confusion (Most Common Error)
路径混淆(最常见错误)
- : ABSOLUTE PATH to project root (e.g.,
projectPath)/Users/name/project- ❌ (wrong - relative)
project - ✅ (correct - absolute)
/Users/name/project
- ❌
- /
filePath/pathInProject: RELATIVE to project rootdirectoryPath
- :项目根目录的绝对路径(例如:
projectPath)/Users/name/project- ❌ (错误 - 相对路径)
project - ✅ (正确 - 绝对路径)
/Users/name/project
- ❌
- /
filePath/pathInProject:相对于项目根目录的路径directoryPath
Search Command Schema Bugs
搜索命令 Schema 漏洞
MCP claims parameters are optional but they're REQUIRED:
-
&
search_in_files_by_text: MUST includesearch_in_files_by_regexmaxUsageCount- Without this → schema error
- Start with
maxUsageCount: 10
-
&
find_files_by_name_keyword: MUST includefind_files_by_globfileCountLimit- Without this → schema error "data must have required property 'probablyHasMoreMatchingFiles'"
- Critical Bug: When , MCP server omits
fileCountLimit > actual matching filesfield → schema errorprobablyHasMoreMatchingFiles - Workaround: Start with or
fileCountLimit: 1, then increase if needed2 - For common keywords (many matches), higher limits work fine
- If schema error, reduce (not increase)
fileCountLimit
MCP 声称部分参数是可选的,但实际上它们是必填的:
-
和
search_in_files_by_text:必须包含search_in_files_by_regex参数maxUsageCount- 缺少该参数会导致Schema错误
- 建议初始值设为
maxUsageCount: 10
-
和
find_files_by_name_keyword:必须包含find_files_by_glob参数fileCountLimit- 缺少该参数会导致Schema错误:"data must have required property 'probablyHasMoreMatchingFiles'"
- 严重漏洞:当 大于实际匹配文件数时,MCP服务器会省略
fileCountLimit字段,进而引发Schema错误probablyHasMoreMatchingFiles - 解决方法:初始值设为 或
fileCountLimit: 1,必要时再调高2 - 对于常见关键词(匹配结果多),可以使用更高的限制值
- 如果出现Schema错误,降低(不要调高)
fileCountLimit
Rename Refactoring Limitations
重命名重构限制
⚠️ MCP doesn't document what rename_refactoring CANNOT do:
- ✅ Renames: Field/variable declarations and their references
- ❌ May have limitations with: Method parameters in signatures, certain symbol types (test before relying)
- Always use first to understand scope
search_in_files_by_text - Always verify with after renaming
get_file_problems
⚠️ MCP 未说明 rename_refactoring 无法完成的操作:
- ✅ 可重命名:字段/变量声明及其引用
- ❌ 可能存在限制的场景:方法签名中的参数、某些符号类型(使用前请测试)
- 务必先使用 了解影响范围
search_in_files_by_text - 务必在重命名后使用 验证
get_file_problems
High-Risk Operations
高风险操作
MCP doesn't emphasize danger levels:
- : HIGH RISK - Can run ANY shell command with full system permissions (no sandboxing). Use with extreme caution; verify commands before execution.
execute_terminal_command - &
rename_refactoring: Modifies code globallyreplace_text_in_file - : Creates files on disk immediately
create_new_file - : Modifies formatting without confirmation
reformat_file
MCP 未强调操作的危险等级:
- :高风险——可以以完整系统权限运行任意Shell命令(无沙箱限制)。使用时需格外谨慎;执行前务必验证命令。
execute_terminal_command - 和
rename_refactoring:会全局修改代码replace_text_in_file - :会立即在磁盘上创建文件
create_new_file - :无需确认即可修改代码格式
reformat_file
✅ Essential Best Practices
✅ 核心最佳实践
- Path discipline: Absolute for , relative for everything else
projectPath - Count parameters: Always include for search,
maxUsageCountfor file searchfileCountLimit - File search strategy: Start with ; if schema error, reduce the limit (bug: limit > matches causes error)
fileCountLimit: 1-2 - Before refactoring: Search first to understand scope
- After changes: Use to verify no errors introduced
get_file_problems - Java accuracy: Prefer IDEA's over LSP (avoids false positives)
get_file_problems - Text replacement: Get exact text with before replacing
get_file_text_by_path - Test execution: Use for proper TeamCity-formatted output
execute_run_configuration - Timeouts: Build/test may need 120-300s, not default 30s
- 路径规范:使用绝对路径,其他路径均使用相对路径
projectPath - 必填计数参数:搜索命令务必包含 ,文件搜索命令务必包含
maxUsageCountfileCountLimit - 文件搜索策略:初始值设为 ;如果出现Schema错误,降低限制值(漏洞:限制值大于匹配数会引发错误)
fileCountLimit: 1-2 - 重构前:先搜索以了解影响范围
- 修改后:使用 验证未引入新错误
get_file_problems - Java代码准确性:优先使用IDEA的 而非LSP(避免误报)
get_file_problems - 文本替换:替换前先使用 获取准确文本
get_file_text_by_path - 测试执行:使用 以获取标准TeamCity格式的输出
execute_run_configuration - 超时设置:构建/测试可能需要120-300秒,而非默认的30秒
🔄 Common Workflows (Dongting Project)
🔄 常见工作流(洞庭项目)
Note: Examples use project path . Adjust for other projects.
/Users/huangli/dt/dongtingprojectPath注意:示例使用项目路径 。其他项目请调整 。
/Users/huangli/dt/dongtingprojectPath1. Find a Java Class by Name
1. 通过名称查找Java类
Use case: Locate in the codebase.
KvImpl.javayaml
Tool: IntelliJ-IDEA_find_files_by_name_keyword
Parameters:
projectPath: "/Users/huangli/dt/dongting" # Absolute path
nameKeyword: "KvImpl"
fileCountLimit: 2 # Start small; bug: limit > matches causes schema errorIf no results: Try with pattern:
find_files_by_globyaml
Tool: IntelliJ-IDEA_find_files_by_glob
Parameters:
projectPath: "/Users/huangli/dt/dongting"
globPattern: "**/*KvImpl*.java"
fileCountLimit: 5使用场景:定位代码库中的 。
KvImpl.javayaml
Tool: IntelliJ-IDEA_find_files_by_name_keyword
Parameters:
projectPath: "/Users/huangli/dt/dongting" # Absolute path
nameKeyword: "KvImpl"
fileCountLimit: 2 # Start small; bug: limit > matches causes schema error如果无结果:尝试使用 并指定匹配模式:
find_files_by_globyaml
Tool: IntelliJ-IDEA_find_files_by_glob
Parameters:
projectPath: "/Users/huangli/dt/dongting"
globPattern: "**/*KvImpl*.java"
fileCountLimit: 52. Search for Text Across Codebase
2. 在代码库中搜索文本
Use case: Find all occurrences of "DtLog.getLogger".
yaml
Tool: IntelliJ-IDEA_search_in_files_by_text
Parameters:
projectPath: "/Users/huangli/dt/dongting"
searchText: "DtLog.getLogger"
maxUsageCount: 20 # REQUIRED parameter
caseSensitive: trueFor regex patterns (e.g., find all log declarations):
yaml
Tool: IntelliJ-IDEA_search_in_files_by_regex
Parameters:
projectPath: "/Users/huangli/dt/dongting"
regexPattern: "private static final DtLog log = DtLogs\\.getLogger\\(.*\\)"
maxUsageCount: 10使用场景:查找所有 "DtLog.getLogger" 的出现位置。
yaml
Tool: IntelliJ-IDEA_search_in_files_by_text
Parameters:
projectPath: "/Users/huangli/dt/dongting"
searchText: "DtLog.getLogger"
maxUsageCount: 20 # REQUIRED parameter
caseSensitive: true正则表达式搜索(例如:查找所有日志声明):
yaml
Tool: IntelliJ-IDEA_search_in_files_by_regex
Parameters:
projectPath: "/Users/huangli/dt/dongting"
regexPattern: "private static final DtLog log = DtLogs\\.getLogger\\(.*\\)"
maxUsageCount: 103. Run a Test via IDEA Run Configuration
3. 通过IDEA运行配置执行测试
Use case: Execute the "client:test" run configuration.
yaml
Tool: IntelliJ-IDEA_execute_run_configuration
Parameters:
projectPath: "/Users/huangli/dt/dongting"
configurationName: "client:test"
timeout: 120000 # 2 minutes for testsFirst, list available run configurations:
yaml
Tool: IntelliJ-IDEA_get_run_configurations
Parameters:
projectPath: "/Users/huangli/dt/dongting"使用场景:执行 "client:test" 运行配置。
yaml
Tool: IntelliJ-IDEA_execute_run_configuration
Parameters:
projectPath: "/Users/huangli/dt/dongting"
configurationName: "client:test"
timeout: 120000 # 2 minutes for tests先列出可用的运行配置:
yaml
Tool: IntelliJ-IDEA_get_run_configurations
Parameters:
projectPath: "/Users/huangli/dt/dongting"4. Check Compilation Errors in a File
4. 检查文件中的编译错误
Use case: Verify has no errors.
server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.javayaml
Tool: IntelliJ-IDEA_get_file_problems
Parameters:
projectPath: "/Users/huangli/dt/dongting"
filePath: "server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.java"
errorsOnly: trueNote: More accurate than LSP for this multi-module Maven project.
使用场景:验证 无错误。
server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.javayaml
Tool: IntelliJ-IDEA_get_file_problems
Parameters:
projectPath: "/Users/huangli/dt/dongting"
filePath: "server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.java"
errorsOnly: true注意:对于这个多模块Maven项目,该方法比LSP更准确。
5. Safe Refactoring: Rename a Field
5. 安全重构:重命名字段
Pre-verification: Search for current usage:
yaml
Tool: IntelliJ-IDEA_search_in_files_by_text
Parameters:
projectPath: "/Users/huangli/dt/dongting"
searchText: "currentTerm"
maxUsageCount: 50Execute rename:
yaml
Tool: IntelliJ-IDEA_rename_refactoring
Parameters:
projectPath: "/Users/huangli/dt/dongting"
pathInProject: "server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.java"
symbolName: "currentTerm"
newName: "currentElectionTerm"Post-verification: Check for errors:
yaml
Tool: IntelliJ-IDEA_get_file_problems
Parameters:
projectPath: "/Users/huangli/dt/dongting"
filePath: "server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.java"预验证:搜索当前字段的使用情况:
yaml
Tool: IntelliJ-IDEA_search_in_files_by_text
Parameters:
projectPath: "/Users/huangli/dt/dongting"
searchText: "currentTerm"
maxUsageCount: 50执行重命名:
yaml
Tool: IntelliJ-IDEA_rename_refactoring
Parameters:
projectPath: "/Users/huangli/dt/dongting"
pathInProject: "server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.java"
symbolName: "currentTerm"
newName: "currentElectionTerm"后验证:检查是否存在错误:
yaml
Tool: IntelliJ-IDEA_get_file_problems
Parameters:
projectPath: "/Users/huangli/dt/dongting"
filePath: "server/src/main/java/com/github/dtprj/dongting/raft/server/RaftNode.java"6. Explore Project Structure
6. 探索项目结构
Use case: View module layout.
yaml
Tool: IntelliJ-IDEA_list_directory_tree
Parameters:
projectPath: "/Users/huangli/dt/dongting"
directoryPath: "." # Project root
maxDepth: 3To see all open files (helpful for context):
yaml
Tool: IntelliJ-IDEA_get_all_open_file_paths
Parameters:
projectPath: "/Users/huangli/dt/dongting"使用场景:查看模块布局。
yaml
Tool: IntelliJ-IDEA_list_directory_tree
Parameters:
projectPath: "/Users/huangli/dt/dongting"
directoryPath: "." # Project root
maxDepth: 3查看所有已打开文件(有助于了解上下文):
yaml
Tool: IntelliJ-IDEA_get_all_open_file_paths
Parameters:
projectPath: "/Users/huangli/dt/dongting"🤔 When to Use: IDEA MCP vs LSP vs Bash Tools
🤔 工具选择:IDEA MCP vs LSP vs Bash工具
Decision Matrix
决策矩阵
| Task | Recommended Tool | Why |
|---|---|---|
| Java code analysis (errors, warnings) | IDEA MCP ( | More accurate for multi-module Maven projects; avoids LSP false positives |
| Running tests | IDEA MCP ( | Proper test environment, TeamCity-formatted output, dependency resolution |
| Refactoring (rename, move) | IDEA MCP ( | Semantic understanding, cross-file updates, safer than manual edits |
| Search code (text, regex) | IDEA MCP ( | Fast, indexes entire project; better than |
| Find files (by name, glob) | IDEA MCP ( | Fast indexed search; use workarounds for schema bugs |
| Read file content | LSP ( | LSP for quick reads; IDEA for large files or binary detection |
| Build/compile | Bash ( | Full control, reproducible; IDEA build may have caching issues |
| Git operations | Bash ( | Standard, predictable; IDEA MCP lacks git tools |
| Project exploration | IDEA MCP ( | Visual tree structure; better than |
| Terminal commands | IDEA MCP ( | IDEA for integrated terminal; Bash for complex pipelines |
| 任务 | 推荐工具 | 原因 |
|---|---|---|
| Java代码分析(错误、警告) | IDEA MCP ( | 对多模块Maven项目更准确;避免LSP误报 |
| 运行测试 | IDEA MCP ( | 提供合适的测试环境、TeamCity格式输出、依赖解析 |
| 重构(重命名、移动) | IDEA MCP ( | 具备语义理解能力、跨文件更新、比手动编辑更安全 |
| 代码搜索(文本、正则) | IDEA MCP ( | 速度快,索引整个代码库;比 |
| 查找文件(按名称、通配符) | IDEA MCP ( | 基于索引的快速搜索;针对Schema漏洞使用解决方法 |
| 读取文件内容 | LSP( | LSP适合快速读取;IDEA适合大文件或二进制文件检测 |
| 构建/编译 | Bash( | 完全可控、可复现;IDEA构建可能存在缓存问题 |
| Git操作 | Bash( | 标准、可预测;IDEA MCP缺少Git工具 |
| 项目探索 | IDEA MCP ( | 可视化树状结构;比 |
| 终端命令 | IDEA MCP ( | IDEA适合集成终端;Bash适合复杂管道操作 |
Key Principles
核心原则
- IDEA MCP when: Need IDE intelligence (refactoring, accurate errors, test execution)
- LSP when: Quick file reads, symbol navigation (if IDEA not available)
- Bash when: Builds, Git, system operations, or when IDEA MCP has schema bugs
Remember: IDEA must be running for MCP tools to work. If IDEA is unavailable, fall back to LSP/Bash.
- 使用IDEA MCP的场景:需要IDE智能能力(重构、精准错误检测、测试执行)
- 使用LSP的场景:快速读取文件、符号导航(当IDEA不可用时)
- 使用Bash的场景:构建、Git操作、系统操作,或IDEA MCP存在Schema漏洞时
注意:使用MCP工具时必须运行IDEA。如果IDEA不可用, fallback到LSP或Bash工具。
⏱️ Performance Considerations & Timeouts
⏱️ 性能考量与超时设置
Recommended Timeouts by Operation
各操作推荐超时时间
| Operation | Recommended Timeout | Notes |
|---|---|---|
File search ( | 30000 (30s) | Usually fast; start with |
Text search ( | 60000 (60s) | Can be slower for large codebases; use |
Read file ( | 10000 (10s) | Fast for text files; binary files may fail |
Get file problems ( | 15000 (15s) | Quick analysis |
Run configuration ( | 300000 (5min) | Tests/builds can take minutes; adjust based on test size |
Build project ( | 300000 (5min) | Full rebuild may be slow |
Refactoring ( | 60000 (60s) | Usually fast for single symbols |
Directory listing ( | 20000 (20s) | Depends on project size |
| 操作 | 推荐超时时间 | 说明 |
|---|---|---|
文件搜索 ( | 30000(30秒) | 通常速度快;初始值设为 |
文本搜索 ( | 60000(60秒) | 大型代码库可能较慢;使用 |
读取文件 ( | 10000(10秒) | 文本文件读取速度快;二进制文件可能读取失败 |
获取文件问题 ( | 15000(15秒) | 分析速度快 |
运行配置 ( | 300000(5分钟) | 测试/构建可能需要数分钟;根据测试规模调整 |
构建项目 ( | 300000(5分钟) | 完整重构可能较慢 |
重构 ( | 60000(60秒) | 单个符号重构通常速度快 |
目录列表 ( | 20000(20秒) | 取决于项目规模 |
Performance Tips
性能优化技巧
- Limit search results: Use and
maxUsageCountto avoid excessive data transferfileCountLimit - Cache project state: IDEA MCP maintains project index; repeated searches are faster
- Avoid redundant calls: Use to see what's already loaded
get_all_open_file_paths - Batch operations: Combine searches with careful planning (but MCP is stateless)
- Fallback for large operations: For full project builds, use Bash commands instead
mvn
- 限制搜索结果:使用和
maxUsageCount避免过多数据传输fileCountLimit - 缓存项目状态:IDEA MCP维护项目索引;重复搜索速度更快
- 避免冗余调用:使用查看已加载的文件
get_all_open_file_paths - 批量操作:通过周密规划组合搜索操作(但MCP是无状态的)
- 大型操作的备选方案:全项目构建使用Bash的命令
mvn
Memory & Resource Considerations
内存与资源考量
- IDEA MCP runs within IDEA's JVM; large operations may affect IDE performance
- Searching huge files (>10MB) may cause timeouts; use LSP with offset/limit instead
read - Concurrent MCP requests may queue; avoid parallel operations on same project
- IDEA MCP运行在IDEA的JVM中;大型操作可能影响IDE性能
- 搜索超大文件(>10MB)可能超时;改用LSP的工具并指定偏移量/限制
read - 同一项目的并发MCP请求可能排队;避免并行操作
🔧 Quick Troubleshooting
🔧 快速故障排除
Common Error Messages and Solutions
常见错误信息与解决方案
| Error Message | Likely Cause | Solution |
|---|---|---|
| Missing | Add required parameter: |
| | Reduce |
| IDEA not running or MCP server not connected | Verify IDEA is running with MCP plugin active; wait for connection |
| Operation taking longer than default timeout | Increase |
| Incorrect path (absolute vs relative confusion) | Use absolute path for |
| Search text not found or path incorrect | Verify search text exists; check |
| Trying to read binary/ non-text file | Use |
| | Verify project is fully loaded in IDEA; use absolute path |
| 错误信息 | 可能原因 | 解决方案 |
|---|---|---|
| 缺少 | 添加必填参数:文件搜索设 |
| | 降低 |
| IDEA未运行或MCP服务器未连接 | 验证IDEA已运行且MCP插件已激活;等待连接建立 |
| 操作耗时超过默认超时时间 | 调高 |
| 路径错误(绝对/相对路径混淆) | |
| 搜索文本不存在或路径错误 | 验证搜索文本存在;检查 |
| 尝试读取二进制/非文本文件 | |
| | 验证项目已在IDEA中完全加载;使用绝对路径 |
"Structured content does not match" (schema error)
"Structured content does not match"(Schema错误)
- Add missing or
maxUsageCountparameterfileCountLimit - For :
find_files_by_name_keyword> actual matches causes this bug. Reduce the limit to 1 or 2, then increase if neededfileCountLimit
- 添加缺失的或
maxUsageCount参数fileCountLimit - 针对:当
find_files_by_name_keyword大于实际匹配数时会触发该漏洞。降低限制值至1或2,必要时再调高fileCountLimit
Commands fail/timeout
命令失败/超时
- Verify IDEA is running with MCP server connected
- Check MCP plugin is active in IDEA settings
- Wait for connection (may take seconds)
- Verify project is fully loaded in IDEA
- 验证IDEA已运行且已连接MCP服务器
- 检查IDEA设置中MCP插件已激活
- 等待连接建立(可能需要数秒)
- 验证项目已在IDEA中完全加载
Search returns no results
搜索无结果
- Verify is absolute and correct
projectPath - Verify file paths are relative to project root
- Use to verify structure exists
list_directory_tree
- 验证是正确的绝对路径
projectPath - 验证文件路径是相对于项目根目录的相对路径
- 使用验证结构存在
list_directory_tree
File operation fails
文件操作失败
- For : Use
create_new_fileif file existsoverwrite: true - For : Get exact text with
replace_text_in_filefirstget_file_text_by_path - Check file is not locked by another process
- 对于:如果文件已存在,使用
create_new_file参数overwrite: true - 对于:替换前先使用
replace_text_in_file获取准确文本get_file_text_by_path - 检查文件是否被其他进程锁定