Obsidian MCP Server

by cyanheads
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Enables AI models to interact with Obsidian vaults through a standardized interface, providing file operations, search capabilities, and property management for knowledge bases in Obsidian

Obsidian MCP サーバー

LLMがObsidian Vaultと連携できるように設計されたモデルコンテキストプロトコルサーバーです。TypeScriptで構築され、安全なAPI通信、効率的なファイル操作、包括的な検索機能を備えており、AIアシスタントはシンプルで柔軟なツールインターフェースを通じてナレッジベースをシームレスに管理できます。

モデル コンテキスト プロトコル (MCP) により、AI モデルは標準化されたインターフェースを通じて外部のツールやリソースと対話できるようになります。

Obsidian の Local REST API プラグインが必要です。

特徴

ファイル操作

  • 検証を伴うアトミックなファイル/ディレクトリ操作
  • リソースの監視とクリーンアップ
  • エラー処理と正常な失敗

検索システム

  • 設定可能なコンテキストによる全文検索
  • ファイル、タグ、メタデータに対する高度な JsonLogic クエリ
  • globパターンとfrontmatterフィールドのサポート

不動産管理

  • YAML フロントマターの解析とインテリジェントなマージ
  • 自動タイムスタンプ(Obsidian によって作成され、サーバーによって変更されます)
  • カスタムフィールドのサポート

セキュリティとパフォーマンス

  • レート制限とSSLオプションを備えたAPIキー認証
  • リソース監視とヘルスチェック
  • 正常なシャットダウン処理

インストール

注: Node.js が必要です

  1. ObsidianでローカルREST APIプラグインを有効にする
  2. クローンとビルド:
git clone git@github.com:cyanheads/obsidian-mcp-server.git cd obsidian-mcp-server npm install npm run build

または npm からインストールします:

npm install obsidian-mcp-server

構成

MCP クライアント設定に追加します (例: claude_desktop_config.jsonまたはcline_mcp_settings.json ):

{ "mcpServers": { "obsidian-mcp-server": { "command": "node", "args": ["/path/to/obsidian-mcp-server/build/index.js"], "env": { "OBSIDIAN_API_KEY": "your_api_key_here", "VERIFY_SSL": "false", "OBSIDIAN_PROTOCOL": "https", "OBSIDIAN_HOST": "127.0.0.1", "OBSIDIAN_PORT": "27124", "REQUEST_TIMEOUT": "5000", "MAX_CONTENT_LENGTH": "52428800", "MAX_BODY_LENGTH": "52428800", "RATE_LIMIT_WINDOW_MS": "900000", "RATE_LIMIT_MAX_REQUESTS": "200", "TOOL_TIMEOUT_MS": "60000" } } } }

環境変数:

必須:

  • OBSIDIAN_API_KEY : ObsidianのLocal REST APIプラグイン設定からのAPIキー

接続設定:

  • VERIFY_SSL : SSL証明書の検証を有効にする (デフォルト: false) # 自己署名証明書の場合は必ずfalseに設定してください。ローカルで実行している場合や、この意味がわからない場合は、falseに設定してください。
  • OBSIDIAN_PROTOCOL : 使用するプロトコル(デフォルト: "https")
  • OBSIDIAN_HOST : ホストアドレス(デフォルト: "127.0.0.1")
  • OBSIDIAN_PORT : ポート番号(デフォルト: 27124)

リクエスト制限:

  • REQUEST_TIMEOUT : リクエストタイムアウト(ミリ秒)(デフォルト: 5000)
  • MAX_CONTENT_LENGTH : レスポンスコンテンツの最大長(バイト単位)(デフォルト: 52428800 [50MB])
  • MAX_BODY_LENGTH : リクエストボディの最大長(バイト単位)(デフォルト: 52428800 [50MB])

レート制限:

  • RATE_LIMIT_WINDOW_MS : レート制限ウィンドウ(ミリ秒単位)(デフォルト: 900000 [15分])
  • RATE_LIMIT_MAX_REQUESTS : ウィンドウあたりの最大リクエスト数(デフォルト: 200)

ツールの実行:

  • TOOL_TIMEOUT_MS : ツール実行タイムアウト(ミリ秒)(デフォルト: 60000 [1分])

プロジェクト構造

このプロジェクトは、関心事が明確に分離されたモジュール型アーキテクチャを採用しています。

src/ ├── index.ts # Main entry point ├── mcp/ # MCP server implementation ├── obsidian/ # Obsidian API client and types ├── resources/ # MCP resource implementations ├── tools/ # MCP tool implementations │ ├── files/ # File operations tools │ ├── search/ # Search tools │ └── properties/ # Property management tools └── utils/ # Shared utilities

ツール

ファイル管理

// List vault contents obsidian_list_files_in_vault: { } // List directory contents obsidian_list_files_in_dir: { dirpath: string; // Path relative to vault root } // Get file contents obsidian_get_file_contents: { filepath: string; // Path relative to vault root }

捜索活動

// Text search with context obsidian_find_in_file: { query: string, contextLength?: number // Default: 10 } // Advanced search with JsonLogic obsidian_complex_search: { query: JsonLogicQuery // Examples: // Find by tag: // {"in": ["#mytag", {"var": "frontmatter.tags"}]} // // Find markdown files in a directory: // {"glob": ["docs/*.md", {"var": "path"}]} // // Combine conditions: // {"and": [ // {"glob": ["*.md", {"var": "path"}]}, // {"in": ["#mytag", {"var": "frontmatter.tags"}]} // ]} } // Get all tags in vault or directory obsidian_get_tags: { path?: string // Optional: limit to specific directory }

コンテンツの変更

// Append to file obsidian_append_content: { filepath: string, // Path relative to vault root content: string // Content to append } // Update file content obsidian_patch_content: { filepath: string, // Path relative to vault root content: string // New content (replaces existing) }

不動産管理

// Get note properties obsidian_get_properties: { filepath: string // Path relative to vault root } // Update note properties obsidian_update_properties: { filepath: string, // Path relative to vault root properties: { title?: string, author?: string, // Note: created/modified timestamps are managed automatically type?: Array<"concept" | "architecture" | "specification" | "protocol" | "api" | "research" | "implementation" | "guide" | "reference">, tags?: string[], // Must start with # status?: Array<"draft" | "in-progress" | "review" | "complete">, version?: string, platform?: string, repository?: string, // URL dependencies?: string[], sources?: string[], urls?: string[], // URLs papers?: string[], custom?: Record<string, unknown> } }

ベストプラクティス

ファイル操作

  • 検証を伴うアトミック操作を使用する
  • エラーを処理し、パフォーマンスを監視する

検索実装

  • タスクに適切な検索ツールを使用します。
    • テキスト検索用のobsidian_find_in_file
    • メタデータ/タグフィルタリング用のobsidian_complex_search
  • コンテキストのサイズを適切に保つ(デフォルト: 10 文字)

不動産管理

  • 適切なタイプを使用して更新を検証する
  • 配列とカスタムフィールドを適切に処理する
  • タイムスタンプを設定しない(自動的に管理される)

エラー防止

  • 入力を検証し、エラーを適切に処理する
  • パターンを監視し、レート制限を尊重する

リソース

MCP サーバーは次のリソースを公開します。

obsidian://tags # List of all tags used across the vault

貢献

  1. リポジトリをフォークする
  2. 機能ブランチを作成する
  3. プルリクエストを送信する

バグや機能については、 https://github.com/cyanheads/obsidian-mcp-server/issuesで問題を作成してください。

出版

バージョン タグがプッシュされると、パッケージは自動的に npm に公開されます。

# Update version in package.json npm version patch # or minor, or major git push --follow-tags

これにより、GitHub アクションがトリガーされ、パッケージがビルドされて公開されます。

ライセンス

Apacheライセンス2.0


ID: syuh40cxyk