obsidian-mcp-server 1.5.8 → 2.0.2

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 (221) hide show
  1. package/README.md +248 -104
  2. package/dist/config/index.d.ts +41 -0
  3. package/dist/config/index.js +191 -0
  4. package/dist/index.d.ts +1 -5
  5. package/dist/index.js +296 -18
  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 -8
  97. package/dist/utils/index.js +13 -9
  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 +58 -37
  133. package/dist/index.js.map +0 -1
  134. package/dist/mcp/handlers.d.ts +0 -29
  135. package/dist/mcp/handlers.js +0 -305
  136. package/dist/mcp/handlers.js.map +0 -1
  137. package/dist/mcp/index.d.ts +0 -6
  138. package/dist/mcp/index.js +0 -7
  139. package/dist/mcp/index.js.map +0 -1
  140. package/dist/mcp/server.d.ts +0 -18
  141. package/dist/mcp/server.js +0 -240
  142. package/dist/mcp/server.js.map +0 -1
  143. package/dist/mcp/types.d.ts +0 -70
  144. package/dist/mcp/types.js +0 -49
  145. package/dist/mcp/types.js.map +0 -1
  146. package/dist/obsidian/client.d.ts +0 -109
  147. package/dist/obsidian/client.js +0 -403
  148. package/dist/obsidian/client.js.map +0 -1
  149. package/dist/obsidian/errors.d.ts +0 -28
  150. package/dist/obsidian/errors.js +0 -75
  151. package/dist/obsidian/errors.js.map +0 -1
  152. package/dist/obsidian/index.d.ts +0 -6
  153. package/dist/obsidian/index.js +0 -7
  154. package/dist/obsidian/index.js.map +0 -1
  155. package/dist/obsidian/types.d.ts +0 -107
  156. package/dist/obsidian/types.js +0 -12
  157. package/dist/obsidian/types.js.map +0 -1
  158. package/dist/resources/index.d.ts +0 -13
  159. package/dist/resources/index.js +0 -15
  160. package/dist/resources/index.js.map +0 -1
  161. package/dist/resources/tags.d.ts +0 -39
  162. package/dist/resources/tags.js +0 -257
  163. package/dist/resources/tags.js.map +0 -1
  164. package/dist/resources/types.d.ts +0 -27
  165. package/dist/resources/types.js +0 -5
  166. package/dist/resources/types.js.map +0 -1
  167. package/dist/tools/base.d.ts +0 -46
  168. package/dist/tools/base.js +0 -88
  169. package/dist/tools/base.js.map +0 -1
  170. package/dist/tools/files/content.d.ts +0 -58
  171. package/dist/tools/files/content.js +0 -171
  172. package/dist/tools/files/content.js.map +0 -1
  173. package/dist/tools/files/index.d.ts +0 -14
  174. package/dist/tools/files/index.js +0 -22
  175. package/dist/tools/files/index.js.map +0 -1
  176. package/dist/tools/files/list.d.ts +0 -35
  177. package/dist/tools/files/list.js +0 -133
  178. package/dist/tools/files/list.js.map +0 -1
  179. package/dist/tools/index.d.ts +0 -21
  180. package/dist/tools/index.js +0 -31
  181. package/dist/tools/index.js.map +0 -1
  182. package/dist/tools/properties/index.d.ts +0 -14
  183. package/dist/tools/properties/index.js +0 -19
  184. package/dist/tools/properties/index.js.map +0 -1
  185. package/dist/tools/properties/manager.d.ts +0 -62
  186. package/dist/tools/properties/manager.js +0 -302
  187. package/dist/tools/properties/manager.js.map +0 -1
  188. package/dist/tools/properties/tools.d.ts +0 -47
  189. package/dist/tools/properties/tools.js +0 -239
  190. package/dist/tools/properties/tools.js.map +0 -1
  191. package/dist/tools/properties/types.d.ts +0 -141
  192. package/dist/tools/properties/types.js +0 -70
  193. package/dist/tools/properties/types.js.map +0 -1
  194. package/dist/tools/search/complex.d.ts +0 -38
  195. package/dist/tools/search/complex.js +0 -270
  196. package/dist/tools/search/complex.js.map +0 -1
  197. package/dist/tools/search/index.d.ts +0 -14
  198. package/dist/tools/search/index.js +0 -20
  199. package/dist/tools/search/index.js.map +0 -1
  200. package/dist/tools/search/simple.d.ts +0 -25
  201. package/dist/tools/search/simple.js +0 -127
  202. package/dist/tools/search/simple.js.map +0 -1
  203. package/dist/utils/errors.d.ts +0 -24
  204. package/dist/utils/errors.js +0 -59
  205. package/dist/utils/errors.js.map +0 -1
  206. package/dist/utils/idGenerator.d.ts +0 -15
  207. package/dist/utils/idGenerator.js +0 -21
  208. package/dist/utils/idGenerator.js.map +0 -1
  209. package/dist/utils/index.js.map +0 -1
  210. package/dist/utils/logging.d.ts +0 -245
  211. package/dist/utils/logging.js +0 -417
  212. package/dist/utils/logging.js.map +0 -1
  213. package/dist/utils/rate-limiting.d.ts +0 -50
  214. package/dist/utils/rate-limiting.js +0 -94
  215. package/dist/utils/rate-limiting.js.map +0 -1
  216. package/dist/utils/tokenization.d.ts +0 -28
  217. package/dist/utils/tokenization.js +0 -75
  218. package/dist/utils/tokenization.js.map +0 -1
  219. package/dist/utils/validation.d.ts +0 -22
  220. package/dist/utils/validation.js +0 -92
  221. package/dist/utils/validation.js.map +0 -1
package/README.md CHANGED
@@ -1,159 +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.8-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.2-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) |
18
- [Tools](#-tools) | [Resources](#-resources) | [Project Structure](#-project-structure) |
19
- [Contributing](#-contributing) | [Publishing](#-publishing) | [License](#-license)
18
+ This server equips your AI with specialized tools to interact with your Obsidian vault:
20
19
 
21
- ## 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. |
22
30
 
23
- - **File Operations**: Atomic file/directory operations with validation, resource monitoring, and error handling.
24
- - **Search System**: Full-text search with configurable context, advanced JsonLogic queries, glob patterns, and frontmatter field support.
25
- - **Property Management**: YAML frontmatter parsing, intelligent merging, automatic timestamps, and custom field support.
26
- - **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
27
79
 
28
- ## 🚀 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.
29
84
 
30
- 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)
31
86
 
32
- ### Option 1: Clone and Build (for development or direct use)
87
+ ```bash
88
+ npm install obsidian-mcp-server
89
+ ```
90
+
91
+ ### Install from Source
33
92
 
34
- 1. Enable the Local REST API plugin in Obsidian.
35
- 2. Clone the repository, install dependencies, and build the project:
93
+ 1. Clone the repository:
36
94
  ```bash
37
- git clone git@github.com:cyanheads/obsidian-mcp-server.git
95
+ git clone https://github.com/cyanheads/obsidian-mcp-server.git
38
96
  cd obsidian-mcp-server
97
+ ```
98
+ 2. Install dependencies:
99
+ ```bash
39
100
  npm install
101
+ ```
102
+ 3. Build the project:
103
+ ```bash
40
104
  npm run build
41
105
  ```
42
- 3. Configure the server using environment variables (see Configuration section below).
106
+ This compiles the TypeScript code to JavaScript in the `dist/` directory and makes the entry point executable.
43
107
 
44
- 4. Configure your MCP client settings (e.g., `claude_desktop_config.json` or `cline_mcp_settings.json`) to include the server. See the Configuration section for details.
108
+ ## Configuration
45
109
 
46
- ### Option 2: Install via npm (as a dependency or globally)
110
+ ### Environment Variables
47
111
 
48
- 1. Enable the Local REST API plugin in Obsidian.
49
- 2. Install the package using npm:
112
+ Configure the server using environment variables.
50
113
 
51
- ```bash
52
- # Install locally (e.g., within another project)
53
- npm install obsidian-mcp-server
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).
54
115
 
55
- # Or install globally
56
- npm install -g obsidian-mcp-server
57
- ```
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` |
58
131
 
59
- 3. Configure your MCP client settings (e.g., `claude_desktop_config.json` or `cline_mcp_settings.json`) to include the server. See the Configuration section for details.
132
+ ### Connecting to the Obsidian API
60
133
 
61
- ## ⚙️ Configuration
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:
62
135
 
63
- Add to your MCP client settings (e.g., `claude_desktop_config.json` or `cline_mcp_settings.json`):
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):_
150
+
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
+ ```
157
+
158
+ _Using the encrypted HTTPS URL:_
159
+
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`):
64
171
 
65
172
  ```json
66
173
  {
67
174
  "mcpServers": {
68
175
  "obsidian-mcp-server": {
69
176
  "command": "node",
70
- "args": ["/path/to/obsidian-mcp-server/dist/index.js"],
177
+ "args": ["/path/to/your/obsidian-mcp-server/dist/index.js"],
71
178
  "env": {
72
- "OBSIDIAN_API_KEY": "your_api_key_here",
73
- "VERIFY_SSL": "false",
74
- "OBSIDIAN_PROTOCOL": "https",
75
- "OBSIDIAN_HOST": "127.0.0.1",
76
- "OBSIDIAN_PORT": "27124",
77
- "REQUEST_TIMEOUT": "5000",
78
- "MAX_CONTENT_LENGTH": "52428800",
79
- "MAX_BODY_LENGTH": "52428800",
80
- "RATE_LIMIT_WINDOW_MS": "900000",
81
- "RATE_LIMIT_MAX_REQUESTS": "200",
82
- "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"
83
183
  }
84
184
  }
85
185
  }
86
186
  }
87
187
  ```
88
188
 
89
- **Environment Variables:**
90
-
91
- - `OBSIDIAN_API_KEY` (Required): Your API key from Obsidian's Local REST API plugin settings.
92
- - `VERIFY_SSL` (Default: `false`): Enable SSL verification. Set to `false` for self-signed certificates or local use.
93
- - `OBSIDIAN_PROTOCOL` (Default: `"https"`): Protocol (`http` or `https`).
94
- - `OBSIDIAN_HOST` (Default: `"127.0.0.1"`): Host address.
95
- - `OBSIDIAN_PORT` (Default: `27124`): Port number.
96
- - `REQUEST_TIMEOUT` (Default: `5000`): Request timeout (ms).
97
- - `MAX_CONTENT_LENGTH` (Default: `52428800` [50MB]): Max response content length (bytes).
98
- - `MAX_BODY_LENGTH` (Default: `52428800` [50MB]): Max request body length (bytes).
99
- - `RATE_LIMIT_WINDOW_MS` (Default: `900000` [15 min]): Rate limit window (ms).
100
- - `RATE_LIMIT_MAX_REQUESTS` (Default: `200`): Max requests per window.
101
- - `TOOL_TIMEOUT_MS` (Default: `60000` [1 min]): Tool execution timeout (ms).
102
-
103
- ## 🛠️ Tools
104
-
105
- | Tool | Description | Parameters |
106
- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
107
- | **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 |
108
- | **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. |
109
- | **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). |
110
- | **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 |
111
- | **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). |
112
- | **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). |
113
- | **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. |
114
- | **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. |
115
- | **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) |
116
- | **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). |
117
-
118
- ## 🔗 Resources
119
-
120
- | Resource | Description | Returns |
121
- | ------------------- | ----------------------------------------------------------------------- | ---------------- |
122
- | **obsidian://tags** | List of all tags used across the Obsidian vault with their usage counts | application/json |
123
-
124
- ## 📁 Project Structure
125
-
126
- 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:
127
192
 
128
193
  ```
129
194
  src/
130
- ├── index.ts # Main entry point
131
- ├── mcp/ # MCP server implementation
132
- ├── obsidian/ # Obsidian API client and types
133
- ├── resources/ # MCP resource implementations
134
- ├── tools/ # MCP tool implementations
135
- │ ├── files/ # File operations tools
136
- │ ├── search/ # Search tools
137
- │ └── properties/ # Property management tools
138
- └── 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.)
139
207
  ```
140
208
 
141
- ## 👥 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:
231
+
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
- 1. Fork the repository
144
- 2. Create a feature branch
145
- 3. Submit a Pull Request
235
+ ## Tools
146
236
 
147
- For bugs and features, create an issue at [https://github.com/cyanheads/obsidian-mcp-server/issues](https://github.com/cyanheads/obsidian-mcp-server/issues).
237
+ The Obsidian MCP Server provides a suite of tools for interacting with your vault, callable via the Model Context Protocol.
148
238
 
149
- ## 📄 License
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
+ ```
150
294
 
151
- [![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
295
+ ## License
152
296
 
153
- Apache License 2.0
297
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
154
298
 
155
299
  ---
156
300
 
157
301
  <div align="center">
158
- Built with the Model Context Protocol
302
+ Built with the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a>
159
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;