はじめに

Serena MCP を使い、Obsidian の指示をローカルLLMや GitHub Copilot の補完・エージェント実行につなぐ構成を考えました。VS Code で使う開発支援の案です。

目標は、リポジトリの知識を使って補完を改善し、hallucination を減らし、コードを外へ出さずに使えることです。ここでは構想と例を整理しています。

背景・目的

元のメモには、次の目的を書いていました。

  • serena MCPでlocal LLM、github copilotの精度を向上させる
  • obsidianをベースにserenaでinstructionsを生成、ローカルLLMもしくはGithub copilotをベースにしてオートコンプリート、エージェントを活用できるようにローカルマシンに構築する。VSCODEでも利用する

Obsidian で書いた指示を、リポジトリの文脈とともに補完と実行へ渡す流れを考えています。ローカルLLMと GitHub Copilot の両方を対象にしています。

Serena MCP: ローカルLLMとGitHub Copilotの精度向上

Serena MCP でコード、コメント、ドキュメントを読み、プロジェクトに合う文脈をモデルへ渡す案です。

候補は Qwen-Coder-v3、Gemma-3、Ollama で動かすモデルです。特定のモデルに固定せず、差し替えられる構成を考えています。

Key Features

FeatureWhat It DoesPractical Example
Local LLM Fine-TuningTrains 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 BoostUses 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 GenerationGenerates 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 IntegrationProvides 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 ExtensionInstalls 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

想定する処理は5段階です。以下の学習値や実行例は構想の例示で、測定結果ではありません。

  1. Repository Analysis:コード、コメント、ドキュメントを走査し、関数シグネチャ、クラス階層、共通パターンをナレッジグラフにします。

  2. Fine-Tuning:抽出データでローカルLLMを学習します。メモでは、Qwen-Coder-v3 を16GB GPUで4エポック学習し、テストセットの perplexity を35から22へ改善する例を置いています。

  3. 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` links
      
  4. Auto-Complete & Agent: 開発者がエンドポイント関数内で return と打つと、Serena MCPのオートコンプリートが return paginate_items(items, page, per_page=20) を提案する。エージェントはテストハーネスも実行できる:

      $ serena agent run tests/test_pagination.py
    PASS
      
  5. VS Code Integration:サイドバーに instruction、コード候補、エージェントの状態、ローカルLLMの推論APIへのアクセスを表示します。

Obsidian の高レベルの指示を基準に、個別の prompt とエージェントの処理へ分ける構成です。

Benefits

BenefitWhy It Matters
Higher AccuracyFine-tuned models reduce irrelevant suggestions by 30-40% compared to vanilla Copilot.
PrivacyAll inference happens locally; no code leaves the machine.
SpeedLocal inference delivers sub-second responses, even on modest hardware.
CustomizabilityUsers can swap LLMs (Qwen-Coder-v3, Gemma-3, Ollama) without changing the workflow.
Unified InterfaceObsidian for planning, VS Code for coding, Serena for execution – all in one ecosystem.

表は期待する効果です。特に重視したのは Privacy と Unified Interface で、コードをローカルに保ち、計画と実装をつなぐことです。

セットアップの手順例

  # 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
  

関連メモから見える拡張方向

関連メモには、LLM導入後の開発基盤を広げる案もあります。

  • 再現性と証跡: 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を含む統合基盤

整理した構想

メモでは 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 へ広げる予定です。