Serena MCPでローカルAIコーディング環境を組み直す構想
Serena MCPを中心にObsidianからVSCodeまでを繋ぐローカルAIコーディング基盤の構想と、拡張方向の整理。
はじめに
開発環境を見直すにあたって、今回はSerena MCPを中心に据えたローカルAIコーディング基盤を考えた。狙いは単にローカルLLMを動かすことではなく、Obsidianで書いた指示をそのまま開発コンテキストとして扱い、GitHub CopilotやVS Code上の補完、エージェント実行までつなげることだった。
いま欲しかったのは、クラウド前提の巨大な仕組みではなく、ローカルマシン上で閉じつつ、リポジトリ固有の知識を反映できる実用的な支援環境だった。補完の精度が上がること、hallucinationが減ること、コードが外へ出ないこと、この三つを同時に満たしたかった。
背景・目的
手元のノートには次の意図がはっきり書かれていた。
- serena MCPでlocal LLM、github copilotの精度を向上させる
- obsidianをベースにserenaでinstructionsを生成、ローカルLLMもしくはGithub copilotをベースにしてオートコンプリート、エージェントを活用できるようにローカルマシンに構築する。VSCODEでも利用する
つまり、単体のLLM運用ではなく、ノート、補完、実行、エディタを一つの流れでつなげたいという話だった。Obsidianに残したメモを単なる文章で終わらせず、実際の開発アクションに変換したい。そこにSerena MCPを挟むことで、ローカルLLMかGitHub Copilotを使うにしても、リポジトリ文脈に沿った支援へ寄せていく。
Serena MCP: ローカルLLMとGitHub Copilotの精度向上
このメモで一番中核になっているのは、Serena MCPを「精度向上のための補助エンジン」として使う考え方だった。local LLMを単独で投げるのではなく、repositoryのcode、comments、documentationを読み込ませてproject-specificな文脈へ寄せる。
対象モデルとして Qwen-Coder-v3、Gemma-3、Ollama-hosted modelが挙がっていた。ここは特定モデルに固定するというより、ローカルで回せるモデル群を差し替え可能にしながらSerena MCPで文脈を補う設計として読める。
Key Features
| Feature | What It Does | Practical Example |
|---|---|---|
| Local LLM Fine-Tuning | Trains a model on your repository’s code, comments, and documentation. | A Python project with 10k lines of code gets a model that understands project-specific naming conventions. |
| GitHub Copilot Accuracy Boost | Uses the fine-tuned model as a secondary suggestion engine, filtering Copilot’s output. | Copilot suggests a generic def foo(): but Serena MCP replaces it with def calculate_total_price(items): after matching repository patterns. |
| Obsidian-Based Instruction Generation | Generates Markdown instructions that guide the LLM or Copilot. | An Obsidian note titled “Add unit tests” automatically creates a prompt: “Write pytest tests for calculate_total_price.” |
| Auto-Complete & Agent Integration | Provides context-aware auto-completion and a lightweight agent that can execute code snippets. | While typing in VS Code, Serena MCP completes df. to df.groupby() based on pandas usage in the repo. |
| VS Code Extension | Installs a side-panel that displays Serena-generated instructions and suggestions. | A developer sees a “Suggested refactor” button that, when clicked, runs the agent to rename variables. |
この中で特に重要なのは、Obsidian-Based Instruction GenerationとAuto-Complete & Agent Integrationが同居している点だった。計画を書く場所と、コードを書く場所と、実行する場所が分断されていない。
How It Works
Serena MCPの流れは5段階で説明できる。
Repository Analysis: Serena MCPがリポジトリを走査し、コード、コメント、ドキュメントを抽出。関数シグネチャ、クラス階層、共通パターンを捉えたナレッジグラフを構築する。
Fine-Tuning: 抽出データを使って選択したローカルLLMをfine-tuneする。例えばQwen-Coder-v3に対して16GB GPUで4エポックの学習を行い、プロジェクトのテストセットでperplexityを35から22に改善する。
Instruction Generation: Obsidianでユーザーが高レベルの目標を書く: “Implement pagination for the API.” Serena MCPがこれを詳細なプロンプトに変換する:
## Task: Add pagination to the API endpoint `/items` - Use FastAPI - Return 20 items per page - Include `next_page` and `prev_page` linksAuto-Complete & Agent: 開発者がエンドポイント関数内で
returnと打つと、Serena MCPのオートコンプリートがreturn paginate_items(items, page, per_page=20)を提案する。エージェントはテストハーネスも実行できる:$ serena agent run tests/test_pagination.py PASSVS Code Integration: Serena拡張がサイドバーに表示: 現在のinstructionセット、提案コードスニペット、エージェント実行ステータス、ローカルLLMの推論APIへのクイックアクセス。
この構成の良さは、Obsidianのメモが単なる人間向けの文章で終わらないところにある。高レベルの指示をsource of truthにして、それを細かいpromptやエージェント実行に落とし込む。
Benefits
| Benefit | Why It Matters |
|---|---|
| Higher Accuracy | Fine-tuned models reduce irrelevant suggestions by 30-40% compared to vanilla Copilot. |
| Privacy | All inference happens locally; no code leaves the machine. |
| Speed | Local inference delivers sub-second responses, even on modest hardware. |
| Customizability | Users can swap LLMs (Qwen-Coder-v3, Gemma-3, Ollama) without changing the workflow. |
| Unified Interface | Obsidian for planning, VS Code for coding, Serena for execution – all in one ecosystem. |
自分にとって特に大きいのはPrivacyとUnified Interfaceの二つだった。コードを外へ出さずに済むことはもちろん重要だが、それと同じくらい、計画と実装がばらけないことが効く。
Getting Started
# 1. Install Serena MCP
pip install serena-mcp
# 2. Initialize your project
serena init
# 3. Choose an LLM
serena llm install qwen-coder-v3
# 4. Fine-tune
serena llm fine-tune
# 5. Install VS Code extension
code --install-extension serena.mcp
# 6. Open Obsidian, create an instruction note, and sync
関連メモから見える拡張方向
関連ファイルを重ねると、この構想は単なるeditor pluginの話では終わらない。
- 再現性と証跡: MLflow、SBOM、署名、Feastを組み合わせれば、生成支援込みの開発でも再現性と監査性を持たせやすい
- データ基盤と検索基盤: Trino、Iceberg、lakeFS/Nessie/Polaris、Qdrant、pgvectorを含めたベクター検索とデータ版管理
- 観測と運用: Prometheus/Grafana/LokiとOpenTelemetryによるresponse time、失敗率、instructionの有効性の可視化
- 実行基盤: Podman Quadletsを現実解、k3sを将来拡張案とした段階的なコンテナ運用
- 開発生産性: Devcontainer、pre-commit、Devbox/Nix flakes、Playwright/k6による再現可能な開発環境
いまの構想で足りていない点
方向性はかなり良いが、まだ埋めるべき点は残っている。
まず、概念と例示が中心で、実際の設定ファイルがない。Serena MCPのconfig、Obsidianノートをどう検知するか、VS Code側でどうinstructionを読み込むか、その具体がないと再現手順としては弱い。
次に、最小構成と拡張構成がまだ一つに混ざっている。自分なら次の二層に分ける。
- 最小構成: Serena MCP + local LLM + Obsidian + VS Code
- 拡張構成: Podman / MLflow / Trino / Iceberg / Qdrant / Observabilityを含む統合基盤
結果
今回のメモから見えたのは、Serena MCPを中心にすると、Obsidianで書いた意図をそのままローカルAIコーディングに接続できる、ということだった。単独のチャットUIではなく、repository analysis、fine-tuning、instruction generation、auto-complete、agent execution、VS Code integrationを一つの連続した流れとして扱えるのが強い。
今後の作業
次にやるべきことは、まず最小構成を固定することだと思う。Serena MCPの設定、Obsidianからinstructionを生成するルール、VS Code側の読み込み方法を小さく実装して、ローカルLLMとGitHub Copilotのどちらでどう使うかを切り分ける。
そのあとで、必要なものだけをPodman、MLflow、Qdrant、Observability側へ広げるほうがいい。最初から全部載せにすると重くなるが、最小構成で手応えがあれば、関連メモにある開発基盤案へ自然に接続できる。
