Repository navigation
Description
title: "[Feature Request] Integrate Serena for Semantic Code Understanding"
labels: ["enhancement", "mcp", "semantic-search"]
Feature Request: Integrate Serena for Semantic Code Understanding
Summary
Add support for Serena - a powerful coding agent toolkit providing semantic code retrieval and editing capabilities via Language Server Protocol (LSP).
Background
Currently, OpenCode has excellent file-level search capabilities but lacks semantic code understanding. When I ask questions like:
- "Find all usages of this function"
- "Go to definition of this symbol"
- "Show me the class hierarchy"
- "Where is error handling for API calls?"
These require understanding code structure and relationships, not just text matching.
Serena provides IDE-like semantic capabilities:
- Symbol-level code understanding via LSP
- Find references across codebase
- Go to definition/declaration
- Precise code edits at symbol level
- Cross-language support
Why Serena?
- MCP Compatible: Serena works as MCP server - OpenCode already supports MCP
- Actively Maintained: 16.1K+ stars, active development
- Proven Technology: Used in production by teams building AI coding agents
- Token Efficient: Semantic retrieval reduces context needed vs grep/text search
- Framework Agnostic: Not tied to specific LLMs
Proposed Implementation
Option 1: MCP Server Integration (Recommended)
Add Serena as built-in MCP server in OpenCode:
// ~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"serena": {
"type": "local",
"command": "serena",
"args": ["mcp"],
"enabled": true
}
}
}Benefits:
- Users can enable/disable in config
- Leverages existing MCP infrastructure
- No breaking changes
Option 2: Direct Tool Integration
Add Serena as first-class OpenCode tool (similar to existing grep/ripgrep tools):
{
name: "serena_find_symbols",
description: "Find symbols and references using Serena LSP",
parameters: {
type: "object",
properties: {
query: { type: "string" },
language: { type: "string" }
}
}
}Option 3: Auto-Detection
Automatically detect and integrate Serena when:
serenabinary is in PATHserenaMCP server is available- Serena config exists in project
Use Cases
1. Semantic Code Search
User prompt: "Find all functions that handle user authentication"
Current behavior: Uses grep/ripgrep - matches text "authentication"
With Serena: Returns functions authenticateUser(), login(), verifyCredentials() with file locations and line numbers
2. Go to Definition
User prompt: "Show me the User schema definition"
Current behavior: Searches files for "User" and "schema"
With Serena: Jumps directly to User class/interface definition with import tree
3. Find References
User prompt: "Where is PaymentProcessor used?"
Current behavior: Text search for "PaymentProcessor"
With Serena: Returns list of all usages with context (imports, instantiations, method calls)
4. Cross-File Refactoring
User prompt: "Rename UserService to AccountService across all files"
Current behavior: Text search and replace (error-prone)
With Serena: Semantic rename across LSP-aware files (safely)
Technical Details
Serena Capabilities
From Serena README:
- Symbol search and navigation
- Cross-reference finding
- Semantic code retrieval
- Multi-language support (TypeScript, Python, Go, etc.)
- LSP-based editing primitives
Integration Effort
- MCP Path: Low (2-3 hours) - Serena has MCP support
- Direct Path: Medium (1-2 days) - Needs tool registration
- Auto-Detection: Medium (1 day) - Add detection logic
Alternatives Considered
- Keep using grep/ripgrep: Fast, but no semantic understanding
- Build custom LSP client: Higher effort, maintenance burden
- Use existing MCP servers: See below (directory-indexer, Codebase)
Related Issues
- Split off MCP configuration: Split off MCP server configuration from config.json #1998
- MCP server documentation: docs/mcp-servers
References
- Serena repo: https://github.com/oraios/serena
- Serena MCP integration: MCP server mode
- OpenCode MCP docs: https://opencode.ai/docs/mcp-servers/
Acceptance Criteria
- Serena can be added as MCP server in
opencode.json - OpenCode can call Serena tools (symbol search, go-to-definition)
- Documentation updated with Serena examples
- User feedback from beta testing
- Performance impact evaluated (should be minimal)
Questions for Maintainers
- Do you prefer MCP server integration or direct tool integration?
- Should Serena be opt-in or auto-detected?
- Are there concerns about adding another MCP server (token usage)?
Open these issues to discuss approach and implementation details!
Activity
github-actions commentedon Dec 27, 2025
This issue might be a duplicate or related to existing feature requests. Please check:
Feel free to ignore if none of these address your specific use case.
[-]---[/-][+]Feature Request: Integrate Serena for Semantic Code Understanding[/+]gytis-ivaskevicius commentedon Jan 6, 2026
Hi, can you elaborate how serena improves your workflow? Does it actually save tokens? I just wrote my mini review of this idea here #438 (comment)
layeddie commentedon Jan 7, 2026
One of the main objects of my local AI coding assistant project was to focus on using tools that would reduce token count and I asked opencode to review mgrep and serena. What prompted me was seranas LSP like features. LSP's are now the focus in AI coding tools now. I have builtin mgrep and serana to my project now but cant report on the benefits yet.
I just saw your comment in #438
Also, on Serena, I reached the same conclusion than you, it would only work if LSP edits are part of OpenCode core (which I think is in progress and available as experimental feature)
I dont know if you mean LSP's are part of OpenCode core or Serena are in progress?
At the moment OpenCode has already got very good LSP support builtin. As I tend to do now - I ask opencode to give me the answer. I am just asking it to review my use of mgrep, serana and ElixirLS... and the answer is....
**Final Recommendation
Your current configuration is optimal for reducing token count while maintaining idiomatic Elixir code quality. The three tools complement each other perfectly:
Minor optimization: Consider disabling OpenCode's built-in LSP when Serena is active to prevent conflicts, or use them selectively based on workflow.**
I am looking in to the suggestion.. I think using them selectively is the answer
gytis-ivaskevicius commentedon Jan 7, 2026
It's not my comment but close enough :D
So Serena states massive token savings which I was not able to reproduce even tho I basically got it almost perfectly integrated with custom system prompt. One of the issues is that LLMs strongly prefers using edit tool because that's what they are trained on
Few times I worked on a task and afterwards I asked LLM if Serena was worth it, it said no...
As for saving tokens, one of the conclusions I came to is that it's better to disable tools such as grep/glob and instead let it use bash. Minor improvement tho
thdxr commentedon Mar 25, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.