obsidian-mcp-server 1.5.7 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +249 -101
  2. package/dist/config/index.d.ts +41 -0
  3. package/dist/config/index.js +191 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +298 -0
  6. package/dist/mcp-server/server.d.ts +33 -0
  7. package/dist/mcp-server/server.js +211 -0
  8. package/dist/mcp-server/tools/obsidianDeleteFileTool/index.d.ts +12 -0
  9. package/dist/mcp-server/tools/obsidianDeleteFileTool/index.js +12 -0
  10. package/dist/mcp-server/tools/obsidianDeleteFileTool/logic.d.ts +51 -0
  11. package/dist/mcp-server/tools/obsidianDeleteFileTool/logic.js +168 -0
  12. package/dist/mcp-server/tools/obsidianDeleteFileTool/registration.d.ts +19 -0
  13. package/dist/mcp-server/tools/obsidianDeleteFileTool/registration.js +91 -0
  14. package/dist/mcp-server/tools/obsidianGlobalSearchTool/index.d.ts +12 -0
  15. package/dist/mcp-server/tools/obsidianGlobalSearchTool/index.js +12 -0
  16. package/dist/mcp-server/tools/obsidianGlobalSearchTool/logic.d.ts +77 -0
  17. package/dist/mcp-server/tools/obsidianGlobalSearchTool/logic.js +341 -0
  18. package/dist/mcp-server/tools/obsidianGlobalSearchTool/registration.d.ts +18 -0
  19. package/dist/mcp-server/tools/obsidianGlobalSearchTool/registration.js +69 -0
  20. package/dist/mcp-server/tools/obsidianListFilesTool/index.d.ts +12 -0
  21. package/dist/mcp-server/tools/obsidianListFilesTool/index.js +12 -0
  22. package/dist/mcp-server/tools/obsidianListFilesTool/logic.d.ts +64 -0
  23. package/dist/mcp-server/tools/obsidianListFilesTool/logic.js +179 -0
  24. package/dist/mcp-server/tools/obsidianListFilesTool/registration.d.ts +19 -0
  25. package/dist/mcp-server/tools/obsidianListFilesTool/registration.js +96 -0
  26. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/index.d.ts +3 -0
  27. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/index.js +2 -0
  28. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/logic.d.ts +42 -0
  29. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/logic.js +152 -0
  30. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/registration.d.ts +3 -0
  31. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/registration.js +52 -0
  32. package/dist/mcp-server/tools/obsidianManageTagsTool/index.d.ts +3 -0
  33. package/dist/mcp-server/tools/obsidianManageTagsTool/index.js +2 -0
  34. package/dist/mcp-server/tools/obsidianManageTagsTool/logic.d.ts +28 -0
  35. package/dist/mcp-server/tools/obsidianManageTagsTool/logic.js +161 -0
  36. package/dist/mcp-server/tools/obsidianManageTagsTool/registration.d.ts +3 -0
  37. package/dist/mcp-server/tools/obsidianManageTagsTool/registration.js +52 -0
  38. package/dist/mcp-server/tools/obsidianReadFileTool/index.d.ts +12 -0
  39. package/dist/mcp-server/tools/obsidianReadFileTool/index.js +12 -0
  40. package/dist/mcp-server/tools/obsidianReadFileTool/logic.d.ts +87 -0
  41. package/dist/mcp-server/tools/obsidianReadFileTool/logic.js +216 -0
  42. package/dist/mcp-server/tools/obsidianReadFileTool/registration.d.ts +20 -0
  43. package/dist/mcp-server/tools/obsidianReadFileTool/registration.js +101 -0
  44. package/dist/mcp-server/tools/obsidianSearchReplaceTool/index.d.ts +12 -0
  45. package/dist/mcp-server/tools/obsidianSearchReplaceTool/index.js +12 -0
  46. package/dist/mcp-server/tools/obsidianSearchReplaceTool/logic.d.ts +255 -0
  47. package/dist/mcp-server/tools/obsidianSearchReplaceTool/logic.js +583 -0
  48. package/dist/mcp-server/tools/obsidianSearchReplaceTool/registration.d.ts +22 -0
  49. package/dist/mcp-server/tools/obsidianSearchReplaceTool/registration.js +111 -0
  50. package/dist/mcp-server/tools/obsidianUpdateFileTool/index.d.ts +12 -0
  51. package/dist/mcp-server/tools/obsidianUpdateFileTool/index.js +12 -0
  52. package/dist/mcp-server/tools/obsidianUpdateFileTool/logic.d.ts +183 -0
  53. package/dist/mcp-server/tools/obsidianUpdateFileTool/logic.js +490 -0
  54. package/dist/mcp-server/tools/obsidianUpdateFileTool/registration.d.ts +21 -0
  55. package/dist/mcp-server/tools/obsidianUpdateFileTool/registration.js +108 -0
  56. package/dist/mcp-server/transports/authentication/authContext.d.ts +33 -0
  57. package/dist/mcp-server/transports/authentication/authContext.js +24 -0
  58. package/dist/mcp-server/transports/authentication/authMiddleware.d.ts +30 -0
  59. package/dist/mcp-server/transports/authentication/authMiddleware.js +145 -0
  60. package/dist/mcp-server/transports/authentication/authUtils.d.ts +18 -0
  61. package/dist/mcp-server/transports/authentication/authUtils.js +45 -0
  62. package/dist/mcp-server/transports/authentication/oauthMiddleware.d.ts +24 -0
  63. package/dist/mcp-server/transports/authentication/oauthMiddleware.js +109 -0
  64. package/dist/mcp-server/transports/authentication/types.d.ts +17 -0
  65. package/dist/mcp-server/transports/authentication/types.js +5 -0
  66. package/dist/mcp-server/transports/httpTransport.d.ts +24 -0
  67. package/dist/mcp-server/transports/httpTransport.js +496 -0
  68. package/dist/mcp-server/transports/stdioTransport.d.ts +42 -0
  69. package/dist/mcp-server/transports/stdioTransport.js +63 -0
  70. package/dist/services/obsidianRestAPI/index.d.ts +15 -0
  71. package/dist/services/obsidianRestAPI/index.js +17 -0
  72. package/dist/services/obsidianRestAPI/methods/activeFileMethods.d.ts +38 -0
  73. package/dist/services/obsidianRestAPI/methods/activeFileMethods.js +62 -0
  74. package/dist/services/obsidianRestAPI/methods/commandMethods.d.ts +22 -0
  75. package/dist/services/obsidianRestAPI/methods/commandMethods.js +31 -0
  76. package/dist/services/obsidianRestAPI/methods/openMethods.d.ts +16 -0
  77. package/dist/services/obsidianRestAPI/methods/openMethods.js +21 -0
  78. package/dist/services/obsidianRestAPI/methods/patchMethods.d.ts +37 -0
  79. package/dist/services/obsidianRestAPI/methods/patchMethods.js +94 -0
  80. package/dist/services/obsidianRestAPI/methods/periodicNoteMethods.d.ts +42 -0
  81. package/dist/services/obsidianRestAPI/methods/periodicNoteMethods.js +66 -0
  82. package/dist/services/obsidianRestAPI/methods/searchMethods.d.ts +25 -0
  83. package/dist/services/obsidianRestAPI/methods/searchMethods.js +36 -0
  84. package/dist/services/obsidianRestAPI/methods/vaultMethods.d.ts +58 -0
  85. package/dist/services/obsidianRestAPI/methods/vaultMethods.js +144 -0
  86. package/dist/services/obsidianRestAPI/service.d.ts +195 -0
  87. package/dist/services/obsidianRestAPI/service.js +379 -0
  88. package/dist/services/obsidianRestAPI/types.d.ts +127 -0
  89. package/dist/services/obsidianRestAPI/types.js +7 -0
  90. package/dist/services/obsidianRestAPI/vaultCache/index.d.ts +4 -0
  91. package/dist/services/obsidianRestAPI/vaultCache/index.js +4 -0
  92. package/dist/services/obsidianRestAPI/vaultCache/service.d.ts +88 -0
  93. package/dist/services/obsidianRestAPI/vaultCache/service.js +299 -0
  94. package/dist/types-global/errors.d.ts +73 -0
  95. package/dist/types-global/errors.js +71 -0
  96. package/dist/utils/index.d.ts +5 -0
  97. package/dist/utils/index.js +13 -0
  98. package/dist/utils/internal/asyncUtils.d.ts +54 -0
  99. package/dist/utils/internal/asyncUtils.js +101 -0
  100. package/dist/utils/internal/errorHandler.d.ts +176 -0
  101. package/dist/utils/internal/errorHandler.js +351 -0
  102. package/dist/utils/internal/index.d.ts +4 -0
  103. package/dist/utils/internal/index.js +4 -0
  104. package/dist/utils/internal/logger.d.ts +141 -0
  105. package/dist/utils/internal/logger.js +406 -0
  106. package/dist/utils/internal/requestContext.d.ts +83 -0
  107. package/dist/utils/internal/requestContext.js +72 -0
  108. package/dist/utils/metrics/index.d.ts +1 -0
  109. package/dist/utils/metrics/index.js +1 -0
  110. package/dist/utils/metrics/tokenCounter.d.ts +27 -0
  111. package/dist/utils/metrics/tokenCounter.js +128 -0
  112. package/dist/utils/obsidian/index.d.ts +5 -0
  113. package/dist/utils/obsidian/index.js +5 -0
  114. package/dist/utils/obsidian/obsidianApiUtils.d.ts +14 -0
  115. package/dist/utils/obsidian/obsidianApiUtils.js +29 -0
  116. package/dist/utils/obsidian/obsidianStatUtils.d.ts +68 -0
  117. package/dist/utils/obsidian/obsidianStatUtils.js +143 -0
  118. package/dist/utils/parsing/dateParser.d.ts +56 -0
  119. package/dist/utils/parsing/dateParser.js +104 -0
  120. package/dist/utils/parsing/index.d.ts +2 -0
  121. package/dist/utils/parsing/index.js +3 -0
  122. package/dist/utils/parsing/jsonParser.d.ts +80 -0
  123. package/dist/utils/parsing/jsonParser.js +133 -0
  124. package/dist/utils/security/idGenerator.d.ts +140 -0
  125. package/dist/utils/security/idGenerator.js +194 -0
  126. package/dist/utils/security/index.d.ts +3 -0
  127. package/dist/utils/security/index.js +3 -0
  128. package/dist/utils/security/rateLimiter.d.ts +156 -0
  129. package/dist/utils/security/rateLimiter.js +235 -0
  130. package/dist/utils/security/sanitization.d.ts +244 -0
  131. package/dist/utils/security/sanitization.js +599 -0
  132. package/package.json +72 -40
  133. package/.github/workflows/publish.yml +0 -35
  134. package/Dockerfile +0 -63
  135. package/build/index.js +0 -20
  136. package/build/mcp/handlers.js +0 -305
  137. package/build/mcp/index.js +0 -7
  138. package/build/mcp/server.js +0 -240
  139. package/build/mcp/types.js +0 -49
  140. package/build/obsidian/client.js +0 -403
  141. package/build/obsidian/errors.js +0 -75
  142. package/build/obsidian/index.js +0 -7
  143. package/build/obsidian/types.js +0 -12
  144. package/build/resources/index.js +0 -15
  145. package/build/resources/tags.js +0 -257
  146. package/build/resources/types.js +0 -5
  147. package/build/tools/base.js +0 -88
  148. package/build/tools/files/content.js +0 -171
  149. package/build/tools/files/index.js +0 -22
  150. package/build/tools/files/list.js +0 -133
  151. package/build/tools/index.js +0 -31
  152. package/build/tools/properties/index.js +0 -19
  153. package/build/tools/properties/manager.js +0 -302
  154. package/build/tools/properties/tools.js +0 -239
  155. package/build/tools/properties/types.js +0 -70
  156. package/build/tools/search/complex.js +0 -270
  157. package/build/tools/search/index.js +0 -20
  158. package/build/tools/search/simple.js +0 -127
  159. package/build/utils/errors.js +0 -59
  160. package/build/utils/idGenerator.js +0 -21
  161. package/build/utils/index.js +0 -9
  162. package/build/utils/logging.js +0 -417
  163. package/build/utils/rate-limiting.js +0 -94
  164. package/build/utils/tokenization.js +0 -75
  165. package/build/utils/validation.js +0 -92
  166. package/debug.js +0 -98
  167. package/docs/tree.md +0 -67
  168. package/env.json +0 -42
  169. package/mcp-client-config.example.json +0 -23
  170. package/repomix.config.json +0 -20
  171. package/scripts/clean.ts +0 -103
  172. package/scripts/tree.ts +0 -599
  173. package/src/index.ts +0 -23
  174. package/src/mcp/handlers.ts +0 -410
  175. package/src/mcp/index.ts +0 -7
  176. package/src/mcp/server.ts +0 -288
  177. package/src/mcp/types.ts +0 -112
  178. package/src/obsidian/client.ts +0 -505
  179. package/src/obsidian/errors.ts +0 -105
  180. package/src/obsidian/index.ts +0 -7
  181. package/src/obsidian/types.ts +0 -124
  182. package/src/resources/index.ts +0 -17
  183. package/src/resources/tags.ts +0 -283
  184. package/src/resources/types.ts +0 -30
  185. package/src/tools/base.ts +0 -123
  186. package/src/tools/files/content.ts +0 -206
  187. package/src/tools/files/index.ts +0 -31
  188. package/src/tools/files/list.ts +0 -150
  189. package/src/tools/index.ts +0 -38
  190. package/src/tools/properties/index.ts +0 -21
  191. package/src/tools/properties/manager.ts +0 -370
  192. package/src/tools/properties/tools.ts +0 -280
  193. package/src/tools/properties/types.ts +0 -117
  194. package/src/tools/search/complex.ts +0 -303
  195. package/src/tools/search/index.ts +0 -22
  196. package/src/tools/search/simple.ts +0 -147
  197. package/src/utils/errors.ts +0 -69
  198. package/src/utils/idGenerator.ts +0 -22
  199. package/src/utils/index.ts +0 -8
  200. package/src/utils/logging.ts +0 -558
  201. package/src/utils/rate-limiting.ts +0 -114
  202. package/src/utils/tokenization.ts +0 -85
  203. package/src/utils/validation.ts +0 -105
  204. package/tsconfig.json +0 -17
package/README.md CHANGED
@@ -1,155 +1,303 @@
1
1
  # Obsidian MCP Server
2
2
 
3
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.8.3-blue.svg)](https://www.typescriptlang.org/)
4
- [![Model Context Protocol](https://img.shields.io/badge/MCP-1.10.2-green.svg)](https://modelcontextprotocol.io/)
5
- [![Version](https://img.shields.io/badge/Version-1.5.7-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
- [![Status](https://img.shields.io/badge/Status-Stable-green.svg)]()
3
+ [![TypeScript](https://img.shields.io/badge/TypeScript-^5.8.3-blue.svg)](https://www.typescriptlang.org/)
4
+ [![Model Context Protocol](https://img.shields.io/badge/MCP%20SDK-^1.12.1-green.svg)](https://modelcontextprotocol.io/)
5
+ [![Version](https://img.shields.io/badge/Version-2.0.1-blue.svg)](./CHANGELOG.md)
6
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
+ [![Status](https://img.shields.io/badge/Status-Production-brightgreen.svg)](https://github.com/cyanheads/obsidian-mcp-server/issues)
7
8
  [![GitHub](https://img.shields.io/github/stars/cyanheads/obsidian-mcp-server?style=social)](https://github.com/cyanheads/obsidian-mcp-server)
8
9
 
9
- A Model Context Protocol server designed for LLMs to interact with Obsidian vaults. Built with TypeScript and featuring secure API communication, efficient file operations, and comprehensive search capabilities, it enables AI assistants to seamlessly manage knowledge bases through a clean, flexible tool interface.
10
+ **Empower your AI agents and development tools with seamless Obsidian integration!**
10
11
 
11
- The Model Context Protocol (MCP) enables AI models to interact with external tools and resources through a standardized interface.
12
+ An MCP (Model Context Protocol) server providing comprehensive access to your Obsidian vault. Enables LLMs and AI agents to read, write, search, and manage your notes and files through the [Obsidian Local REST API plugin](https://github.com/coddingtonbear/obsidian-local-rest-api).
12
13
 
13
- Requires the [Local REST API plugin](https://github.com/coddingtonbear/obsidian-local-rest-api) in Obsidian.
14
+ Built on the [`cyanheads/mcp-ts-template`](https://github.com/cyanheads/mcp-ts-template), this server follows a modular architecture with robust error handling, logging, and security features.
14
15
 
15
- ## 📋 Table of Contents
16
+ ## 🚀 Core Capabilities: Obsidian Tools 🛠️
16
17
 
17
- [Features](#-features) | [Installation](#-installation) | [Configuration](#-configuration) | [Tools](#-tools) | [Resources](#-resources) | [Project Structure](#-project-structure) | [Contributing](#-contributing) | [Publishing](#-publishing) | [License](#-license)
18
+ This server equips your AI with specialized tools to interact with your Obsidian vault:
18
19
 
19
- ## Features
20
+ | Tool Name | Description | Key Features |
21
+ | :------------------------------------------------------------------------------------- | :-------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
22
+ | [`obsidian_read_file`](./src/mcp-server/tools/obsidianReadFileTool/) | Retrieves the content and metadata of a specified file. | - Read in `markdown` or `json` format.<br/>- Case-insensitive path fallback.<br/>- Includes file stats (creation/modification time). |
23
+ | [`obsidian_update_file`](./src/mcp-server/tools/obsidianUpdateFileTool/) | Modifies notes using whole-file operations. | - `append`, `prepend`, or `overwrite` content.<br/>- Can create files if they don't exist.<br/>- Targets files by path, active note, or periodic note. |
24
+ | [`obsidian_search_replace`](./src/mcp-server/tools/obsidianSearchReplaceTool/) | Performs search-and-replace operations within a target note. | - Supports string or regex search.<br/>- Options for case sensitivity, whole word, and replacing all occurrences. |
25
+ | [`obsidian_global_search`](./src/mcp-server/tools/obsidianGlobalSearchTool/) | Performs a search across the entire vault. | - Text or regex search.<br/>- Filter by path and modification date.<br/>- Paginated results. |
26
+ | [`obsidian_list_files`](./src/mcp-server/tools/obsidianListFilesTool/) | Lists files and subdirectories within a specified vault folder. | - Filter by file extension or name regex.<br/>- Provides a formatted tree view of the directory. |
27
+ | [`obsidian_manage_frontmatter`](./src/mcp-server/tools/obsidianManageFrontmatterTool/) | Atomically manages a note's YAML frontmatter. | - `get`, `set`, or `delete` frontmatter keys.<br/>- Avoids rewriting the entire file for metadata changes. |
28
+ | [`obsidian_manage_tags`](./src/mcp-server/tools/obsidianManageTagsTool/) | Adds, removes, or lists tags for a note. | - Manages tags in both YAML frontmatter and inline content. |
29
+ | [`obsidian_delete_file`](./src/mcp-server/tools/obsidianDeleteFileTool/) | Permanently deletes a specified file from the vault. | - Case-insensitive path fallback for safety. |
20
30
 
21
- - **File Operations**: Atomic file/directory operations with validation, resource monitoring, and error handling.
22
- - **Search System**: Full-text search with configurable context, advanced JsonLogic queries, glob patterns, and frontmatter field support.
23
- - **Property Management**: YAML frontmatter parsing, intelligent merging, automatic timestamps, and custom field support.
24
- - **Security & Performance**: API key authentication, rate limiting, SSL options, resource monitoring, and graceful shutdown.
31
+ ---
32
+
33
+ ## Table of Contents
34
+
35
+ | [Overview](#overview) | [Features](#features) | [Installation](#installation) |
36
+ | [Configuration](#configuration) | [Project Structure](#project-structure) | [Vault Cache Service](#vault-cache-service) |
37
+ | [Tools](#tools) | [Resources](#resources) | [Development](#development) | [License](#license) |
38
+
39
+ ## Overview
40
+
41
+ The Obsidian MCP Server acts as a bridge, allowing applications (MCP Clients) that understand the Model Context Protocol (MCP) – like advanced AI assistants (LLMs), IDE extensions, or custom scripts – to interact directly and safely with your Obsidian vault.
42
+
43
+ Instead of complex scripting or manual interaction, your tools can leverage this server to:
44
+
45
+ - **Automate vault management**: Read notes, update content, manage frontmatter and tags, search across files, list directories, and delete files programmatically.
46
+ - **Integrate Obsidian into AI workflows**: Enable LLMs to access and modify your knowledge base as part of their research, writing, or coding tasks.
47
+ - **Build custom Obsidian tools**: Create external applications that interact with your vault data in novel ways.
48
+
49
+ Built on the robust `mcp-ts-template`, this server provides a standardized, secure, and efficient way to expose Obsidian functionality via the MCP standard. It achieves this by communicating with the powerful [Obsidian Local REST API plugin](https://github.com/coddingtonbear/obsidian-local-rest-api) running inside your vault.
50
+
51
+ > **Developer Note**: This repository includes a [.clinerules](.clinerules) file that serves as a developer cheat sheet for your LLM coding agent with quick reference for the codebase patterns, file locations, and code snippets.
52
+
53
+ ## Features
54
+
55
+ ### Core Utilities
56
+
57
+ Leverages the robust utilities provided by the `mcp-ts-template`:
58
+
59
+ - **Logging**: Structured, configurable logging (file rotation, console, MCP notifications) with sensitive data redaction.
60
+ - **Error Handling**: Centralized error processing, standardized error types (`McpError`), and automatic logging.
61
+ - **Configuration**: Environment variable loading (`dotenv`) with comprehensive validation.
62
+ - **Input Validation/Sanitization**: Uses `zod` for schema validation and custom sanitization logic.
63
+ - **Request Context**: Tracking and correlation of operations via unique request IDs.
64
+ - **Type Safety**: Strong typing enforced by TypeScript and Zod schemas.
65
+ - **HTTP Transport Option**: Built-in Hono server with SSE, session management, CORS support, and JWT authentication.
66
+
67
+ ### Obsidian Integration
68
+
69
+ - **Obsidian Local REST API Integration**: Communicates directly with the Obsidian Local REST API plugin via HTTP requests managed by the `ObsidianRestApiService`.
70
+ - **Comprehensive Command Coverage**: Exposes key vault operations as MCP tools (see [Tools](#tools) section).
71
+ - **Vault Interaction**: Supports reading, updating (append, prepend, overwrite), searching (global text/regex, search/replace), listing, deleting, and managing frontmatter and tags.
72
+ - **Targeting Flexibility**: Tools can target files by path, the currently active file in Obsidian, or periodic notes (daily, weekly, etc.).
73
+ - **Vault Cache Service**: An intelligent in-memory cache that improves performance and resilience. It caches vault content, provides a fallback for the global search tool if the live API fails, and periodically refreshes to stay in sync.
74
+ - **Safety Features**: Case-insensitive path fallbacks for file operations, clear distinction between modification types (append, overwrite, etc.).
75
+
76
+ ## Installation
77
+
78
+ ### Prerequisites
25
79
 
26
- ## 🚀 Installation
80
+ 1. **Obsidian**: You need Obsidian installed.
81
+ 2. **Obsidian Local REST API Plugin**: Install and enable the [Obsidian Local REST API plugin](https://github.com/coddingtonbear/obsidian-local-rest-api) within your Obsidian vault.
82
+ 3. **API Key**: Configure an API key within the Local REST API plugin settings in Obsidian. You will need this key to configure the server.
83
+ 4. **Node.js & npm**: Ensure you have Node.js (v18 or later recommended) and npm installed.
27
84
 
28
- Note: Requires Node.js and the [Local REST API plugin](https://github.com/coddingtonbear/obsidian-local-rest-api) enabled in Obsidian.
85
+ ### Install via npm (Recommended)
29
86
 
30
- ### Option 1: Clone and Build (for development or direct use)
87
+ ```bash
88
+ npm install obsidian-mcp-server
89
+ ```
90
+
91
+ ### Install from Source
31
92
 
32
- 1. Enable the Local REST API plugin in Obsidian.
33
- 2. Clone the repository, install dependencies, and build the project:
93
+ 1. Clone the repository:
34
94
  ```bash
35
- git clone git@github.com:cyanheads/obsidian-mcp-server.git
95
+ git clone https://github.com/cyanheads/obsidian-mcp-server.git
36
96
  cd obsidian-mcp-server
97
+ ```
98
+ 2. Install dependencies:
99
+ ```bash
37
100
  npm install
101
+ ```
102
+ 3. Build the project:
103
+ ```bash
38
104
  npm run build
39
105
  ```
40
- 3. Configure the server using environment variables and run it using `node build/index.js` (see Configuration section below).
106
+ This compiles the TypeScript code to JavaScript in the `dist/` directory and makes the entry point executable.
41
107
 
42
- ### Option 2: Install via npm (as a dependency or globally)
108
+ ## Configuration
43
109
 
44
- 1. Enable the Local REST API plugin in Obsidian.
45
- 2. Install the package using npm:
110
+ ### Environment Variables
46
111
 
47
- ```bash
48
- # Install locally (e.g., within another project)
49
- npm install obsidian-mcp-server
112
+ Configure the server using environment variables.
50
113
 
51
- # Or install globally
52
- npm install -g obsidian-mcp-server
53
- ```
114
+ These variables must be set in the MCP client configuration (e.g., `cline_mcp_settings.json`) or in your environment before starting the server (if running directly).
115
+
116
+ If running directly, they can be set in a `.env` file in the project root or directly in your environment.
117
+
118
+ | Variable | Description | Required | Default |
119
+ | :------------------------------------ | :-------------------------------------------------------- | :---------------- | :----------------------- |
120
+ | **`OBSIDIAN_API_KEY`** | API Key from the Obsidian Local REST API plugin. | **Yes** | `undefined` |
121
+ | **`OBSIDIAN_BASE_URL`** | Base URL of your Obsidian Local REST API. | **Yes** | `http://127.0.0.1:27123` |
122
+ | `MCP_TRANSPORT_TYPE` | Server transport: `stdio` or `http`. | No | `stdio` |
123
+ | `MCP_HTTP_PORT` | Port for the HTTP server. | No | `3010` |
124
+ | `MCP_HTTP_HOST` | Host for the HTTP server. | No | `127.0.0.1` |
125
+ | `MCP_ALLOWED_ORIGINS` | Comma-separated origins for CORS. **Set for production.** | No | (none) |
126
+ | **`MCP_AUTH_SECRET_KEY`** | 32+ char secret for JWT auth. **Required for HTTP.** | **Yes (if HTTP)** | `undefined` |
127
+ | `MCP_LOG_LEVEL` | Logging level (`debug`, `info`, `error`, etc.). | No | `info` |
128
+ | `OBSIDIAN_VERIFY_SSL` | Set to `false` to disable SSL verification. | No | `true` |
129
+ | `OBSIDIAN_ENABLE_CACHE` | Set to `true` to enable the in-memory vault cache. | No | `true` |
130
+ | `OBSIDIAN_CACHE_REFRESH_INTERVAL_MIN` | Refresh interval for the vault cache in minutes. | No | `10` |
131
+
132
+ ### Connecting to the Obsidian API
133
+
134
+ To connect the MCP server to your Obsidian vault, you need to configure the base URL (`OBSIDIAN_BASE_URL`) and API key (`OBSIDIAN_API_KEY`). The Obsidian Local REST API plugin offers two ways to connect:
135
+
136
+ 1. **Encrypted (HTTPS) - Default**:
137
+
138
+ - The plugin provides a secure `https://` endpoint (e.g., `https://127.0.0.1:27124`).
139
+ - This uses a self-signed certificate, which will cause connection errors by default.
140
+ - **To fix this**, you must set the `OBSIDIAN_VERIFY_SSL` environment variable to `"false"`. This tells the server to trust the self-signed certificate.
141
+
142
+ 2. **Non-encrypted (HTTP) - Recommended for Simplicity**:
143
+ - In the plugin's settings within Obsidian, you can enable the "Non-encrypted (HTTP) Server".
144
+ - This provides a simpler `http://` endpoint (e.g., `http://127.0.0.1:27123`).
145
+ - When using this URL, you do not need to worry about SSL verification.
146
+
147
+ **Example `env` configuration for your MCP client:**
148
+
149
+ _Using the non-encrypted HTTP URL (recommended):_
54
150
 
55
- 3. Configure the server using environment variables and run it (see Configuration section below).
151
+ ```json
152
+ "env": {
153
+ "OBSIDIAN_API_KEY": "YOUR_API_KEY_FROM_OBSIDIAN_PLUGIN",
154
+ "OBSIDIAN_BASE_URL": "http://127.0.0.1:27123"
155
+ }
156
+ ```
56
157
 
57
- ## ⚙️ Configuration
158
+ _Using the encrypted HTTPS URL:_
58
159
 
59
- Add to your MCP client settings (e.g., `claude_desktop_config.json` or `cline_mcp_settings.json`):
160
+ ```json
161
+ "env": {
162
+ "OBSIDIAN_API_KEY": "YOUR_API_KEY_FROM_OBSIDIAN_PLUGIN",
163
+ "OBSIDIAN_BASE_URL": "https://127.0.0.1:27124",
164
+ "OBSIDIAN_VERIFY_SSL": "false"
165
+ }
166
+ ```
167
+
168
+ ### MCP Client Settings
169
+
170
+ Add to your MCP client settings (e.g., `cline_mcp_settings.json`):
60
171
 
61
172
  ```json
62
173
  {
63
174
  "mcpServers": {
64
175
  "obsidian-mcp-server": {
65
176
  "command": "node",
66
- "args": ["/path/to/obsidian-mcp-server/build/index.js"],
177
+ "args": ["/path/to/your/obsidian-mcp-server/dist/index.js"],
67
178
  "env": {
68
- "OBSIDIAN_API_KEY": "your_api_key_here",
69
- "VERIFY_SSL": "false",
70
- "OBSIDIAN_PROTOCOL": "https",
71
- "OBSIDIAN_HOST": "127.0.0.1",
72
- "OBSIDIAN_PORT": "27124",
73
- "REQUEST_TIMEOUT": "5000",
74
- "MAX_CONTENT_LENGTH": "52428800",
75
- "MAX_BODY_LENGTH": "52428800",
76
- "RATE_LIMIT_WINDOW_MS": "900000",
77
- "RATE_LIMIT_MAX_REQUESTS": "200",
78
- "TOOL_TIMEOUT_MS": "60000"
179
+ "OBSIDIAN_API_KEY": "YOUR_OBSIDIAN_API_KEY",
180
+ "OBSIDIAN_BASE_URL": "http://127.0.0.1:27123",
181
+ "OBSIDIAN_VERIFY_SSL": "false",
182
+ "OBSIDIAN_ENABLE_CACHE": "true"
79
183
  }
80
184
  }
81
185
  }
82
186
  }
83
187
  ```
84
188
 
85
- **Environment Variables:**
86
-
87
- - `OBSIDIAN_API_KEY` (Required): Your API key from Obsidian's Local REST API plugin settings.
88
- - `VERIFY_SSL` (Default: `false`): Enable SSL verification. Set to `false` for self-signed certificates or local use.
89
- - `OBSIDIAN_PROTOCOL` (Default: `"https"`): Protocol (`http` or `https`).
90
- - `OBSIDIAN_HOST` (Default: `"127.0.0.1"`): Host address.
91
- - `OBSIDIAN_PORT` (Default: `27124`): Port number.
92
- - `REQUEST_TIMEOUT` (Default: `5000`): Request timeout (ms).
93
- - `MAX_CONTENT_LENGTH` (Default: `52428800` [50MB]): Max response content length (bytes).
94
- - `MAX_BODY_LENGTH` (Default: `52428800` [50MB]): Max request body length (bytes).
95
- - `RATE_LIMIT_WINDOW_MS` (Default: `900000` [15 min]): Rate limit window (ms).
96
- - `RATE_LIMIT_MAX_REQUESTS` (Default: `200`): Max requests per window.
97
- - `TOOL_TIMEOUT_MS` (Default: `60000` [1 min]): Tool execution timeout (ms).
98
-
99
- ## 🛠️ Tools
100
-
101
- | Tool | Description | Parameters |
102
- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103
- | **obsidian_list_files_in_vault** | Lists all files and directories within the root of your Obsidian vault. Returns a hierarchical structure detailing files, folders, and their types. | None |
104
- | **obsidian_list_files_in_dir** | Lists files and directories within a specific folder in your Obsidian vault. Returns a hierarchical structure. Note: Empty directories may not be included in the results. Useful for exploring vault organization. | `dirpath*`: Path to list files from (relative to vault root). Note that empty directories will not be returned. |
105
- | **obsidian_get_file_contents** | Retrieves the full content of a specified file within your Obsidian vault. Supports various readable file formats. | `filepath*`: Path to the relevant file (relative to your vault root). |
106
- | **obsidian_append_content** | Appends the provided content to the end of a specified file in the vault. If the file does not exist, it will be created. | `filepath*`: Path to the file (relative to vault root)<br>`content*`: Content to append to the file |
107
- | **obsidian_update_content** | Overwrites the entire content of a specified file in the vault with the provided content. If the file does not exist, it will be created. | `filepath*`: Path to the file (relative to vault root)<br>`content*`: The new, complete content for the file (overwrites existing content). |
108
- | **obsidian_find_in_file** | Performs a full-text search across all files in your Obsidian vault. Returns matching files with context around each match. If more than 5 files match, only filenames and match counts are returned to avoid excessive output. Ideal for locating specific text, tags, or patterns. | `query*`: Text pattern to search for. Can include tags, keywords, or phrases.<br>`contextLength`: Number of characters surrounding each match to provide context (default: 10). |
109
- | **obsidian_complex_search** | Finds files based on path patterns using JsonLogic queries. Primarily supports `glob` for pattern matching (e.g., '\*.md') and `var` for accessing the 'path' variable. Note: For content-based searches (full-text, tags within content, dates), use `obsidian_find_in_file`. | `query*`: A JsonLogic query object targeting file paths. Example: `{"glob": ["*.md", {"var": "path"}]}` matches all markdown files. |
110
- | **obsidian_get_tags** | Retrieves all tags defined in the YAML frontmatter of markdown files within your Obsidian vault, along with their usage counts and associated file paths. Optionally, limit the search to a specific folder. | `path`: Optional folder path (relative to vault root) to restrict the tag search. |
111
- | **obsidian_get_properties** | Retrieves properties (like title, tags, status) from the YAML frontmatter of a specified Obsidian note. Returns all defined properties, including any custom fields. | `filepath*`: Path to the note file (relative to vault root) |
112
- | **obsidian_update_properties** | Updates properties within the YAML frontmatter of a specified Obsidian note. By default, array properties (like tags, type, status) are merged; use the 'replace' option to overwrite them instead. Handles custom fields and manages timestamps automatically. See schema for supported standard fields (title, author, tags, status, etc.). | `filepath*`: Path to the note file (relative to vault root)<br>`properties*`: Properties to update<br>`replace`: If true, array properties (like tags, status) will be completely replaced with the provided values instead of being merged with existing values. Defaults to false (merge). |
113
-
114
- ## 🔗 Resources
115
-
116
- | Resource | Description | Returns |
117
- | ------------------- | ----------------------------------------------------------------------- | ---------------- |
118
- | **obsidian://tags** | List of all tags used across the Obsidian vault with their usage counts | application/json |
119
-
120
- ## 📁 Project Structure
121
-
122
- The project follows a modular architecture with clear separation of concerns:
189
+ ## Project Structure
190
+
191
+ The codebase follows a modular structure within the `src/` directory:
123
192
 
124
193
  ```
125
194
  src/
126
- ├── index.ts # Main entry point
127
- ├── mcp/ # MCP server implementation
128
- ├── obsidian/ # Obsidian API client and types
129
- ├── resources/ # MCP resource implementations
130
- ├── tools/ # MCP tool implementations
131
- │ ├── files/ # File operations tools
132
- │ ├── search/ # Search tools
133
- │ └── properties/ # Property management tools
134
- └── utils/ # Shared utilities
195
+ ├── index.ts # Entry point: Initializes and starts the server
196
+ ├── config/ # Configuration loading (env vars, package info)
197
+ │ └── index.ts
198
+ ├── mcp-server/ # Core MCP server logic and capability registration
199
+ ├── server.ts # Server setup, transport handling, tool/resource registration
200
+ │ ├── resources/ # MCP Resource implementations (currently none)
201
+ │ ├── tools/ # MCP Tool implementations (subdirs per tool)
202
+ │ └── transports/ # Stdio and HTTP transport logic, auth middleware
203
+ ├── services/ # Abstractions for external APIs or internal caching
204
+ │ └── obsidianRestAPI/ # Typed client for Obsidian Local REST API
205
+ ├── types-global/ # Shared TypeScript type definitions (errors, etc.)
206
+ └── utils/ # Common utility functions (logger, error handler, security, etc.)
135
207
  ```
136
208
 
137
- ## 👥 Contributing
209
+ For a detailed file tree, run `npm run tree` or see [docs/tree.md](docs/tree.md).
210
+
211
+ ## Vault Cache Service
212
+
213
+ This server includes an intelligent **in-memory cache** designed to enhance performance and resilience when interacting with your vault.
214
+
215
+ ### Purpose and Benefits
216
+
217
+ - **Performance**: By caching file content and metadata, the server can perform search operations much faster, especially in large vaults. This reduces the number of direct requests to the Obsidian Local REST API, resulting in a snappier experience.
218
+ - **Resilience**: The cache acts as a fallback for the `obsidian_global_search` tool. If the live API search fails or times out, the server seamlessly uses the cache to provide results, ensuring that search functionality remains available even if the Obsidian API is temporarily unresponsive.
219
+ - **Efficiency**: The cache is designed to be efficient. It performs an initial build on startup and then periodically refreshes in the background by checking for file modifications, ensuring it stays reasonably up-to-date without constant, heavy API polling.
220
+
221
+ ### How It Works
222
+
223
+ 1. **Initialization**: When enabled, the `VaultCacheService` builds an in-memory map of all `.md` files in your vault, storing their content and modification times.
224
+ 2. **Periodic Refresh**: The cache automatically refreshes at a configurable interval (defaulting to 10 minutes). During a refresh, it only fetches content for files that are new or have been modified since the last check.
225
+ 3. **Proactive Updates**: After a file is modified through a tool like `obsidian_update_file`, the service proactively updates the cache for that specific file, ensuring immediate consistency.
226
+ 4. **Search Fallback**: The `obsidian_global_search` tool first attempts a live API search. If this fails, it automatically falls back to searching the in-memory cache.
227
+
228
+ ### Configuration
229
+
230
+ The cache is enabled by default but can be configured via environment variables:
138
231
 
139
- 1. Fork the repository
140
- 2. Create a feature branch
141
- 3. Submit a Pull Request
232
+ - **`OBSIDIAN_ENABLE_CACHE`**: Set to `true` (default) or `false` to enable or disable the cache service.
233
+ - **`OBSIDIAN_CACHE_REFRESH_INTERVAL_MIN`**: Defines the interval in minutes for the periodic background refresh. Defaults to `10`.
142
234
 
143
- For bugs and features, create an issue at [https://github.com/cyanheads/obsidian-mcp-server/issues](https://github.com/cyanheads/obsidian-mcp-server/issues).
235
+ ## Tools
144
236
 
145
- ## 📄 License
237
+ The Obsidian MCP Server provides a suite of tools for interacting with your vault, callable via the Model Context Protocol.
238
+
239
+ | Tool Name | Description | Key Arguments |
240
+ | :---------------------------- | :-------------------------------------------------------- | :------------------------------------------------------------ |
241
+ | `obsidian_read_file` | Retrieves the content and metadata of a file. | `filePath`, `format?`, `includeStat?` |
242
+ | `obsidian_update_file` | Modifies a file by appending, prepending, or overwriting. | `targetType`, `content`, `targetIdentifier?`, `wholeFileMode` |
243
+ | `obsidian_search_replace` | Performs search-and-replace operations in a note. | `targetType`, `replacements`, `useRegex?`, `replaceAll?` |
244
+ | `obsidian_global_search` | Searches the entire vault for content. | `query`, `searchInPath?`, `useRegex?`, `page?`, `pageSize?` |
245
+ | `obsidian_list_files` | Lists files and subdirectories in a folder. | `dirPath`, `fileExtensionFilter?`, `nameRegexFilter?` |
246
+ | `obsidian_manage_frontmatter` | Gets, sets, or deletes keys in a note's frontmatter. | `filePath`, `operation`, `key`, `value?` |
247
+ | `obsidian_manage_tags` | Adds, removes, or lists tags in a note. | `filePath`, `operation`, `tags` |
248
+ | `obsidian_delete_file` | Permanently deletes a file from the vault. | `filePath` |
249
+
250
+ _Note: All tools support comprehensive error handling and return structured JSON responses._
251
+
252
+ ## Resources
253
+
254
+ **MCP Resources are not implemented in this version.**
255
+
256
+ This server currently focuses on providing interactive tools for vault manipulation. Future development may introduce resource capabilities (e.g., exposing notes or search results as readable resources).
257
+
258
+ ## Development
259
+
260
+ ### Build and Test
261
+
262
+ ```bash
263
+ # Build the project (compile TS to JS in dist/ and make executable)
264
+ npm run build
265
+
266
+ # Format code using Prettier
267
+ npm run format
268
+
269
+ # Test the server locally using stdio transport
270
+ npm start
271
+ # or specifically:
272
+ npm run start:stdio
273
+
274
+ # Test the server locally using http transport
275
+ npm run start:http
276
+
277
+ # Generate a file tree representation for documentation (runs scripts/tree.ts)
278
+ npm run tree
279
+
280
+ # Clean build artifacts and then rebuild the project
281
+ npm run rebuild
282
+
283
+ # Fetch the Obsidian API spec (requires Obsidian running with Local REST API)
284
+ npm run fetch:spec http://127.0.0.1:27123/ docs/obsidian-api/obsidian_rest_api_spec
285
+
286
+ # Generate API documentation using TypeDoc
287
+ npm run docs:generate
288
+
289
+ # Inspect the server's capabilities using the MCP Inspector tool
290
+ npm run inspect:stdio
291
+ # or for the http transport:
292
+ npm run inspect:http
293
+ ```
146
294
 
147
- [![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
295
+ ## License
148
296
 
149
- Apache License 2.0
297
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
150
298
 
151
299
  ---
152
300
 
153
301
  <div align="center">
154
- Built with the Model Context Protocol
302
+ Built with the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a>
155
303
  </div>
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Main application configuration object.
3
+ */
4
+ export declare const config: {
5
+ pkg: {
6
+ name: string;
7
+ version: string;
8
+ };
9
+ mcpServerName: string;
10
+ mcpServerVersion: string;
11
+ logLevel: string;
12
+ logsPath: string;
13
+ environment: string;
14
+ mcpTransportType: "stdio" | "http";
15
+ mcpHttpPort: number;
16
+ mcpHttpHost: string;
17
+ mcpAllowedOrigins: string[] | undefined;
18
+ mcpAuthMode: "jwt" | "oauth" | undefined;
19
+ mcpAuthSecretKey: string | undefined;
20
+ oauthIssuerUrl: string | undefined;
21
+ oauthAudience: string | undefined;
22
+ oauthJwksUri: string | undefined;
23
+ obsidianApiKey: string;
24
+ obsidianBaseUrl: string;
25
+ obsidianVerifySsl: boolean;
26
+ obsidianCacheRefreshIntervalMin: number;
27
+ obsidianEnableCache: boolean;
28
+ obsidianApiSearchTimeoutMs: number;
29
+ };
30
+ /**
31
+ * The configured logging level for the application.
32
+ * Exported separately for convenience (e.g., logger initialization).
33
+ * @type {string}
34
+ */
35
+ export declare const logLevel: string;
36
+ /**
37
+ * The configured runtime environment for the application.
38
+ * Exported separately for convenience.
39
+ * @type {string}
40
+ */
41
+ export declare const environment: string;