npx skills add https://github.com/massgen/massgen --skill serena使用基于语言服务器协议(LSP)的类 IDE 语义分析,在符号级别导航和操作代码。
您可能通过以下一种或两种方式获得 Serena:
选项 1:直接 MCP 工具(如果由您的编排器配置)请检查您的可用工具中是否有:
find_symbol, find_referencing_symbols - 符号查找rename_symbol, replace_symbol_body - 重构insert_after_symbol, insert_before_symbol - 精确插入onboarding, activate_project - 项目理解广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
write_memory, read_memory - 保存上下文如果您看到这些工具,请直接使用它们——它们提供完整的 Serena 功能!
选项 2:CLI 命令(始终可通过 execute_command 使用)您可以使用以下方式运行 serena 命令:
execute_command("uvx --from git+https://github.com/oraios/serena serena <command>")
此技能侧重于 CLI 使用模式。如果您有直接的 MCP 工具,建议优先使用它们以获得更好的集成体验。
serena 技能提供对 Serena 的访问,Serena 是一个编码代理工具包,可将基于文本的 LLM 转变为具备符号感知能力的代码代理。与传统的文本搜索(ripgrep)或结构搜索(ast-grep)不同,Serena 通过 LSP 集成理解代码语义。
核心能力:
Serena 在符号级别而非文本或语法级别运行,提供对代码结构、作用域和关系的真正类 IDE 理解。
当您需要符号级代码理解时,请使用 serena 技能:
代码导航:
代码理解:
代码重构:
在以下情况下选择 serena 而非文件搜索(ripgrep/ast-grep):
在以下情况下仍使用文件搜索:
Serena 使用 LSP 服务器进行语义分析。大多数常见语言都开箱即用:
LSP 服务器为您正在使用的语言提供符号信息。
find_symbol)定位符号在代码库中的定义位置。
注意: 以下所有示例均使用简写形式 serena <command>。完整命令是:
uvx --from git+https://github.com/oraios/serena serena <command>
# 查找类定义
execute_command("uvx --from git+https://github.com/oraios/serena serena find_symbol --name 'UserService' --type class")
# 查找函数定义
execute_command("uvx --from git+https://github.com/oraios/serena serena find_symbol --name 'authenticate' --type function")
# 查找变量定义
execute_command("uvx --from git+https://github.com/oraios/serena serena find_symbol --name 'API_KEY' --type variable")
使用场景:
输出格式:
File: src/services/user_service.py
Line: 42
Symbol: UserService (class)
Context: class UserService(BaseService):
find_referencing_symbols)发现符号被使用、导入或引用的所有位置。
# 查找类的所有用法
execute_command("serena find_referencing_symbols --name 'UserService'")
# 查找函数的所有调用点
execute_command("serena find_referencing_symbols --name 'authenticate'")
# 查找变量的所有读/写操作
execute_command("serena find_referencing_symbols --name 'API_KEY'")
使用场景:
输出格式:
Found 12 references to 'authenticate':
1. src/api/routes.py:34
authenticate(user_credentials)
2. src/middleware/auth.py:18
from services import authenticate
3. tests/test_auth.py:56
mock_authenticate = Mock(spec=authenticate)
...
insert_after_symbol)以手术般的精度在特定符号位置插入代码。
# 向类添加方法
execute_command("""serena insert_after_symbol --name 'UserService' --type class --code '
def get_user_by_email(self, email: str) -> Optional[User]:
return self.db.query(User).filter_by(email=email).first()
'""")
# 在函数调用后插入错误处理
execute_command("""serena insert_after_symbol --name 'database_query' --code '
if result is None:
raise DatabaseError("Query returned no results")
'""")
# 向数据类添加字段
execute_command("""serena insert_after_symbol --name 'User' --type class --code '
email_verified: bool = False
'""")
使用场景:
安全特性:
当更改函数签名或行为时:
# 步骤 1:查找函数定义
serena find_symbol --name 'process_payment' --type function
# 步骤 2:查找所有调用点
serena find_referencing_symbols --name 'process_payment'
# 步骤 3:分析影响(审查输出)
# [审查所有使用位置以了解影响]
# 步骤 4:有信心地进行更改
# [根据发现更新函数和所有调用点]
当使用新方法扩展类时:
# 步骤 1:定位类
serena find_symbol --name 'PaymentProcessor' --type class
# 步骤 2:验证无冲突
serena find_symbol --name 'process_refund' --type function
# 步骤 3:插入新方法
serena insert_after_symbol --name 'PaymentProcessor' --type class --code '
def process_refund(self, payment_id: str, amount: float) -> bool:
# Implementation here
pass
'
当分析代码关系时:
# 步骤 1:查找类定义
serena find_symbol --name 'DatabaseManager' --type class
# 步骤 2:查找所有用法
serena find_referencing_symbols --name 'DatabaseManager'
# 步骤 3:对于每个用法,查找哪些符号使用该代码
# [重复引用追踪以构建依赖图]
当识别未使用的代码时:
# 步骤 1:查找符号定义
serena find_symbol --name 'legacy_auth_handler'
# 步骤 2:检查引用
serena find_referencing_symbols --name 'legacy_auth_handler'
# 步骤 3:如果零引用(定义除外),标记为待删除
# [如果输出仅显示定义,则该符号未使用]
Serena 和文件搜索(ripgrep/ast-grep)是互补工具。结合使用它们:
先使用 ripgrep 再使用 serena:
# 1. 使用 ripgrep 查找潜在匹配项(快速、广泛)
rg "authenticate" --type py
# 2. 使用 serena 缩小到特定符号(精确)
serena find_symbol --name 'authenticate' --type function
serena find_referencing_symbols --name 'authenticate'
先使用 serena 再使用 ripgrep:
# 1. 使用 serena 查找符号定义
serena find_symbol --name 'UserService'
# 2. 使用 ripgrep 搜索相关模式
rg "UserService\(" --type py # 查找直接实例化
rg "class.*UserService" --type py # 查找子类
| 任务 | 最佳工具 | 原因 |
|---|---|---|
| 查找字符串字面量 | ripgrep | 基于文本,快速 |
| 查找待办事项/注释 | ripgrep | 基于文本 |
| 查找符号定义 | serena | 符号感知 |
| 查找所有引用 | serena | 语义理解 |
| 查找代码模式 | ast-grep | 语法感知 |
| 在符号处插入 | serena | 精确定位 |
| 跨语言搜索 | ripgrep | 语言无关 |
| 理解作用域 | serena | LSP 语义信息 |
始终首先定位符号定义:
# 良好实践:先查找定义,再查找引用
serena find_symbol --name 'MyClass'
serena find_referencing_symbols --name 'MyClass'
# 避免:在未确认定义存在的情况下搜索引用
尽可能使用 --type 缩小搜索范围:
# 良好实践:特定类型减少歧义
serena find_symbol --name 'User' --type class
# 精度较低:可能匹配 User 函数、User 变量等
serena find_symbol --name 'User'
在插入代码前始终查找符号:
# 良好实践:先验证目标存在
serena find_symbol --name 'PaymentService' --type class
# [审查输出以确认正确的类]
serena insert_after_symbol --name 'PaymentService' --code '...'
# 有风险:未经验证就插入
serena insert_after_symbol --name 'PaymentService' --code '...'
检查引用输出以进行影响分析:
# 查找引用并评估影响
serena find_referencing_symbols --name 'deprecated_function'
# 如果有 50+ 个引用,请规划仔细的迁移
# 如果 0 个引用,可以安全移除
插入后,验证更改:
serena insert_after_symbol --name 'MyClass' --code '...'
git diff # 提交前审查实际更改
Serena 通过 LSP 集成支持 30 多种语言:
第 1 层(完全测试):
第 2 层(社区测试):
第 3 层(实验性):
有关完整列表和设置说明,请参阅 Serena 语言支持文档。
搜索文本/注释:请改用 ripgrep
# 错误工具:Serena 不搜索注释
serena find_symbol --name "TODO"
# 正确工具:使用 ripgrep 搜索文本
rg "TODO"
生成的代码:LSP 可能不会索引自动生成的文件
非常大的代码库:符号索引可能很慢
没有类型的动态语言:语义信息有限
Serena 专为令牌高效的代码导航而设计:
# 传统方法(低效)
execute_command("cat entire_file.py") # 1000+ 令牌
# [在输出中手动搜索符号]
# Serena 方法(高效)
serena find_symbol --name 'MyClass' # 50 令牌
# [立即获得精确位置]
与替代方案的比较:
如果 find_symbol 未返回结果:
验证符号是否存在:使用 ripgrep 确认
rg "class MyClass" --type py
检查语言服务器:确保已为语言配置 LSP
serena status # 检查 LSP 服务器状态
尝试大小写变体:符号名称区分大小写
serena find_symbol --name 'myclass' # 尝试不同的大小写
重建索引:强制 LSP 重新索引
serena reindex # 重建符号索引
如果 find_referencing_symbols 返回数百个结果:
先使用文件搜索:使用 ripgrep 缩小范围
rg "MyClass" src/services/ # 限制到特定目录
serena find_referencing_symbols --name 'MyClass' --path src/services/
按引用类型过滤:专注于特定的使用模式
# 仅查找导入
rg "from .* import.*MyClass" --type py
优先处理最近的更改:先检查 git 历史记录
git log --all -p -S 'MyClass' --since="1 week ago"
如果 insert_after_symbol 失败:
每周安装量
82
代码库
GitHub 星标数
891
首次出现
2026 年 1 月 22 日
安全审计
安装于
codex70
opencode70
claude-code66
gemini-cli65
github-copilot61
cursor57
Navigate and manipulate code at the symbol level using IDE-like semantic analysis powered by Language Server Protocol (LSP).
You may have Serena available in one or both of these ways:
Option 1: Direct MCP Tools (if configured by your orchestrator) Check your available tools for:
find_symbol, find_referencing_symbols - Symbol lookuprename_symbol, replace_symbol_body - Refactoringinsert_after_symbol, insert_before_symbol - Precise insertionsonboarding, activate_project - Project understandingwrite_memory, read_memory - Save contextIf you see these tools, use them directly - they provide full Serena capabilities!
Option 2: CLI Commands (always available via execute_command) You can run serena commands using:
execute_command("uvx --from git+https://github.com/oraios/serena serena <command>")
This skill focuses on CLI usage patterns. If you have direct MCP tools, prefer those for better integration.
The serena skill provides access to Serena, a coding agent toolkit that transforms text-based LLMs into symbol-aware code agents. Unlike traditional text search (ripgrep) or structural search (ast-grep), Serena understands code semantics through LSP integration.
Key capabilities:
Serena operates at the symbol level rather than the text or syntax level, providing true IDE-like understanding of code structure, scope, and relationships.
Use the serena skill when you need symbol-level code understanding:
Code Navigation:
Code Understanding:
Code Refactoring:
Choose serena over file-search (ripgrep/ast-grep) when:
Still use file-search when:
Serena uses LSP servers for semantic analysis. Most common languages are supported out-of-the-box:
The LSP servers provide symbol information for the language you're working with.
find_symbol)Locate where a symbol is defined in your codebase.
Note: All examples below use the short form serena <command>. The full command is:
uvx --from git+https://github.com/oraios/serena serena <command>
# Find a class definition
execute_command("uvx --from git+https://github.com/oraios/serena serena find_symbol --name 'UserService' --type class")
# Find a function definition
execute_command("uvx --from git+https://github.com/oraios/serena serena find_symbol --name 'authenticate' --type function")
# Find a variable definition
execute_command("uvx --from git+https://github.com/oraios/serena serena find_symbol --name 'API_KEY' --type variable")
Use cases:
Output format:
File: src/services/user_service.py
Line: 42
Symbol: UserService (class)
Context: class UserService(BaseService):
find_referencing_symbols)Discover all locations where a symbol is used, imported, or referenced.
# Find all usages of a class
execute_command("serena find_referencing_symbols --name 'UserService'")
# Find all call sites of a function
execute_command("serena find_referencing_symbols --name 'authenticate'")
# Find all reads/writes of a variable
execute_command("serena find_referencing_symbols --name 'API_KEY'")
Use cases:
Output format:
Found 12 references to 'authenticate':
1. src/api/routes.py:34
authenticate(user_credentials)
2. src/middleware/auth.py:18
from services import authenticate
3. tests/test_auth.py:56
mock_authenticate = Mock(spec=authenticate)
...
insert_after_symbol)Insert code at specific symbol locations with surgical precision.
# Add a method to a class
execute_command("""serena insert_after_symbol --name 'UserService' --type class --code '
def get_user_by_email(self, email: str) -> Optional[User]:
return self.db.query(User).filter_by(email=email).first()
'""")
# Insert error handling after a function call
execute_command("""serena insert_after_symbol --name 'database_query' --code '
if result is None:
raise DatabaseError("Query returned no results")
'""")
# Add a field to a dataclass
execute_command("""serena insert_after_symbol --name 'User' --type class --code '
email_verified: bool = False
'""")
Use cases:
Safety features:
When changing a function signature or behavior:
# Step 1: Find the function definition
serena find_symbol --name 'process_payment' --type function
# Step 2: Find all call sites
serena find_referencing_symbols --name 'process_payment'
# Step 3: Analyze impact (review output)
# [Review all usage locations to understand impact]
# Step 4: Make changes with confidence
# [Update function and all call sites based on findings]
When extending a class with new methods:
# Step 1: Locate the class
serena find_symbol --name 'PaymentProcessor' --type class
# Step 2: Verify no conflicts
serena find_symbol --name 'process_refund' --type function
# Step 3: Insert new method
serena insert_after_symbol --name 'PaymentProcessor' --type class --code '
def process_refund(self, payment_id: str, amount: float) -> bool:
# Implementation here
pass
'
When analyzing code relationships:
# Step 1: Find class definition
serena find_symbol --name 'DatabaseManager' --type class
# Step 2: Find all usages
serena find_referencing_symbols --name 'DatabaseManager'
# Step 3: For each usage, find what symbols use that code
# [Repeat reference tracking to build dependency graph]
When identifying unused code:
# Step 1: Find symbol definition
serena find_symbol --name 'legacy_auth_handler'
# Step 2: Check references
serena find_referencing_symbols --name 'legacy_auth_handler'
# Step 3: If zero references (except definition), mark for removal
# [If output shows only the definition, symbol is unused]
Serena and file-search (ripgrep/ast-grep) are complementary tools. Use them together:
Use ripgrep THEN serena:
# 1. Find potential matches with ripgrep (fast, broad)
rg "authenticate" --type py
# 2. Narrow to specific symbol with serena (precise)
serena find_symbol --name 'authenticate' --type function
serena find_referencing_symbols --name 'authenticate'
Use serena THEN ripgrep:
# 1. Find symbol definition with serena
serena find_symbol --name 'UserService'
# 2. Search for related patterns with ripgrep
rg "UserService\(" --type py # Find direct instantiations
rg "class.*UserService" --type py # Find subclasses
| Task | Best Tool | Why |
|---|---|---|
| Find string literals | ripgrep | Text-based, fast |
| Find TODOs/comments | ripgrep | Text-based |
| Find symbol definition | serena | Symbol-aware |
| Find all references | serena | Semantic understanding |
| Find code patterns | ast-grep | Syntax-aware |
| Insert at symbol | serena | Precise positioning |
| Search across languages | ripgrep | Language-agnostic |
| Understand scope | serena | LSP semantic info |
Always locate the symbol definition first:
# GOOD: Find definition, then references
serena find_symbol --name 'MyClass'
serena find_referencing_symbols --name 'MyClass'
# AVOID: Searching for references without confirming definition exists
Narrow searches with --type when possible:
# GOOD: Specific type reduces ambiguity
serena find_symbol --name 'User' --type class
# LESS PRECISE: May match User function, User variable, etc.
serena find_symbol --name 'User'
Always find the symbol before inserting code:
# GOOD: Verify target exists first
serena find_symbol --name 'PaymentService' --type class
# [Review output to confirm correct class]
serena insert_after_symbol --name 'PaymentService' --code '...'
# RISKY: Inserting without verification
serena insert_after_symbol --name 'PaymentService' --code '...'
Check reference output for impact analysis:
# Find references and assess impact
serena find_referencing_symbols --name 'deprecated_function'
# If 50+ references, plan careful migration
# If 0 references, safe to remove
After insertions, verify changes:
serena insert_after_symbol --name 'MyClass' --code '...'
git diff # Review actual changes before committing
Serena supports 30+ languages through LSP integration:
Tier 1 (Fully tested):
Tier 2 (Community tested):
Tier 3 (Experimental):
For the complete list and setup instructions, see Serena language support docs.
Searching text/comments : Use ripgrep instead
# WRONG TOOL: Serena doesn't search comments
serena find_symbol --name "TODO"
# RIGHT TOOL: Use ripgrep for text
rg "TODO"
Generated code : LSP may not index auto-generated files
Very large codebases : Symbol indexing can be slow
Dynamic languages without types : Limited semantic info
Serena is designed for token-efficient code navigation :
# Traditional approach (inefficient)
execute_command("cat entire_file.py") # 1000+ tokens
# [Search for symbol manually in output]
# Serena approach (efficient)
serena find_symbol --name 'MyClass' # 50 tokens
# [Get precise location immediately]
Comparison with alternatives:
If find_symbol returns no results:
Verify symbol exists : Use ripgrep to confirm
rg "class MyClass" --type py
Check language server : Ensure LSP is configured for the language
serena status # Check LSP server status
Try case variations : Symbol names are case-sensitive
serena find_symbol --name 'myclass' # Try different cases
Rebuild index : Force LSP to re-index
serena reindex # Rebuild symbol index
If find_referencing_symbols returns hundreds of results:
Use file-search first : Narrow scope with ripgrep
rg "MyClass" src/services/ # Limit to specific directory
serena find_referencing_symbols --name 'MyClass' --path src/services/
Filter by reference type : Focus on specific usage patterns
# Look for imports only
rg "from .* import.*MyClass" --type py
Prioritize recent changes : Check git history first
git log --all -p -S 'MyClass' --since="1 week ago"
If insert_after_symbol fails:
Weekly Installs
82
Repository
GitHub Stars
891
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex70
opencode70
claude-code66
gemini-cli65
github-copilot61
cursor57
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
163,300 周安装
Kiro-Skill:规范驱动开发工作流 - 从想法到实现计划的AI辅助工具
165 周安装
Azure App Service 完全指南:Web应用、API、移动后端托管与最佳实践
164 周安装
Apple Intelligence 基础模型诊断指南:解决上下文超限、护栏违规、生成缓慢等问题
162 周安装
DNS管理指南:Route53、Azure DNS、CloudFlare配置与故障转移最佳实践
162 周安装
AWS MCP 服务器配置指南:为AI代理快速集成AWS工具与文档搜索
166 周安装
Docker平台指南:Windows/Linux/macOS差异、配置优化与最佳实践
70 周安装