setup-serena-mcp
Creates or updates .mcp.json in the current project directory to configure the serena MCP server for Claude Code. Invoke only when the user explicitly runs the `/setup-serena-mcp` slash command — do not trigger on general phrases like "set up serena" or "add an MCP server" unless that exact slash command is used.
setup-serena-mcp
Configures the serena MCP server for the current project
by writing (or updating) .mcp.json in the current working directory.
Invocation mechanism
Use uvx --from git+https://github.com/oraios/serena so serena runs in an isolated,
auto-fetched environment. This means the user doesn't need to pre-install serena or keep
a global install in sync — uvx handles caching and resolution. The only prerequisite is
uv on PATH (install via curl -LsSf https://astral.sh/uv/install.sh | sh on Unix).
Why these flags matter
serena runs correctly under Claude Code with both:
--context claude-code— tunes serena's tool descriptions and reminders for Claude Code. The default context is generic and drops some Claude Code-specific behavior that the serena maintainers ship for this client.--project <path>— serena does not auto-detect the project root; without it, serena either refuses to start or operates on the wrong directory.
Config to write
Wrap the launch in sh -c so $PWD expands to the project root at process-launch time
rather than hardcoding an absolute path. This keeps .mcp.json portable — it survives
the project being moved, renamed, or cloned to a different location, and it works for
every teammate who checks out the repo.
The serena entry to add:
"serena": {
"type": "stdio",
"command": "sh",
"args": [
"-c",
"uvx --from git+https://github.com/oraios/serena serena start-mcp-server --context claude-code --project \"$PWD\""
]
}
Steps
-
Check whether
.mcp.jsonalready exists in the current directory.- If it exists: read and parse it. If the top-level shape is not
{"mcpServers": {...}}, stop and ask the user before overwriting — a different shape likely means the file is managed by a tool you don't want to stomp on. - If not: start from
{"mcpServers": {}}.
- If it exists: read and parse it. If the top-level shape is not
-
Set
mcpServers["serena"]to the entry above. Preserve all othermcpServersentries. If aserenaentry already exists, overwrite it and note the overwrite to the user. -
Write the result back to
.mcp.jsonwith 2-space indentation and a trailing newline. -
Tell the user:
- Whether
.mcp.jsonwas created fresh or updated, and whether an existingserenaentry was overwritten. - To restart their Claude Code session for the change to take effect.
- That
uvmust be on PATH for serena to launch. If they don't have it:curl -LsSf https://astral.sh/uv/install.sh | sh. - That the first launch will be slow while
uvxfetches and caches serena from git; subsequent launches are fast.
- Whether
Notes
$PWDis evaluated when Claude Code launches the MCP server process, which inherits the working directory from the terminal. Launchclaudefrom the project root so the path resolves correctly.- This is a project-level config — it only affects sessions opened in this directory.
Commit
.mcp.jsonto the repo if you want teammates to share the setup. - If there is also a global
serenaentry in~/.claude.json(e.g. fromclaude mcp add --scope user serena ...), the project-level entry takes precedence for sessions opened here, but the two configs can drift. If the user reports unexpected behavior, suggest:claude mcp remove --scope user serena. - To pin a specific serena version instead of tracking
main, change the--fromtarget togit+https://github.com/oraios/serena@<tag-or-sha>.