diff --git a/README.md b/README.md index f9f9c9a..21d9462 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,17 @@ - `bin/`: `llama-server` と依存 DLL をダウンロード - `models/`: ベクトル生成用モデルをダウンロード -### 2. 実行 +### 2. LM Studio への統合 (オプション) + +LM Studio で本サーバーをツールとして利用する場合、以下のコマンドを実行します。これにより、必要なファイルが LM Studio のプラグインディレクトリに適切に配置されます。 + +```bash +bun run mcp:install +``` + +実行後、LM Studio を再起動するかプラグインをリロードしてください。 + +### 3. 実行 ```bash bun dev diff --git a/document/system_summary.md b/document/system_summary.md new file mode 100644 index 0000000..8e56264 --- /dev/null +++ b/document/system_summary.md @@ -0,0 +1,40 @@ +# システム概要 + +本プロジェクトは、SQLite と Rust (Tauri v2) を用いた、ローカル実行型のベクトル検索 MCP (Model Context Protocol) サーバーです。 + +## 主要コンポーネント + +```mermaid +graph LR + User([User / MCP Client]) + + subgraph "App (Tauri v2)" + Axum[Axum SSE Server] + Core[Tauri Core] + DB[(SQLite + sqlite-vec)] + end + + subgraph "Sidecar" + LS[llama-server] + Model[Gemma 3 300M] + end + + User <-->|SSE / JSON-RPC| Axum + Axum <--> DB + Axum <--> LS + LS <--> Model +``` + +## 各コンポーネントの説明 + +- **Tauri v2**: アプリケーションの基盤。Windows 上で常駐し、システムトレイからの操作や UI 表示を提供。 +- **Axum (MCP Server)**: SSE トランスポートを用いた MCP 通信を担当。`messages` ポストを受け、各ツールを実行。 +- **SQLite + sqlite-vec**: ベクトルデータとメタデータを一元管理。`sqlite-vec` による ANN 検索を実行。 +- **llama-server (Sidecar)**: `llama.cpp` の外部プロセス。テキストのベクトル化 (Embedding) および生成を担当。 +- **Gemma 3 300M**: ローカルで高速かつ軽量に埋め込みを抽出するためのモデル。 + +## 開発環境 + +- **言語**: Rust (Backend), Vanilla JS (Frontend) +- **パッケージ管理**: Bun +- **ビルドツール**: Cargo, Tauri CLI diff --git a/package.json b/package.json index 968aa43..a3fc253 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "build": "tauri build --config src/backend/tauri.conf.json", "tauri": "tauri", "release": "node scripts/release.js", + "mcp:install": "node scripts/install-mcp.js", "test:watch": "bun test --watch test/**/*.test.js" }, "devDependencies": { diff --git a/scripts/install-mcp.js b/scripts/install-mcp.js new file mode 100644 index 0000000..a62a4fc --- /dev/null +++ b/scripts/install-mcp.js @@ -0,0 +1,56 @@ +import fs from 'fs'; +import os from 'os'; +import path from 'path'; + +/** + * LM Studio 用の MCP プラグインをインストール/セットアップするスクリプト + * 1. プラグインディレクトリの作成 + * 2. 必要なアダプターファイルのコピー + * 3. 対応する設定ファイルの作成 (相対パス使用) + */ + +const PLUGIN_NAME = 'sqlite-vector'; +const PLUGIN_DIR = path.join(os.homedir(), '.lmstudio', 'extensions', 'plugins', 'mcp', PLUGIN_NAME); +const BIN_DIR = path.join(PLUGIN_DIR, 'bin'); + +console.log(`🔧 Setting up LM Studio extension: ${PLUGIN_NAME}...`); + +try { + // 1. ディレクトリ作成 + if (!fs.existsSync(BIN_DIR)) { + fs.mkdirSync(BIN_DIR, { recursive: true }); + console.log(`✅ Created directory: ${BIN_DIR}`); + } + + // 2. アダプターのコピー + const sourceAdapter = path.join(process.cwd(), 'bin', 'mcp-stdio-adapter.cjs'); + const targetAdapter = path.join(BIN_DIR, 'mcp-stdio-adapter.cjs'); + + fs.copyFileSync(sourceAdapter, targetAdapter); + console.log(`✅ Copied adapter to: ${targetAdapter}`); + + // 3. manifest.json の作成/更新 + const manifest = { + "type": "plugin", + "runner": "mcpBridge", + "owner": "mcp", + "name": PLUGIN_NAME + }; + fs.writeFileSync(path.join(PLUGIN_DIR, 'manifest.json'), JSON.stringify(manifest, null, 2)); + console.log('✅ Created manifest.json'); + + // 4. mcp-bridge-config.json の作成 (相対パスを使用しポータブルにする) + const bridgeConfig = { + "command": "node", + "args": ["./bin/mcp-stdio-adapter.cjs"] + }; + fs.writeFileSync(path.join(PLUGIN_DIR, 'mcp-bridge-config.json'), JSON.stringify(bridgeConfig, null, 2)); + console.log('✅ Created mcp-bridge-config.json (using relative path)'); + + console.log(`\n✨ Successfully installed LM Studio extension!`); + console.log(`Please restart LM Studio or reload the plugin.`); + +} catch (err) { + console.error('❌ Failed to install extension:', err.message); + process.exit(1); +}