Skip to content

Feature Request: Integrate Serena for Semantic Code Understanding #6263

Closed as not planned

Description

@layeddie

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?

  1. MCP Compatible: Serena works as MCP server - OpenCode already supports MCP
  2. Actively Maintained: 16.1K+ stars, active development
  3. Proven Technology: Used in production by teams building AI coding agents
  4. Token Efficient: Semantic retrieval reduces context needed vs grep/text search
  5. 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:

  1. serena binary is in PATH
  2. serena MCP server is available
  3. 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

  1. Keep using grep/ripgrep: Fast, but no semantic understanding
  2. Build custom LSP client: Higher effort, maintenance burden
  3. Use existing MCP servers: See below (directory-indexer, Codebase)

Related Issues

References

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

  1. Do you prefer MCP server integration or direct tool integration?
  2. Should Serena be opt-in or auto-detected?
  3. Are there concerns about adding another MCP server (token usage)?

Open these issues to discuss approach and implementation details!

Activity

  1. github-actions commented on Dec 27, 2025

    @github-actions
    Contributor

    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.

  2. changed the title [-]---[/-] [+]Feature Request: Integrate Serena for Semantic Code Understanding[/+] on Dec 27, 2025
  3. gytis-ivaskevicius commented on Jan 6, 2026

    @gytis-ivaskevicius

    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)

  4. layeddie commented on Jan 7, 2026

    @layeddie
    Author

    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)

    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:

    1. mgrep → Semantic discovery (plan/review)
    2. Serena → Symbolic precision (build/review)
    3. Expert → Diagnostics and OTP best practices (all modes)
      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

  5. gytis-ivaskevicius commented on Jan 7, 2026

    @gytis-ivaskevicius

    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

  6. thdxr commented on Mar 25, 2026

    @thdxr
    Member

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions