Merge pull request #1287 from oraios/serena_init_cmd

Serena init cmd
This commit is contained in:
Michael Panchenko authored and GitHub committed 2026-04-06 20:28:25 +02:00
commit 33a246ab66
6 files changed
+54 -38

No files matched your search

+3
View File
@@ -2,6 +2,9 @@
Status of the `main` branch. Changes prior to the next official version change will appear here.
* General:
- Added `serena init` command
* Dashboard:
- Add version display
+12 -10
View File
@@ -178,24 +178,26 @@ https://github.com/user-attachments/assets/6eaa9aa1-610d-4723-a2d6-bf1e487ba753
**Prerequisites**. Serena is managed by *uv*. If you don’t already have it, you need to [install uv](https://docs.astral.sh/uv/getting-started/installation/) before proceeding.
> [!NOTE]
> When using the language server backend, some additional dependencies to be installed for certain languages; see the [Language Support](https://oraios.github.io/serena/01-about/020_programming-languages.html) page for details.
**Starting the MCP Server**. The easiest way to start the Serena MCP server is by running the latest version from GitHub using uvx:
**Initialize Serena**. To initialize Serena, simply run:
```bash
uvx -p 3.13 --from git+https://github.com/oraios/serena serena start-mcp-server
uvx -p 3.13 --from git+https://github.com/oraios/serena serena init
```
If this is the first time you are starting Serena, the necessary configuration files will be created, and
you should see the Serena dashboard appear. You can terminate the server by pressing Ctrl+C (multiple times, if necessary).
This will create the global configuration file `~/.serena/config.yaml`.
The default code intelligence backend for Serena is the free LSP backend. You can add `-b JetBrains` to the `init` command
to set up the JetBrains as the default code intelligence backend instead, see [JetBrains Plugin page](https://oraios.github.io/serena/02-usage/025_jetbrains_plugin.html) for more details.
> [!NOTE]
> When using the language server backend, some additional dependencies to be installed for certain languages;
> see the [Language Support](https://oraios.github.io/serena/01-about/020_programming-languages.html) page for details.
**Configuring Your Client**. To connect Serena to your preferred MCP client, you typically need to [configure a launch command in your client](https://oraios.github.io/serena/02-usage/030_clients.html).
Follow the link for specific instructions on how to set up Serena for Claude Code, Codex, Claude Desktop, MCP-enabled IDEs and other clients (such as local and web-based GUIs).
**Switching to the JetBrains Backend**. The default code intelligence backend for Serena is the free LSP backend.
For using the more powerful JetBrains backend, follow the instructions on the [JetBrains Plugin page](https://oraios.github.io/serena/02-usage/025_jetbrains_plugin.html).
> [!TIP]
> While getting started quickly is easy, Serena is a powerful toolkit with many configuration options.
> We highly recommend reading through the [user guide](https://oraios.github.io/serena/02-usage/000_intro.html) to get the most out of Serena.
+6 -8
View File
@@ -65,24 +65,22 @@ After installing the plugin, you need to configure Serena to use it.
**Central Configuration**.
If you ever executed Serena before, you will have the global Serena configuration file located at `~/.serena/serena_config.yml`
(`%USERPROFILE%\.serena\serena_config.yml` on Windows).
If the configuration file does not exist, run
You can run
```shell
uvx -p 3.13 --from git+https://github.com/oraios/serena serena start-mcp-server
uvx -p 3.13 --from git+https://github.com/oraios/serena serena init -b JetBrains
```
(see [running Serena](020_running.md) for alternative options) to install all dependencies and create configuration files. Terminate the server with `Ctrl+C` after it has started.
to set the default code intelligence backend to JetBrains in the global Serena configuration file.
In your configuration, change the `language_backend` setting as follows:
Alternatively, you can also manually edit the configuration file `~/.serena/serena_config.yml`
(`%USERPROFILE%\.serena\serena_config.yml` on Windows) and set
```yaml
language_backend: JetBrains
```
*Note*: you can also use the button `Edit Global Serena Config` in the Serena MCP dashboard to open the config file in your default editor.
Note that the file might not exist yet if you never executed Serena before.
**Per-Instance Configuration**.
The configuration setting in the global config file can be overridden on a
-2
View File
@@ -61,8 +61,6 @@ explicit = true
[project.scripts]
serena = "serena.cli:top_level"
serena-mcp-server = "serena.cli:start_mcp_server"
index-project = "serena.cli:index_project" # deprecated
[project.license]
text = "MIT"
+2 -2
View File
@@ -1,4 +1,4 @@
from serena.cli import start_mcp_server
from serena.cli import top_level
if __name__ == "__main__":
start_mcp_server()
top_level.start_mcp_server()
+31 -16
View File
@@ -45,7 +45,7 @@ from solidlsp.util.subprocess_util import subprocess_kwargs
log = logging.getLogger(__name__)
_MAX_CONTENT_WIDTH = 100
_MAX_CONTENT_WIDTH = 200
_MODES_EXPLANATION = f"""\b\nBuilt-in mode names or paths to custom mode YAMLs with which to
override the default modes defined in the global Serena configuration or
the active project.
@@ -155,6 +155,28 @@ class TopLevelCommands(AutoRegisteringGroup):
def __init__(self) -> None:
super().__init__(name="serena", help="Serena CLI commands. You can run `<command> --help` for more info on each command.")
@staticmethod
@click.command(
"init",
help="Initialize Serena by creating a global config file with the specified default language backend.",
context_settings={"max_content_width": _MAX_CONTENT_WIDTH},
)
@click.option(
"--language-backend",
"-b",
type=click.Choice([b.value for b in LanguageBackend]),
default=LanguageBackend.LSP.value,
show_default=True,
help="Default code intelligence backend (can be overridden in the project config).",
)
def init(language_backend: Literal["LSP", "JetBrains"] = "LSP"):
serena_config = SerenaConfig.from_config_file()
serena_config.language_backend = LanguageBackend(language_backend)
serena_config.save()
click.echo(
f"Initialized Serena with default backend: {language_backend}.\nFind the global Serena config in:\n {serena_config.config_file_path}"
)
@staticmethod
@click.command("start-mcp-server", help="Starts the Serena MCP server.", context_settings={"max_content_width": _MAX_CONTENT_WIDTH})
@click.option("--project", "project", type=PROJECT_TYPE, default=None, help="Path or name of project to activate at startup.")
@@ -1109,23 +1131,16 @@ class PromptCommands(AutoRegisteringGroup):
click.echo(f"Deleted override file '{prompt_yaml_name}'.")
# Expose groups so we can reference them in pyproject.toml
mode = ModeCommands()
context = ContextCommands()
project = ProjectCommands()
config = SerenaConfigCommands()
tools = ToolCommands()
prompts = PromptCommands()
_mode = ModeCommands()
_context = ContextCommands()
_project = ProjectCommands()
_config = SerenaConfigCommands()
_tools = ToolCommands()
_prompts = PromptCommands()
# Expose toplevel commands for the same reason
# Expose so we can use this as an entrypoint
top_level = TopLevelCommands()
start_mcp_server = top_level.start_mcp_server
# needed for the help script to work - register all subcommands to the top-level group
for subgroup in (mode, context, project, config, tools, prompts):
for subgroup in (_mode, _context, _project, _config, _tools, _prompts):
top_level.add_command(subgroup)
def get_help() -> str:
"""Retrieve the help text for the top-level Serena CLI."""
return top_level.get_help(click.Context(top_level, info_name="serena"))