iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐥

Understanding Serena: A Quick Overview

に公開

My company recently provided all engineers with access to the Max plan for Claude Code. I'm so grateful for this! As part of my efforts to improve how I use Claude Code, I decided to install Serena myself.

However, even after installing it, I was left wondering: "What does Serena actually do?" In this article, I will try to organize my findings.

What is Serena MCP?

Serena is an open-source MCP server developed by Oraios AI.

First, let's look at the official documentation's description:

  • 🚀 Serena is a powerful coding agent toolkit that turns LLMs into full-featured agents that operate directly on your codebase. Unlike most other tools, it is not tied to a specific LLM, framework, or interface, making it easy to use in various ways.

  • 🔧 Serena provides essential semantic code search and editing tools similar to IDE features. It extracts code entities at the symbol level and leverages relational structures. By combining these with existing coding agents, these tools significantly improve (token) efficiency.

Semantic code search? Symbol level? Well, it sounds like a powerful coding agent toolkit... This description was a bit abstract for me, so I'll explain it based on my own interpretation to show why it's useful.
*For installation instructions, please refer to the official documentation or other articles written by fellow developers! (Serena Official Documentation)

Understanding code by "Symbols" instead of text

Normally, LLMs read code as just text (a blob of characters). Just like a human reading a sentence, it follows the characters from top to bottom. However, in programming, the structure is more important than the text itself.

  • Where is function getUser() defined?
  • What properties does the User class have?
  • Where is this variable referenced?

To understand these "structural connections," you need to grasp the code at the symbol level rather than the text level.

What is LSP (Language Server Protocol)?

Serena utilizes the LSP (Language Server Protocol) mechanism. This is the same underlying technology that enables the "Go to Definition," "Rename Symbol," and "Code Completion" features we benefit from in editors like VSCode.

Serena uses the power of LSP to analyze code not as mere strings, but as meaningful units (symbols), such as "Function A calls Class B, and its return value is C."

In short, it seems that "giving the LLM an IDE-like map" is equivalent to "performing understanding at the symbol level."

What is Semantic Code Search?

Next, let's talk about "semantic code search."

Searching with Claude Code without Serena is essentially a text search (grep search), which checks whether keywords match. For example, if you want to search for "save" code, it won't hit if there are no comments or function names containing "save" in the source code. It won't find it if it's written as "persist" or "commit."

On the other hand, semantic search vectorizes the meaning and context of words to perform searches. (Very impressive!)
Because of this, if you search for "I want to know about data saving processes," it can find semantically related code like PersistenceManager or commitTransaction, even if those exact words are not included.

The benefits of Serena

Serena possesses both this "symbol-level structural understanding (LSP)" and "semantic search" capability.

It doesn't just look for code that "looks right"; it understands the connections within the code—such as "the definition of this function is here, and it's used over there"—and can pass that information to the LLM.

The effects of Serena include:

  1. Improved accuracy in project understanding.
  2. Significant reduction in token consumption.
  3. (Since the understanding accuracy is improved, the LLM's response time might also become faster, perhaps...)

Having actually introduced Serena, I can feel the reduction in Claude Code's token consumption. As the scale of a project grows, the amount of context that needs to be fed to the AI tends to become massive. By using Serena, you can extract only the information you need, right when you need it, avoiding unnecessary token consumption.
It's free to use, so I highly recommend giving it a try! 🙌

Discussion