Open13

ClaudeCode、CursorのMCPサーバー設定

keitaknkeitakn

概要

ClaudeCode、CursorのMCPサーバー設定メモ。
最初はGitHub MCP Serverを設定していく。

許可する操作

  • Gitコミット
  • GitHub上にリモートブランチの作成
  • GitHub上にPRの作成・編集
keitaknkeitakn

事前準備

PAT(Personal Access Token) の発行

https://github.com/settings/personal-access-tokens から発行を行う。

Fine-grained personal access tokens だとorgの範囲内でしか権限を付与する事が出来ないので、全体的に利用する場合は Personal access tokens (classic) を利用する。

スコープ(権限)選択だが最低限 repo があればOK。

GitHub Actionのワークフローを修正する場合は workflow も選択しておく。

インストール

npmでインストールしたり、ローカルにリポジトリを落としてServerを起動するなど色々な方法があるがHomebrewでインストールする方法が一番カンタンそうなので、それで進める。

インストールを実行。

brew install github-mcp-server
keitaknkeitakn

Cursorの場合

~/.cursor/mcp.json に以下を追加。

{
  "mcpServers": {
    "github": {
      "command": "github-mcp-server",
      "args": ["stdio", "--toolsets", "repos,issues,pull_requests"],
      "transport": "stdio",
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      }
    }
  }
}
keitaknkeitakn

デフォルトだと設定されているツールが多すぎるので repos,issues,pull_requests と利用するツールを絞っている。

利用可能なツールは以下の公式リポジトリREADMEを参照。
ちなみに自分が試した限りだと2025年6月22日現在 actions のツールは利用出来なかった。

https://github.com/github/github-mcp-server

keitaknkeitakn

Claude Codeの場合

以下を実行すると設定されます。

claude mcp add github \
  -s user \
  -e GITHUB_PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
  -- github-mcp-server stdio --toolsets repos,issues,pull_requests

自分の環境だと ~/.claude.json の一番最後の行にMCPの設定が追加されていた。

{
  // 省略
  "mcpServers": {
    "github": {
      "type": "stdio",
      "command": "github-mcp-server",
      "args": [
        "stdio",
        "--toolsets",
        "repos,issues,pull_requests"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      }
    }
  }
}

Claude Codeのバージョンによっては ~/.claude/settings.json に追加される可能性もあるかも。

余談だが将来的には ~/.claude/settings.json が標準になるっぽい。

https://docs.anthropic.com/en/docs/claude-code/settings

keitaknkeitakn

claude mcp list --verbose を実行するとMCPの設定を読み込める。

claude 起動中に /mcp を実行するとMCPServerにちゃんと接続出来ている事が確認可能。

╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code!                         │
│                                                   │
│   /help for help, /status for your current setup  │
│                                                   │
│   cwd: /Users/keita/◯◯          │
╰───────────────────────────────────────────────────╯


 ※ Tip: Did you know you can drag and drop image files into your terminal?
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Manage MCP servers                                                                                                                                               │
│                                                                                                                                                                  │
│ ❯ 1. github  ✔ connected · Enter to view details                                                                                                                 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
   Esc to exit
keitaknkeitakn

Serena(Claude Codeのみ、多分Cursorでも使える)

LLMに高度なコード解析機能やコード編集機能を付与するオープンソースのツール。

https://github.com/oraios/serena

何が出来るか?

  • Claude Codeが定義ジャンプ・参照検索・補完 など IDE 相当のシンボル操作が出来るようになるので、より確実なリファクタリングが出来る
  • プロジェクト全体インデックス化する事で大規模コードベースでも高速な検索が可能になる

要するにコーディングエージェントにIDEを使ってもらえるようになるとう理解で良さそう。

対応言語はこちらに記載あり、とりあえず自分がよく書いているTypeScriptとPythonは問題なく利用可能。

https://github.com/oraios/serena?tab=readme-ov-file#programming-language-support--semantic-analysis-capabilities

高性能なコード解析ツールが手に入る事でClaudeCodeの料金を節約しさらにタスクの消化スピードを高速化する事が期待出来る。

事前準備

uv のインストール

自分は最近PythonかTypeScriptのプロジェクトが多いので既にインストール済だがインストールされていない場合は以下でインストール。

brew install uv

導入

以下を実行。

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

ちなみにこの手順だとMCP起動時にGitHubの最新のソースコードを取ってきてMCPサーバーがローカル上で起動するようになるので、セキュリティ面が気になる場合はローカルにgit cloneしてサーバーを起動する形でも問題はない。

MCPサーバーが起動するとブラウザで http://127.0.0.1:24282/dashboard/index.html が起動されて以下のようなログが確認出来る。

claude を起動して以下を実行。

以下を実行してSerena の初期インストラクションを読み込む。

/mcp__serena__initial_instructions

利用したいプロジェクトで claude を起動した状態で以下を実行。

/mcp__serena__activate_project

これによって .serena/project.yml が作成され、コードの解析などが行われ利用出来る状態になる。

# language of the project (csharp, python, rust, java, typescript, go, cpp, or ruby)
#  * For C, use cpp
#  * For JavaScript, use typescript
# Special requirements:
#  * csharp: Requires the presence of a .sln file in the project folder.
language: python

# whether to use the project's gitignore file to ignore files
# Added on 2025-04-07
ignore_all_files_in_gitignore: true
# list of additional paths to ignore
# same syntax as gitignore, so you can use * and **
# Was previously called `ignored_dirs`, please update your config if you are using that.
# Added (renamed)on 2025-04-07
ignored_paths: []

# whether the project is in read-only mode
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
# Added on 2025-04-18
read_only: false


# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
# Below is the complete list of tools for convenience.
# To make sure you have the latest list of tools, and to view their descriptions, 
# execute `uv run scripts/print_tool_overview.py`.
#
#  * `activate_project`: Activates a project by name.
#  * `check_onboarding_performed`: Checks whether project onboarding was already performed.
#  * `create_text_file`: Creates/overwrites a file in the project directory.
#  * `delete_lines`: Deletes a range of lines within a file.
#  * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
#  * `execute_shell_command`: Executes a shell command.
#  * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
#  * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
#  * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
#  * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
#  * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file or directory.
#  * `initial_instructions`: Gets the initial instructions for the current project.
#     Should only be used in settings where the system prompt cannot be set,
#     e.g. in clients you have no control over, like Claude Desktop.
#  * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
#  * `insert_at_line`: Inserts content at a given line in a file.
#  * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
#  * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
#  * `list_memories`: Lists memories in Serena's project-specific memory store.
#  * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
#  * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
#  * `read_file`: Reads a file within the project directory.
#  * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
#  * `remove_project`: Removes a project from the Serena configuration.
#  * `replace_lines`: Replaces a range of lines within a file with new content.
#  * `replace_symbol_body`: Replaces the full definition of a symbol.
#  * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
#  * `search_for_pattern`: Performs a search for a pattern in the project.
#  * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
#  * `switch_modes`: Activates modes by providing a list of their names
#  * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
#  * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
#  * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
#  * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
excluded_tools: []

# initial prompt for the project. It will always be given to the LLM upon activating the project
# (contrary to the memories, which are loaded on demand).
initial_prompt: ""

project_name: "GitHubのリポジトリ名などのプロジェクト名が自動で入ってくる"

他にも .serena/memories/tech_stack.md のようなファイルが生成されプロジェクトの構造がserenaによって理解しやすい形になる。

# 技術スタック

## コア技術
- **Python**: 3.13.3
- **uvicorn**: 0.35.0 (ASGIサーバー)

## フレームワーク
- **FastAPI**: 0.116.1 (Webフレームワーク)
- **SQLAlchemy**: 2.0.41 (ORM)
- **fastapi-mcp**: 0.3.7 (MCP統合)
- **Pydantic**: FastAPIに含まれる (データバリデーション)

## 認証・外部サービス
- **Firebase Admin**: 7.0.0 (認証)
- **Google GenAI**: 1.26.0 (AI機能)
- **OpenAI**: 1.97.0

## データベース関連
- **asyncmy**: 0.2.10 (非同期MySQL)
- **asyncpg**: 0.30.0 (非同期PostgreSQL)

## 開発ツール
- **uv**: 0.6.14 (パッケージマネージャー)
- **ruff**: 0.12.4 (Linter/Formatter)
- **pyright**: 1.1.403 (型チェッカー)
- **pytest**: 8.4.1 (テストフレームワーク)
- **pytest-asyncio**: 1.1.0
- **pytest-xdist**: 3.8.0 (並列実行)
keitaknkeitakn

設定ファイルのGit管理について

自分の場合は .serena/project.yml のみコミットするようにして .serena/memories/ のマークダウンファイルなどはコミットしないようにしている。

理由はここには技術スタックなどの情報だけでなく /mcp__serena__prepare_for_new_conversation などのコマンドで要約されたClaude Codeとの会話の内容などが記録される事もあるので個人の管理にとどめたほうが良いと判断した。

.serena/cache/ は当然Cacheなのでコミットしないほうが良い。

自分の場合は .gitignore に以下を追加している。

.serena/memories/
.serena/cache/
.serena/index/
.serena/logs/
.serena/dashboard/

keitaknkeitakn

注意点

ClaudeCodeの会話をリセットした後は claude を立ち上げた直後に必ず以下を再実行する。

/mcp__serena__initial_instructions

こうしないとClaude Codeが上手くserenaのMCPを使ってくれない。

この点に関してはREADMEにも記載されている。

https://github.com/oraios/serena

ℹ️ Serena comes with an instruction text, and Claude needs to read it to properly use Serena's tools. Once in Claude Code, you can ask to "read Serena's initial instructions" or run /mcp__serena__initial_instructions to load the instruction text. Do this whenever you start a new conversation and after any compacting operation to ensure Claude remains properly configured to use Serena's tools.

一応以下のように claude を起動すれば上記の実行は必要ないらしいが、まだ出来たばかりの機能でちゃんと動作確認が取れていない部分もあるらしいのでしばらくは上記のコマンドを実行するようにすると良い。

claude --append-system-prompt $(uvx --from git+https://github.com/oraios/serena serena print-system-prompt)
keitaknkeitakn

2025-08-18 追記

会話リセットのたびに /mcp__serena__initial_instructions を実行する必要がなくなった模様。

https://github.com/oraios/serena

ただしClaude Codeのバージョンが v1.0.52 以上であることが条件。

これでより快適に利用出来るようになった。

keitaknkeitakn

2025-08-19

導入時のコマンドが微妙に変わっていました。

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

Context7(Claude CodeのみCursorでも使えるハズ)

upstash が開発したドキュメントをLLMが解析しやすい形で提供してくれるMCPサーバー。

https://github.com/upstash/context7

実際に提供されているドキュメントは以下のページから確認出来る。

https://context7.com

一通り確認しましたがTypeScript、Pythonだと主要なライブラリは一通り揃っていそうだった。

導入手順(Claude Code)

以下に記載されている Install in Claude Code の手順に従うだけ。

https://github.com/upstash/context7

導入したいプロジェクトの配下で以下を実行。

claude mcp add --transport http context7 https://mcp.context7.com/mcp

claude を起動して /mcp を実行すると無事Context7のMCPが利用出来る状態になっている。

使い方

非常にシンプルで公式ドキュメントに記載してある通りプロンプトで use context7 を含めるだけ。

Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to `/login`. use context7

もちろん日本語でも問題なく例えば以下のように質問するとちゃんとContext7を使ってHeroUIのドキュメントを参照して答えてくれる。

context7 を使って  @src/components/Providers.tsx 内の HeroUIProvider の使い方が正しいかどうかを調べて欲しいです。

keitaknkeitakn

Playwright MCP(Claude CodeのみCursorでも使えるハズ)

トークン消費量が多いのが難点だが実際にブラウザを操作して動作確認が出来るようになるので地味に便利。

全プロジェクトで使えるようにする場合

claude mcp add playwright --scope user -- npx @playwright/mcp@latest

指定したプロジェクトにだけ使えるようにする場合

claude mcp add playwright --scope project -- npx @playwright/mcp@latest