代码智能MCP
通过以下方式展示JetBrains IDE代码分析功能 MCP(模型上下文协议) 用于与Claude Code等AI编码助手集成。
特性
- 查找符号 -按名称搜索类、函数或变量定义
- 查找引用 -查找项目中符号的所有用法
- 获取符号信息 -获取详细信息(类型、文件、签名)
- 列出文件符号 -列出具有层次结构的文件中的所有符号
- 获取类型层次结构 -获取类的继承层次结构
- 运行配置 -列出并执行IDE运行配置(测试、应用程序等)
- 测试结果 -获取结构化测试结果,包括通过/失败状态、持续时间、失败消息和堆栈跟踪\*
\*结构化测试结果需要SM测试运行器支持。骑士的。NET测试运行器使用ReSharper后端,该后端不向平台API公开结构化结果。看 已知限制.
支持的语言
| 语言 | 状态 | 文件扩展名 |
|---|---|---|
| JavaScript/TypeScript | ✅ 支持 | .js, .mjs, .cjs, .ts, .mts, .cts, .jsx, .tsx |
| Vue.js | ✅ 支持 | .vue |
| python✅ 支持 | .py, .pyi | |
| PHP | ✅ 支持 | .php, .phtml |
| Java✅ 支持 | .java | |
| 科特林 | ✅ 支持 | .kt, .kts |
| 锈蚀 | ✅ 支持 | .rs |
| 去吧✅ 支持 | .go | |
| Swift | ✅ 支持 | .swift |
| C✅ 支持 | .cs | |
| 飞镖 | ✅ 支持 | .dart |
需求
- JetBrains IDE(IntelliJ IDEA、PyCharm、WebStorm、GoLand、Rider等)版本2025.1+
- 对于JavaScript/TypeScript支持:JavaScript插件(捆绑在WebStorm、IntelliJ IDEA Ultimate中)
- 对于Vue.js支持:Vue.js插件(捆绑在WebStorm中,可在IntelliJ IDEA Ultimate中获得)
- 对于Python支持:已安装Python插件
- 对于PHP支持:已安装PHP插件(捆绑在PhpStorm中,可在IntelliJ IDEA Ultimate中获得)
- 对于Java支持:已安装Java插件(捆绑在IntelliJ IDEA中)
- 对于Kotlin支持:已安装Kotlin插件(捆绑在IntelliJ IDEA中)
- 对于Rust支持:已安装Rust插件(捆绑在RustRover中,可在IntelliJ IDEA Ultimate/CLion中获得)
- Go支持:安装Go插件(捆绑在GoLand中,可在IntelliJ IDEA Ultimate中获得)
- Swift支持: 仅限macOS -需要Xcode或Swift工具链和SourceKit LSP
- 对于Dart支持:已安装Dart插件(捆绑在Android Studio中,可在IntelliJ IDEA中获得)
安装
来自JetBrains市场

- 打开 设置 → 插件 → 市场
- 搜索“代码智能MCP"
- 点击 安装 → 重新启动IDE
从磁盘
- 下载
intellij-mcp-x.x.x.zip从 发布 - 打开 设置 → 插件 → ⚙️ → 从磁盘安装插件。..
- 选择zip文件→ 重新启动IDE
用法
1.启动MCP服务器
IDE启动时,服务器会自动启动。您也可以手动控制它:
- 工具 → 代码智能MCP → 启动MCP服务器
- 工具 → 代码智能MCP → 停止MCP服务器
服务器运行在 http://localhost:9876 默认情况下。
2.验证服务器
# Health check
curl http://localhost:9876/health
# Returns: OK
# Server info
curl http://localhost:9876/info
# Returns: {"name":"intellij-mcp","version":"1.0.0","languages":["python"]}3.连接克劳德代码
claude mcp add intellij-mcp --transport http http://localhost:9876/mcp或者从以下位置复制配置: 工具 → 代码智能MCP → 复制Claude代码配置
4.配置CLAUDE.md(推荐)
将以下内容添加到您的项目中 CLAUDE.md 或 ~/.claude/CLAUDE.md 帮助Claude Code利用IDE的代码分析:
## Code Intelligence MCP Integration
When working with this Python codebase, prefer using intellij-mcp tools for:
- **Finding symbol definitions** - Use `find_symbol` instead of grep/ripgrep when looking for class, function, or variable definitions. The IDE understands the language structure and provides accurate results.
- **Finding references** - Use `find_references` to find all usages of a symbol. This is more accurate than text search as it understands scope and imports.
- **Getting symbol details** - Use `get_symbol_info` to get type information, documentation, and function signatures for a symbol at a specific location.
- **Understanding code structure** - Use `get_file_symbols` to get an overview of a file's classes, methods, and functions with their signatures.
- **Exploring inheritance** - Use `get_type_hierarchy` to understand class inheritance relationships.
**Note:** Line and column numbers are **1-based**, matching editor display. Line 16 in editor = `line=16` in API.
Note: intellij-mcp requires the JetBrains IDE to be running with the project open.MCP工具
| 工具 | 说明 |
|---|---|
list_projects | 列出IDE中所有打开的项目 |
get_supported_languages | 获取支持的语言列表 |
find_symbol | 按名称查找符号定义 |
find_references | 查找对某个符号的所有引用 |
get_symbol_info | 获取详细的符号信息 |
get_file_symbols | 列出文件中的所有符号 |
get_type_hierarchy | 获取类继承层次结构 |
list_run_configurations | 列出IDE项目中的所有运行配置 |
run_configuration | 按名称执行运行配置 |
get_test_results | 从测试执行中获取结构化测试结果 |
includeLibraries 参数
这 find_symbol, find_references,以及 get_type_hierarchy 工具支持可选 includeLibraries 参数(默认值: false).当设置为 true,搜索范围扩展到包括项目依赖关系和库(例如JDK类、Python stdlib、Dart SDK、Cargo crates)。
支持:Java、Kotlin、Python、PHP、Rust、Go、Dart。不适用于JavaScript/Types/Vue.js(基于FilenameIndex)或Swift/C#(基于LSP,范围由语言服务器控制)。
示例
# Find a symbol
curl -X POST http://localhost:9876/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"find_symbol","arguments":{"name":"MyClass"}}}'Swift支持(仅限macOS)
Swift支持使用 SourceKit LSP 用于代码分析。
先决条件
- macOS -Swift支持仅在macOS上可用
- Xcode或Swift工具链 -以下之一:
- 安装Xcode(推荐,包括SourceKit LSP) - 安装Xcode命令行工具: xcode-select --install - 从以下位置安装独立的Swift工具链 swift.org
支持的项目类型
- SwiftPM项目 (与
Package.swift)-最佳支持 - Xcode项目 (
.xcodeproj)-需要先构建项目
重要说明
- 首次索引:首次打开Swift项目时,SourceKit LSP需要对项目进行索引。这可能需要10-30秒,具体取决于项目规模。在此期间,您将在IDE日志中看到“正在等待SourceKit LSP索引…”。
- 先构建你的项目:运行
swift build在使用代码分析以获得最佳结果之前。
局限性
get_type_hierarchy不支持(SourceKit LSP限制)- 项目必须做到最好
find_references结果 find_symbol需要非空搜索查询
C#支持
先决条件
安装csharp ls(推荐):
dotnet tool install --global csharp-ls支持的项目类型
- 仅限SDK风格的项目 (.NET核心/.NET 5+)
- 解决方案文件 (
.sln)-最佳支持 - 项目文件 (
.csproj)-单一项目支持 - 遗产。NET框架项目(旧式
.csproj和ToolsVersion)都是 不支持
重要说明
- 首次索引:首次打开C#项目时,LSP服务器需要对项目进行索引。这可能需要10-30秒,具体取决于项目规模。
- 先构建你的项目:运行
dotnet build在使用代码分析以获得最佳结果之前。
与Swift支持相比
get_type_hierarchy被支持 C#(与Swift不同)- 跨平台支持(Windows、macOS、Linux)
测试执行限制
这 run_configuration 和 get_test_results 这些工具最适合使用标准SM Test Runner框架的IDE:
| IDE | 运行测试 | 结构化结果 |
|---|---|---|
| IntelliJ IDEA(JUnit、TestNG) | ✅ | ✅ |
| PyCharm(pytest、unittest) | ✅ | ✅ |
| WebStorm(有,有,有速度)✅ | ✅ | |
| GoLand(去测试) | ✅ | ✅ |
| 附加程序(.NET xUnit、NUnit、TUnit) | ✅ 触发执行 | ❌ ReSharper后端 |
骑手限制:骑士。NET测试运行器通过RD协议通过ReSharper后端进行通信,该协议不向IntelliJ平台API公开结构化测试结果。测试将在IDE中成功执行,但是 get_test_results 返回降级响应,没有单独的测试细节。作为解决方法,代理可以运行 dotnet test 直接用于结构化输出。
发展
# Build
./gradlew :core:buildPlugin
# Output: core/build/distributions/intellij-mcp-x.x.x.zip使用插件运行IDE
# IntelliJ IDEA Ultimate (default)
./gradlew :core:runIde
# PyCharm Professional (for Python testing)
./gradlew :core:runPyCharm
# PhpStorm (for PHP testing)
./gradlew :core:runPhpStorm
# WebStorm (for JavaScript/TypeScript/Vue.js testing)
./gradlew :core:runWebStorm
# RustRover (for Rust testing)
./gradlew :core:runRustRover
# GoLand (for Go testing)
./gradlew :core:runGoLand
# Rider (for C# testing)
./gradlew :core:runRider