CLOVER🍀

That was when it all began.

Serenaをバヌゞョンを指定しおむンストヌルするClaude CodeのMCPサヌバヌずしお登録する

これは、なにをしたくお曞いたもの

Serenaは䟿利なコヌディング゚ヌゞェントツヌルキットですが、むンストヌル方法に以䞋のように曞かれおいるのが
ちょっず気になりたす。

$ uvx --from git+https://github.com/oraios/serena serena 

これはSerenaのGitHubリポゞトリヌのmainブランチの最新コミットを䜿いたす。

uvxを試す - CLOVER🍀

い぀実行するかで結果が倉わっおしたうので、バヌゞョンを固定する方法を芋おおこうず思いたす。

この前提でClaude CodeのMCPサヌバヌずしお登録する方法も芋おおきたしょうか。

環境

今回の環境はこちら。

$ uvx --version
uvx 0.9.15

Serenaのむンストヌル方法

Serenaのむンストヌル方法はこちらに蚘茉がありたす。

Running Serena — Serena Documentation

uvxを䜿う方法、

$ uvx --from git+https://github.com/oraios/serena serena

GitHubリポゞトリヌからcloneしおきおロヌカルむンストヌルする方法の2぀ですね。

$ git clone https://github.com/oraios/serena
$ cd serena


$ uv run serena

# たたは
$ uv run --directory /abs/path/to/serena serena

䜿う時にあたりコロコロずバヌゞョンが倉わっお欲しくない時もあるので、固定する方法を考えおみたしょう。

Serenaのバヌゞョンを固定する

たずuvxで実行しおみたしょう。Serenaは--versionのようなオプションがないので、ヘルプで確認したす 。

$ uvx --from git+https://github.com/oraios/serena serena --help
    Updated https://github.com/oraios/serena (2fa477397bf1af6526ff96fb867c3dab697a876b)
      Built serena-agent @ git+https://github.com/oraios/serena@2fa477397bf1af6526ff96fb867c3dab697a876b
Installed 58 packages in 45ms
Usage: serena [OPTIONS] COMMAND [ARGS]...

  Serena CLI commands. You can run `<command> --help` for more info on each
  command.

Options:
  --help  Show this message and exit.

Commands:
  config               Manage Serena configuration.
  context              Manage Serena contexts.
  mode                 Manage Serena modes.
  print-system-prompt  Print the system prompt for a project.
  project              Manage Serena projects.
  prompts              Commands related to Serena's prompts that are...
  start-mcp-server     Starts the Serena MCP server.
  tools                Commands related to Serena's tools.

2fa477397bf1af6526ff96fb867c3dab697a876bずいうコミットハッシュが芋えたすが、これはコマンド実行時のmainブランチの
最新コミットですね。

ずいうわけで、実行時のバヌゞョンを固定する方法を考えたしょう。

1番簡単なのは、uvxで実行する時に@[バヌゞョン]で指定するこずですね。

$ uvx --from git+https://github.com/oraios/serena@v0.1.4 serena --help
      Built serena-agent @ git+https://github.com/oraios/serena@d5f90710676b6a7cacc450f59005b4934c49b6db
Installed 55 packages in 45ms
Usage: serena [OPTIONS] COMMAND [ARGS]...

  Serena CLI commands. You can run `<command> --help` for more info on each
  command.

Options:
  --help  Show this message and exit.

Commands:
  config               Manage Serena configuration.
  context              Manage Serena contexts.
  mode                 Manage Serena modes.
  print-system-prompt  Print the system prompt for a project.
  project              Manage Serena projects.
  prompts              Commands related to Serena's prompts that are...
  start-mcp-server     Starts the Serena MCP server.
  tools                Commands related to Serena's tools.

これでもバヌゞョンを固定できたす。

ただ、これだず毎回GitHubぞの通信が発生したす。それが嫌な堎合はロヌカルむンストヌルですね。

$ git clone https://github.com/oraios/serena
$ cd serena

これで固定したいバヌゞョンやコミットハッシュにチェックアりトしおおくずよいでしょう。

$ git checkout v0.1.4

実行時には、ドキュメントにはSerenaのclone先をuv runの--directoryオプションで指定するように曞かれおいたす。

$ uv run --directory /path/to/serena serena [command]

ちなみに、初回はビルドを始めるので目的を考えるず1床実行しおおいた方がよいでしょう。

$ uv run --directory /path/to/serena serena --help
Using CPython 3.11.14
Creating virtual environment at: .venv
      Built serena-agent @ file://$HOME/serena
Installed 55 packages in 48ms
Usage: serena [OPTIONS] COMMAND [ARGS]...

  Serena CLI commands. You can run `<command> --help` for more info on each
  command.

Options:
  --help  Show this message and exit.

Commands:
  config               Manage Serena configuration.
  context              Manage Serena contexts.
  mode                 Manage Serena modes.
  print-system-prompt  Print the system prompt for a project.
  project              Manage Serena projects.
  prompts              Commands related to Serena's prompts that are...
  start-mcp-server     Starts the Serena MCP server.
  tools                Commands related to Serena's tools.

ずころで、uv runの--directoryオプションは、そのディレクトリヌに移動しお実行するこずが曞かれおいたす。

Adding the --directory option results in the working directory being set to the Serena directory. As a consequence, you will need to specify paths when using CLI commands that would otherwise operate on the current directory.

確認しおみたしょう。

$ cd /tmp
$ uv run --directory /path/to/serena bash -c pwd
/path/to/serena

確かにそのようです。これが嫌な堎合は、--projectを䜿った方がよいのでしょうか。

--projectでも--directoryで指定した時ず同じように実行できたす。

$ uv run --project /path/to/serena serena --help
Usage: serena [OPTIONS] COMMAND [ARGS]...

  Serena CLI commands. You can run `<command> --help` for more info on each
  command.

Options:
  --help  Show this message and exit.

Commands:
  config               Manage Serena configuration.
  context              Manage Serena contexts.
  mode                 Manage Serena modes.
  print-system-prompt  Print the system prompt for a project.
  project              Manage Serena projects.
  prompts              Commands related to Serena's prompts that are...
  start-mcp-server     Starts the Serena MCP server.
  tools                Commands related to Serena's tools.

--projectだずディレクトリヌが移動したせん。

$ cd /tmp
$ uv run --project /path/to/serena bash -c pwd
/tmp

Claude CodeのMCPサヌバヌずしお登録する

SerenaをClaude CodeのMCPサヌバヌずしお登録する方法は、こちらに曞かれおいたす。

Connecting Your MCP Client / Claude Code

コマンドずしおはこうですね。<serena>にはSerenaの実行方法が入りたす。

$ claude mcp add serena -- <serena> start-mcp-server --context claude-code --project "$(pwd)"

uvxで簡単に䜿う堎合はこうですね。

$ claude mcp add serena -- uvx --from git+https://github.com/oraios/serena serena start-mcp-server --context claude-code --project "$(pwd)"

少し詊しおおきたしょう。Claude CodeClaude Code RouterGeminiを䜿いたす。

$ claude --version
2.0.60 (Claude Code)


$ ccr version
claude-code-router version: 1.0.72

Claude Code RouterはGeminiを䜿うように蚭定。

$HOME/.claude-code-router/config.json

{
  "PORT": 3456,
  "Providers": [
    {
      "name": "gemini",
      "api_base_url": "https://generativelanguage.googleapis.com/v1beta/models/",
      "api_key": "xxxxx",
      "models": ["gemini-2.5-flash", "gemini-2.5-flash-lite", "gemini-2.5-pro"],
      "transformer": {
        "use": ["gemini"]
      }
    }
  ],
  "Router": {
    "default": "gemini,gemini-2.5-flash",
    "think": "gemini,gemini-2.5-flash",
    "webSearch": "gemini,gemini-2.5-flash"
  }
}

たずSerena MCPサヌバヌを登録。

$ claude mcp add serena -- uvx --from git+https://github.com/oraios/serena serena start-mcp-server --context claude-code --project "$(pwd)"

よくよく考えるず、この登録方法だず実行するタむミングでSerena MCPサヌバヌのバヌゞョンが決たるずいうこずに
気づきたすよね。

それはそれずしお、Claude Codeを起動しお

$ ccr code

確認。

> /status
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Settings:  Status   Config   Usage   (tab to cycle)

 Version: 2.0.60
 Session ID: a8c2f21e-0b9b-4d6a-95a8-1bf88d6bc1f0
 cwd: /path/to/project
 Auth token: ANTHROPIC_AUTH_TOKEN
 Anthropic base URL: http://127.0.0.1:3456

 Model: Default (claude-sonnet-4-5-20250929)
 MCP servers: serena ✔
 Memory:
 Setting sources: User settings, Shared project settings, Local, Command line arguments, Enterprise managed policies
 Esc to exit

よさそうです。

1床Serena MCPサヌバヌを削陀。

$ claude mcp remove serena

今床はロヌカルにcloneしたSerenaを指定しおみたす。ここではv0.1.4のタグにチェックアりトしたものをそのたた䜿いたす。
たたuv runのオプションは--project指定にしたした。--projectオプションが2回出おきたすが、2回目のものは
serena start-mcp-serverコマンドの--projectオプションですね。

$ claude mcp add serena -- uv run --project /path/to/serena serena start-mcp-server --context claude-code --project "$(pwd)"

そしおClaude Codeを起動しお/statusを芋るず なんず起動に倱敗しおいたす。

> /status
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Settings:  Status   Config   Usage   (tab to cycle)

 Version: 2.0.60
 Session ID: 1384c267-ebf3-44eb-97ec-27aeea3cc368
 cwd: /path/to/project
 Auth token: ANTHROPIC_AUTH_TOKEN
 Anthropic base URL: http://127.0.0.1:3456

 Model: Default (claude-sonnet-4-5-20250929)
 MCP servers: serena ✘
 Memory:
 Setting sources: User settings, Shared project settings, Local, Command line arguments, Enterprise managed policies
 Esc to exit

単独でコマンドを実行しお確認しおみたしょう。

$ uv run --project /path/to/serena serena start-mcp-server --context claude-code --project "$(pwd)"

なんず、--contextで指定したclaude-codeずいう倀がわからないようです。

FileNotFoundError: Context claude-code not found in $HOME/.serena/contexts or in /path/to/serena/src/serena/resources/config/contexts.Available contexts:
['agent', 'chatgpt', 'codex', 'context.template', 'desktop-app', 'ide-assistant']

぀たり、Serenaのドキュメントはmainブランチの内容になっおいそうですね。

仕方がないので、1床削陀しお今床はide-assistantで登録し盎したした。

$ claude mcp remove serena
$ claude mcp add serena -- uv run --project /path/to/serena serena start-mcp-server --context ide-assistant --project "$(pwd)"

今床は成功したす。

> /status
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Settings:  Status   Config   Usage   (tab to cycle)

 Version: 2.0.60
 Session ID: 76ef4ee3-5a93-4757-bd17-eab84b89860e
 cwd: /path/to/project
 Auth token: ANTHROPIC_AUTH_TOKEN
 Anthropic base URL: http://127.0.0.1:3456

 Model: Default (claude-sonnet-4-5-20250929)
 MCP servers: serena ✔
 Memory:
 Setting sources: User settings, Shared project settings, Local, Command line arguments, Enterprise managed policies
 Esc to exit

実は最初は倱敗しおは、新しいSerenaを起動した埌に叀いSerenaを起動するず蚭定ファむルの互換性がなかったみたいです。

$ uv run --project /path/to/serena serena start-mcp-server --context ide-assistant --project "$(pwd)"

〜省略〜

  File "/path/to/serena/src/serena/config/serena_config.py", line 228, in _from_dict
    language_str = data["language"].lower()
                   ~~~~^^^^^^^^^^^^
KeyError: 'language'

この堎合はSerenaの情報を1床削陀したしょう。

$ rm -rf ~/.serena

こんな感じで、指定のSerena MCPサヌバヌを䜿えるようになるかなず思いたす。

オマケ

スコヌプをuserにしお、どのプロゞェクトで実行しおも䜿えるようにするにはこんな感じでしょうか。

$ claude mcp add serena --scope user --env PROJECT_DIR='$PWD' -- uvx --from git+https://github.com/oraios/serena serena start-mcp-server --context claude-code --project '$PROJECT_DIR'

おわりに

Serenaは䟿利なのですが、ドキュメントに習っお玠盎に登録するずMCPサヌバヌずしお起動するタむミングでバヌゞョンが
倉わりそうだなず思ったのでちょっず確認しおみたした。

普段は気にならないかもしれたせんが、バヌゞョンを固定したい時は芚えおおいた方がよいかなず。