obsidian-mcp-server 2.0.7 → 3.1.0

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 (254) hide show
  1. package/CLAUDE.md +364 -0
  2. package/Dockerfile +99 -0
  3. package/LICENSE +4 -6
  4. package/README.md +246 -206
  5. package/changelog/3.0.x/3.0.0.md +102 -0
  6. package/changelog/3.1.x/3.1.0.md +26 -0
  7. package/changelog/template.md +51 -0
  8. package/dist/config/server-config.d.ts +19 -0
  9. package/dist/config/server-config.d.ts.map +1 -0
  10. package/dist/config/server-config.js +55 -0
  11. package/dist/config/server-config.js.map +1 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +23 -295
  15. package/dist/index.js.map +1 -0
  16. package/dist/mcp-server/prompts/definitions/index.d.ts +8 -0
  17. package/dist/mcp-server/prompts/definitions/index.d.ts.map +1 -0
  18. package/dist/mcp-server/prompts/definitions/index.js +8 -0
  19. package/dist/mcp-server/prompts/definitions/index.js.map +1 -0
  20. package/dist/mcp-server/resources/definitions/index.d.ts +36 -0
  21. package/dist/mcp-server/resources/definitions/index.d.ts.map +1 -0
  22. package/dist/mcp-server/resources/definitions/index.js +9 -0
  23. package/dist/mcp-server/resources/definitions/index.js.map +1 -0
  24. package/dist/mcp-server/resources/definitions/obsidian-status.resource.d.ts +23 -0
  25. package/dist/mcp-server/resources/definitions/obsidian-status.resource.d.ts.map +1 -0
  26. package/dist/mcp-server/resources/definitions/obsidian-status.resource.js +47 -0
  27. package/dist/mcp-server/resources/definitions/obsidian-status.resource.js.map +1 -0
  28. package/dist/mcp-server/resources/definitions/obsidian-tags.resource.d.ts +13 -0
  29. package/dist/mcp-server/resources/definitions/obsidian-tags.resource.d.ts.map +1 -0
  30. package/dist/mcp-server/resources/definitions/obsidian-tags.resource.js +30 -0
  31. package/dist/mcp-server/resources/definitions/obsidian-tags.resource.js.map +1 -0
  32. package/dist/mcp-server/resources/definitions/obsidian-vault-note.resource.d.ts +21 -0
  33. package/dist/mcp-server/resources/definitions/obsidian-vault-note.resource.d.ts.map +1 -0
  34. package/dist/mcp-server/resources/definitions/obsidian-vault-note.resource.js +38 -0
  35. package/dist/mcp-server/resources/definitions/obsidian-vault-note.resource.js.map +1 -0
  36. package/dist/mcp-server/tools/definitions/_shared/schemas.d.ts +45 -0
  37. package/dist/mcp-server/tools/definitions/_shared/schemas.d.ts.map +1 -0
  38. package/dist/mcp-server/tools/definitions/_shared/schemas.js +66 -0
  39. package/dist/mcp-server/tools/definitions/_shared/schemas.js.map +1 -0
  40. package/dist/mcp-server/tools/definitions/_shared/suggest-paths.d.ts +51 -0
  41. package/dist/mcp-server/tools/definitions/_shared/suggest-paths.d.ts.map +1 -0
  42. package/dist/mcp-server/tools/definitions/_shared/suggest-paths.js +120 -0
  43. package/dist/mcp-server/tools/definitions/_shared/suggest-paths.js.map +1 -0
  44. package/dist/mcp-server/tools/definitions/index.d.ts +582 -0
  45. package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -0
  46. package/dist/mcp-server/tools/definitions/index.js +40 -0
  47. package/dist/mcp-server/tools/definitions/index.js.map +1 -0
  48. package/dist/mcp-server/tools/definitions/obsidian-append-to-note.tool.d.ts +42 -0
  49. package/dist/mcp-server/tools/definitions/obsidian-append-to-note.tool.d.ts.map +1 -0
  50. package/dist/mcp-server/tools/definitions/obsidian-append-to-note.tool.js +58 -0
  51. package/dist/mcp-server/tools/definitions/obsidian-append-to-note.tool.js.map +1 -0
  52. package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.d.ts +46 -0
  53. package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.d.ts.map +1 -0
  54. package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.js +66 -0
  55. package/dist/mcp-server/tools/definitions/obsidian-delete-note.tool.js.map +1 -0
  56. package/dist/mcp-server/tools/definitions/obsidian-execute-command.tool.d.ts +19 -0
  57. package/dist/mcp-server/tools/definitions/obsidian-execute-command.tool.d.ts.map +1 -0
  58. package/dist/mcp-server/tools/definitions/obsidian-execute-command.tool.js +43 -0
  59. package/dist/mcp-server/tools/definitions/obsidian-execute-command.tool.js.map +1 -0
  60. package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.d.ts +92 -0
  61. package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.d.ts.map +1 -0
  62. package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.js +245 -0
  63. package/dist/mcp-server/tools/definitions/obsidian-get-note.tool.js.map +1 -0
  64. package/dist/mcp-server/tools/definitions/obsidian-list-commands.tool.d.ts +13 -0
  65. package/dist/mcp-server/tools/definitions/obsidian-list-commands.tool.d.ts.map +1 -0
  66. package/dist/mcp-server/tools/definitions/obsidian-list-commands.tool.js +38 -0
  67. package/dist/mcp-server/tools/definitions/obsidian-list-commands.tool.js.map +1 -0
  68. package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.d.ts +59 -0
  69. package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.d.ts.map +1 -0
  70. package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.js +273 -0
  71. package/dist/mcp-server/tools/definitions/obsidian-list-notes.tool.js.map +1 -0
  72. package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.d.ts +13 -0
  73. package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.d.ts.map +1 -0
  74. package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.js +38 -0
  75. package/dist/mcp-server/tools/definitions/obsidian-list-tags.tool.js.map +1 -0
  76. package/dist/mcp-server/tools/definitions/obsidian-manage-frontmatter.tool.d.ts +68 -0
  77. package/dist/mcp-server/tools/definitions/obsidian-manage-frontmatter.tool.d.ts.map +1 -0
  78. package/dist/mcp-server/tools/definitions/obsidian-manage-frontmatter.tool.js +178 -0
  79. package/dist/mcp-server/tools/definitions/obsidian-manage-frontmatter.tool.js.map +1 -0
  80. package/dist/mcp-server/tools/definitions/obsidian-manage-tags.tool.d.ts +77 -0
  81. package/dist/mcp-server/tools/definitions/obsidian-manage-tags.tool.d.ts.map +1 -0
  82. package/dist/mcp-server/tools/definitions/obsidian-manage-tags.tool.js +172 -0
  83. package/dist/mcp-server/tools/definitions/obsidian-manage-tags.tool.js.map +1 -0
  84. package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.d.ts +22 -0
  85. package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.d.ts.map +1 -0
  86. package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.js +88 -0
  87. package/dist/mcp-server/tools/definitions/obsidian-open-in-ui.tool.js.map +1 -0
  88. package/dist/mcp-server/tools/definitions/obsidian-patch-note.tool.d.ts +81 -0
  89. package/dist/mcp-server/tools/definitions/obsidian-patch-note.tool.d.ts.map +1 -0
  90. package/dist/mcp-server/tools/definitions/obsidian-patch-note.tool.js +83 -0
  91. package/dist/mcp-server/tools/definitions/obsidian-patch-note.tool.js.map +1 -0
  92. package/dist/mcp-server/tools/definitions/obsidian-replace-in-note.tool.d.ts +59 -0
  93. package/dist/mcp-server/tools/definitions/obsidian-replace-in-note.tool.d.ts.map +1 -0
  94. package/dist/mcp-server/tools/definitions/obsidian-replace-in-note.tool.js +167 -0
  95. package/dist/mcp-server/tools/definitions/obsidian-replace-in-note.tool.js.map +1 -0
  96. package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.d.ts +76 -0
  97. package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.d.ts.map +1 -0
  98. package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.js +244 -0
  99. package/dist/mcp-server/tools/definitions/obsidian-search-notes.tool.js.map +1 -0
  100. package/dist/mcp-server/tools/definitions/obsidian-write-note.tool.d.ts +48 -0
  101. package/dist/mcp-server/tools/definitions/obsidian-write-note.tool.d.ts.map +1 -0
  102. package/dist/mcp-server/tools/definitions/obsidian-write-note.tool.js +100 -0
  103. package/dist/mcp-server/tools/definitions/obsidian-write-note.tool.js.map +1 -0
  104. package/dist/services/obsidian/frontmatter-ops.d.ts +34 -0
  105. package/dist/services/obsidian/frontmatter-ops.d.ts.map +1 -0
  106. package/dist/services/obsidian/frontmatter-ops.js +230 -0
  107. package/dist/services/obsidian/frontmatter-ops.js.map +1 -0
  108. package/dist/services/obsidian/obsidian-service.d.ts +83 -0
  109. package/dist/services/obsidian/obsidian-service.d.ts.map +1 -0
  110. package/dist/services/obsidian/obsidian-service.js +435 -0
  111. package/dist/services/obsidian/obsidian-service.js.map +1 -0
  112. package/dist/services/obsidian/section-extractor.d.ts +13 -0
  113. package/dist/services/obsidian/section-extractor.d.ts.map +1 -0
  114. package/dist/services/obsidian/section-extractor.js +124 -0
  115. package/dist/services/obsidian/section-extractor.js.map +1 -0
  116. package/dist/services/obsidian/types.d.ts +91 -0
  117. package/dist/services/obsidian/types.d.ts.map +1 -0
  118. package/dist/services/obsidian/types.js +7 -0
  119. package/dist/services/obsidian/types.js.map +1 -0
  120. package/package.json +63 -69
  121. package/server.json +167 -0
  122. package/CHANGELOG.md +0 -124
  123. package/dist/config/index.d.ts +0 -41
  124. package/dist/config/index.js +0 -191
  125. package/dist/mcp-server/server.d.ts +0 -33
  126. package/dist/mcp-server/server.js +0 -211
  127. package/dist/mcp-server/tools/obsidianDeleteNoteTool/index.d.ts +0 -12
  128. package/dist/mcp-server/tools/obsidianDeleteNoteTool/index.js +0 -12
  129. package/dist/mcp-server/tools/obsidianDeleteNoteTool/logic.d.ts +0 -51
  130. package/dist/mcp-server/tools/obsidianDeleteNoteTool/logic.js +0 -168
  131. package/dist/mcp-server/tools/obsidianDeleteNoteTool/registration.d.ts +0 -19
  132. package/dist/mcp-server/tools/obsidianDeleteNoteTool/registration.js +0 -91
  133. package/dist/mcp-server/tools/obsidianGlobalSearchTool/index.d.ts +0 -12
  134. package/dist/mcp-server/tools/obsidianGlobalSearchTool/index.js +0 -12
  135. package/dist/mcp-server/tools/obsidianGlobalSearchTool/logic.d.ts +0 -77
  136. package/dist/mcp-server/tools/obsidianGlobalSearchTool/logic.js +0 -341
  137. package/dist/mcp-server/tools/obsidianGlobalSearchTool/registration.d.ts +0 -18
  138. package/dist/mcp-server/tools/obsidianGlobalSearchTool/registration.js +0 -69
  139. package/dist/mcp-server/tools/obsidianListNotesTool/index.d.ts +0 -12
  140. package/dist/mcp-server/tools/obsidianListNotesTool/index.js +0 -12
  141. package/dist/mcp-server/tools/obsidianListNotesTool/logic.d.ts +0 -68
  142. package/dist/mcp-server/tools/obsidianListNotesTool/logic.js +0 -215
  143. package/dist/mcp-server/tools/obsidianListNotesTool/registration.d.ts +0 -23
  144. package/dist/mcp-server/tools/obsidianListNotesTool/registration.js +0 -98
  145. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/index.d.ts +0 -3
  146. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/index.js +0 -2
  147. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/logic.d.ts +0 -42
  148. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/logic.js +0 -152
  149. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/registration.d.ts +0 -3
  150. package/dist/mcp-server/tools/obsidianManageFrontmatterTool/registration.js +0 -52
  151. package/dist/mcp-server/tools/obsidianManageTagsTool/index.d.ts +0 -3
  152. package/dist/mcp-server/tools/obsidianManageTagsTool/index.js +0 -2
  153. package/dist/mcp-server/tools/obsidianManageTagsTool/logic.d.ts +0 -28
  154. package/dist/mcp-server/tools/obsidianManageTagsTool/logic.js +0 -161
  155. package/dist/mcp-server/tools/obsidianManageTagsTool/registration.d.ts +0 -3
  156. package/dist/mcp-server/tools/obsidianManageTagsTool/registration.js +0 -52
  157. package/dist/mcp-server/tools/obsidianReadNoteTool/index.d.ts +0 -12
  158. package/dist/mcp-server/tools/obsidianReadNoteTool/index.js +0 -12
  159. package/dist/mcp-server/tools/obsidianReadNoteTool/logic.d.ts +0 -87
  160. package/dist/mcp-server/tools/obsidianReadNoteTool/logic.js +0 -216
  161. package/dist/mcp-server/tools/obsidianReadNoteTool/registration.d.ts +0 -20
  162. package/dist/mcp-server/tools/obsidianReadNoteTool/registration.js +0 -101
  163. package/dist/mcp-server/tools/obsidianSearchReplaceTool/index.d.ts +0 -12
  164. package/dist/mcp-server/tools/obsidianSearchReplaceTool/index.js +0 -12
  165. package/dist/mcp-server/tools/obsidianSearchReplaceTool/logic.d.ts +0 -255
  166. package/dist/mcp-server/tools/obsidianSearchReplaceTool/logic.js +0 -583
  167. package/dist/mcp-server/tools/obsidianSearchReplaceTool/registration.d.ts +0 -22
  168. package/dist/mcp-server/tools/obsidianSearchReplaceTool/registration.js +0 -111
  169. package/dist/mcp-server/tools/obsidianUpdateNoteTool/index.d.ts +0 -12
  170. package/dist/mcp-server/tools/obsidianUpdateNoteTool/index.js +0 -12
  171. package/dist/mcp-server/tools/obsidianUpdateNoteTool/logic.d.ts +0 -183
  172. package/dist/mcp-server/tools/obsidianUpdateNoteTool/logic.js +0 -490
  173. package/dist/mcp-server/tools/obsidianUpdateNoteTool/registration.d.ts +0 -21
  174. package/dist/mcp-server/tools/obsidianUpdateNoteTool/registration.js +0 -108
  175. package/dist/mcp-server/transports/auth/core/authContext.d.ts +0 -33
  176. package/dist/mcp-server/transports/auth/core/authContext.js +0 -24
  177. package/dist/mcp-server/transports/auth/core/authTypes.d.ts +0 -17
  178. package/dist/mcp-server/transports/auth/core/authTypes.js +0 -5
  179. package/dist/mcp-server/transports/auth/core/authUtils.d.ts +0 -18
  180. package/dist/mcp-server/transports/auth/core/authUtils.js +0 -45
  181. package/dist/mcp-server/transports/auth/index.d.ts +0 -10
  182. package/dist/mcp-server/transports/auth/index.js +0 -9
  183. package/dist/mcp-server/transports/auth/strategies/jwt/jwtMiddleware.d.ts +0 -27
  184. package/dist/mcp-server/transports/auth/strategies/jwt/jwtMiddleware.js +0 -149
  185. package/dist/mcp-server/transports/auth/strategies/oauth/oauthMiddleware.d.ts +0 -20
  186. package/dist/mcp-server/transports/auth/strategies/oauth/oauthMiddleware.js +0 -124
  187. package/dist/mcp-server/transports/httpErrorHandler.d.ts +0 -26
  188. package/dist/mcp-server/transports/httpErrorHandler.js +0 -73
  189. package/dist/mcp-server/transports/httpTransport.d.ts +0 -21
  190. package/dist/mcp-server/transports/httpTransport.js +0 -208
  191. package/dist/mcp-server/transports/stdioTransport.d.ts +0 -42
  192. package/dist/mcp-server/transports/stdioTransport.js +0 -63
  193. package/dist/services/obsidianRestAPI/index.d.ts +0 -15
  194. package/dist/services/obsidianRestAPI/index.js +0 -17
  195. package/dist/services/obsidianRestAPI/methods/activeFileMethods.d.ts +0 -38
  196. package/dist/services/obsidianRestAPI/methods/activeFileMethods.js +0 -62
  197. package/dist/services/obsidianRestAPI/methods/commandMethods.d.ts +0 -22
  198. package/dist/services/obsidianRestAPI/methods/commandMethods.js +0 -31
  199. package/dist/services/obsidianRestAPI/methods/openMethods.d.ts +0 -16
  200. package/dist/services/obsidianRestAPI/methods/openMethods.js +0 -21
  201. package/dist/services/obsidianRestAPI/methods/patchMethods.d.ts +0 -37
  202. package/dist/services/obsidianRestAPI/methods/patchMethods.js +0 -94
  203. package/dist/services/obsidianRestAPI/methods/periodicNoteMethods.d.ts +0 -42
  204. package/dist/services/obsidianRestAPI/methods/periodicNoteMethods.js +0 -66
  205. package/dist/services/obsidianRestAPI/methods/searchMethods.d.ts +0 -25
  206. package/dist/services/obsidianRestAPI/methods/searchMethods.js +0 -36
  207. package/dist/services/obsidianRestAPI/methods/vaultMethods.d.ts +0 -58
  208. package/dist/services/obsidianRestAPI/methods/vaultMethods.js +0 -144
  209. package/dist/services/obsidianRestAPI/service.d.ts +0 -195
  210. package/dist/services/obsidianRestAPI/service.js +0 -379
  211. package/dist/services/obsidianRestAPI/types.d.ts +0 -127
  212. package/dist/services/obsidianRestAPI/types.js +0 -7
  213. package/dist/services/obsidianRestAPI/vaultCache/index.d.ts +0 -4
  214. package/dist/services/obsidianRestAPI/vaultCache/index.js +0 -4
  215. package/dist/services/obsidianRestAPI/vaultCache/service.d.ts +0 -88
  216. package/dist/services/obsidianRestAPI/vaultCache/service.js +0 -299
  217. package/dist/types-global/errors.d.ts +0 -73
  218. package/dist/types-global/errors.js +0 -71
  219. package/dist/utils/index.d.ts +0 -5
  220. package/dist/utils/index.js +0 -13
  221. package/dist/utils/internal/asyncUtils.d.ts +0 -54
  222. package/dist/utils/internal/asyncUtils.js +0 -101
  223. package/dist/utils/internal/errorHandler.d.ts +0 -176
  224. package/dist/utils/internal/errorHandler.js +0 -351
  225. package/dist/utils/internal/index.d.ts +0 -4
  226. package/dist/utils/internal/index.js +0 -4
  227. package/dist/utils/internal/logger.d.ts +0 -141
  228. package/dist/utils/internal/logger.js +0 -406
  229. package/dist/utils/internal/requestContext.d.ts +0 -83
  230. package/dist/utils/internal/requestContext.js +0 -72
  231. package/dist/utils/metrics/index.d.ts +0 -1
  232. package/dist/utils/metrics/index.js +0 -1
  233. package/dist/utils/metrics/tokenCounter.d.ts +0 -27
  234. package/dist/utils/metrics/tokenCounter.js +0 -128
  235. package/dist/utils/obsidian/index.d.ts +0 -5
  236. package/dist/utils/obsidian/index.js +0 -5
  237. package/dist/utils/obsidian/obsidianApiUtils.d.ts +0 -14
  238. package/dist/utils/obsidian/obsidianApiUtils.js +0 -29
  239. package/dist/utils/obsidian/obsidianStatUtils.d.ts +0 -68
  240. package/dist/utils/obsidian/obsidianStatUtils.js +0 -143
  241. package/dist/utils/parsing/dateParser.d.ts +0 -56
  242. package/dist/utils/parsing/dateParser.js +0 -104
  243. package/dist/utils/parsing/index.d.ts +0 -2
  244. package/dist/utils/parsing/index.js +0 -3
  245. package/dist/utils/parsing/jsonParser.d.ts +0 -80
  246. package/dist/utils/parsing/jsonParser.js +0 -133
  247. package/dist/utils/security/idGenerator.d.ts +0 -140
  248. package/dist/utils/security/idGenerator.js +0 -194
  249. package/dist/utils/security/index.d.ts +0 -3
  250. package/dist/utils/security/index.js +0 -3
  251. package/dist/utils/security/rateLimiter.d.ts +0 -156
  252. package/dist/utils/security/rateLimiter.js +0 -235
  253. package/dist/utils/security/sanitization.d.ts +0 -244
  254. package/dist/utils/security/sanitization.js +0 -599
@@ -1,101 +0,0 @@
1
- import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
2
- import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
3
- import { ObsidianReadNoteInputSchema, processObsidianReadNote, } from "./logic.js";
4
- /**
5
- * Registers the 'obsidian_read_note' tool with the MCP server.
6
- *
7
- * This tool retrieves the content and optionally metadata of a specified file
8
- * within the user's Obsidian vault. It supports specifying the output format
9
- * ('markdown' or 'json') and includes a case-insensitive fallback mechanism
10
- * if the exact file path is not found initially.
11
- *
12
- * The response is a JSON string containing the file content in the requested format
13
- * and optionally formatted file statistics (timestamps, token count).
14
- *
15
- * @param {McpServer} server - The MCP server instance to register the tool with.
16
- * @param {ObsidianRestApiService} obsidianService - An instance of the Obsidian REST API service
17
- * used to interact with the user's Obsidian vault.
18
- * @returns {Promise<void>} A promise that resolves when the tool registration is complete or rejects on error.
19
- * @throws {McpError} Throws an McpError if registration fails critically.
20
- */
21
- export const registerObsidianReadNoteTool = async (server, obsidianService) => {
22
- const toolName = "obsidian_read_note";
23
- const toolDescription = "Retrieves the content and metadata of a specified file within the Obsidian vault. Tries the exact path first, then attempts a case-insensitive fallback. Returns an object containing the content (markdown string or full NoteJson object based on 'format'), and optionally formatted file stats ('stats' object with creationTime, modifiedTime, tokenCountEstimate). Use 'includeStat: true' with 'format: markdown' to include stats; stats are always included with 'format: json'.";
24
- // Create a context specifically for the registration process.
25
- const registrationContext = requestContextService.createRequestContext({
26
- operation: "RegisterObsidianReadNoteTool",
27
- toolName: toolName,
28
- module: "ObsidianReadNoteRegistration", // Identify the module
29
- });
30
- logger.info(`Attempting to register tool: ${toolName}`, registrationContext);
31
- // Wrap the registration logic in a tryCatch block for robust error handling during server setup.
32
- await ErrorHandler.tryCatch(async () => {
33
- // Use the high-level SDK method `server.tool` for registration.
34
- // It handles schema generation from the shape, basic validation, and routing.
35
- server.tool(toolName, toolDescription, ObsidianReadNoteInputSchema.shape, // Provide the Zod schema shape for input definition.
36
- /**
37
- * The handler function executed when the 'obsidian_read_note' tool is called by the client.
38
- *
39
- * @param {ObsidianReadNoteInput} params - The input parameters received from the client,
40
- * validated against the ObsidianReadNoteInputSchema shape. Note: The handler receives the raw input;
41
- * stricter validation against the full schema should happen inside if needed, though in this case,
42
- * the shape and the full schema are identical.
43
- * @returns {Promise<CallToolResult>} A promise resolving to the structured result for the MCP client,
44
- * containing either the successful response data (serialized JSON) or an error indication.
45
- */
46
- async (params) => {
47
- // Type matches the inferred input schema
48
- // Create a specific context for this handler invocation.
49
- const handlerContext = requestContextService.createRequestContext({
50
- parentContext: registrationContext, // Link to registration context
51
- operation: "HandleObsidianReadNoteRequest",
52
- toolName: toolName,
53
- params: {
54
- // Log key parameters for debugging
55
- filePath: params.filePath,
56
- format: params.format,
57
- includeStat: params.includeStat,
58
- },
59
- });
60
- logger.debug(`Handling '${toolName}' request`, handlerContext);
61
- // Wrap the core logic execution in a tryCatch block.
62
- return await ErrorHandler.tryCatch(async () => {
63
- // Delegate the actual file reading logic to the dedicated processing function.
64
- // Pass the (already shape-validated) parameters, context, and the Obsidian service.
65
- // The process function handles the refined validation internally if needed, but here shape = refined.
66
- const response = await processObsidianReadNote(params, // Pass params directly as shape matches refined schema
67
- handlerContext, obsidianService);
68
- logger.debug(`'${toolName}' processed successfully`, handlerContext);
69
- // Format the successful response object from the logic function into the required MCP CallToolResult structure.
70
- // The entire response object (containing content and optional stat) is serialized to JSON.
71
- return {
72
- content: [
73
- {
74
- type: "text", // Standard content type for structured JSON data
75
- text: JSON.stringify(response, null, 2), // Pretty-print JSON
76
- },
77
- ],
78
- isError: false, // Indicate successful execution
79
- };
80
- }, {
81
- // Configuration for the inner error handler (processing logic).
82
- operation: `processing ${toolName} handler`,
83
- context: handlerContext,
84
- input: params, // Log the full input parameters if an error occurs.
85
- // Custom error mapping for consistent error reporting.
86
- errorMapper: (error) => new McpError(error instanceof McpError
87
- ? error.code
88
- : BaseErrorCode.INTERNAL_ERROR, `Error processing ${toolName} tool: ${error instanceof Error ? error.message : "Unknown error"}`, { ...handlerContext }),
89
- }); // End of inner ErrorHandler.tryCatch
90
- }); // End of server.tool call
91
- logger.info(`Tool registered successfully: ${toolName}`, registrationContext);
92
- }, {
93
- // Configuration for the outer error handler (registration process).
94
- operation: `registering tool ${toolName}`,
95
- context: registrationContext,
96
- errorCode: BaseErrorCode.INTERNAL_ERROR, // Default error code for registration failure.
97
- // Custom error mapping for registration failures.
98
- errorMapper: (error) => new McpError(error instanceof McpError ? error.code : BaseErrorCode.INTERNAL_ERROR, `Failed to register tool '${toolName}': ${error instanceof Error ? error.message : "Unknown error"}`, { ...registrationContext }),
99
- critical: true, // Treat registration failure as critical.
100
- }); // End of outer ErrorHandler.tryCatch
101
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * @fileoverview Barrel file for the 'obsidian_search_replace' MCP tool.
3
- *
4
- * This file serves as the public entry point for the obsidian_search_replace tool module.
5
- * It re-exports the primary registration function (`registerObsidianSearchReplaceTool`)
6
- * from the './registration.js' module. This pattern simplifies imports for consumers
7
- * of the tool, allowing them to import necessary components from a single location.
8
- *
9
- * Consumers (like the main server setup) should import the registration function
10
- * from this file to integrate the tool into the MCP server instance.
11
- */
12
- export { registerObsidianSearchReplaceTool } from "./registration.js";
@@ -1,12 +0,0 @@
1
- /**
2
- * @fileoverview Barrel file for the 'obsidian_search_replace' MCP tool.
3
- *
4
- * This file serves as the public entry point for the obsidian_search_replace tool module.
5
- * It re-exports the primary registration function (`registerObsidianSearchReplaceTool`)
6
- * from the './registration.js' module. This pattern simplifies imports for consumers
7
- * of the tool, allowing them to import necessary components from a single location.
8
- *
9
- * Consumers (like the main server setup) should import the registration function
10
- * from this file to integrate the tool into the MCP server instance.
11
- */
12
- export { registerObsidianSearchReplaceTool } from "./registration.js";
@@ -1,255 +0,0 @@
1
- import { z } from "zod";
2
- import { ObsidianRestApiService, VaultCacheService } from "../../../services/obsidianRestAPI/index.js";
3
- import { RequestContext } from "../../../utils/index.js";
4
- /**
5
- * Base Zod schema object containing fields common to the search/replace tool input.
6
- * This is used as the foundation for both the registration shape and the refined internal schema.
7
- */
8
- declare const BaseObsidianSearchReplaceInputSchema: z.ZodObject<{
9
- /** Specifies the target note: 'filePath', 'activeFile', or 'periodicNote'. */
10
- targetType: z.ZodEnum<["filePath", "activeFile", "periodicNote"]>;
11
- /**
12
- * Identifier for the target. Required and must be a vault-relative path if targetType is 'filePath'.
13
- * Required and must be a valid period string (e.g., 'daily') if targetType is 'periodicNote'.
14
- * Not used if targetType is 'activeFile'. The tool attempts a case-insensitive fallback if the exact filePath is not found.
15
- */
16
- targetIdentifier: z.ZodOptional<z.ZodString>;
17
- /** An array of one or more search/replace operations to perform sequentially on the note content. */
18
- replacements: z.ZodArray<z.ZodObject<{
19
- /** The exact string or regex pattern to search for within the note content. Cannot be empty. */
20
- search: z.ZodString;
21
- /** The string to replace each match with. An empty string effectively deletes the matched text. */
22
- replace: z.ZodString;
23
- }, "strip", z.ZodTypeAny, {
24
- replace: string;
25
- search: string;
26
- }, {
27
- replace: string;
28
- search: string;
29
- }>, "many">;
30
- /** If true, treats the 'search' field in each replacement block as a JavaScript regular expression pattern. Defaults to false (exact string matching). */
31
- useRegex: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
32
- /** If true (default), replaces all occurrences matching each search pattern within the note. If false, replaces only the first occurrence of each pattern. */
33
- replaceAll: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
34
- /** If true (default), the search operation is case-sensitive. If false, it's case-insensitive. Applies to both string and regex searches. */
35
- caseSensitive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
36
- /** If true (and useRegex is false), treats sequences of whitespace in the search string as matching one or more whitespace characters (\s+). Defaults to false. Cannot be true if useRegex is true. */
37
- flexibleWhitespace: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
38
- /** If true, ensures the search term matches only whole words by implicitly adding word boundaries (\b) around the pattern (unless boundaries already exist in regex). Applies to both regex and non-regex modes. Defaults to false. */
39
- wholeWord: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
40
- /** If true, includes the final content of the modified file in the response. Defaults to false. */
41
- returnContent: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
42
- }, "strip", z.ZodTypeAny, {
43
- caseSensitive: boolean;
44
- useRegex: boolean;
45
- targetType: "filePath" | "activeFile" | "periodicNote";
46
- replacements: {
47
- replace: string;
48
- search: string;
49
- }[];
50
- replaceAll: boolean;
51
- flexibleWhitespace: boolean;
52
- wholeWord: boolean;
53
- returnContent: boolean;
54
- targetIdentifier?: string | undefined;
55
- }, {
56
- targetType: "filePath" | "activeFile" | "periodicNote";
57
- replacements: {
58
- replace: string;
59
- search: string;
60
- }[];
61
- caseSensitive?: boolean | undefined;
62
- useRegex?: boolean | undefined;
63
- targetIdentifier?: string | undefined;
64
- replaceAll?: boolean | undefined;
65
- flexibleWhitespace?: boolean | undefined;
66
- wholeWord?: boolean | undefined;
67
- returnContent?: boolean | undefined;
68
- }>;
69
- /**
70
- * Refined Zod schema used internally within the tool's logic for strict validation.
71
- * It builds upon `BaseObsidianSearchReplaceInputSchema` and adds cross-field validation rules:
72
- * 1. Ensures `targetIdentifier` is provided and valid when required by `targetType`.
73
- * 2. Ensures `flexibleWhitespace` is not used concurrently with `useRegex`.
74
- */
75
- export declare const ObsidianSearchReplaceInputSchema: z.ZodEffects<z.ZodObject<{
76
- /** Specifies the target note: 'filePath', 'activeFile', or 'periodicNote'. */
77
- targetType: z.ZodEnum<["filePath", "activeFile", "periodicNote"]>;
78
- /**
79
- * Identifier for the target. Required and must be a vault-relative path if targetType is 'filePath'.
80
- * Required and must be a valid period string (e.g., 'daily') if targetType is 'periodicNote'.
81
- * Not used if targetType is 'activeFile'. The tool attempts a case-insensitive fallback if the exact filePath is not found.
82
- */
83
- targetIdentifier: z.ZodOptional<z.ZodString>;
84
- /** An array of one or more search/replace operations to perform sequentially on the note content. */
85
- replacements: z.ZodArray<z.ZodObject<{
86
- /** The exact string or regex pattern to search for within the note content. Cannot be empty. */
87
- search: z.ZodString;
88
- /** The string to replace each match with. An empty string effectively deletes the matched text. */
89
- replace: z.ZodString;
90
- }, "strip", z.ZodTypeAny, {
91
- replace: string;
92
- search: string;
93
- }, {
94
- replace: string;
95
- search: string;
96
- }>, "many">;
97
- /** If true, treats the 'search' field in each replacement block as a JavaScript regular expression pattern. Defaults to false (exact string matching). */
98
- useRegex: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
99
- /** If true (default), replaces all occurrences matching each search pattern within the note. If false, replaces only the first occurrence of each pattern. */
100
- replaceAll: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
101
- /** If true (default), the search operation is case-sensitive. If false, it's case-insensitive. Applies to both string and regex searches. */
102
- caseSensitive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
103
- /** If true (and useRegex is false), treats sequences of whitespace in the search string as matching one or more whitespace characters (\s+). Defaults to false. Cannot be true if useRegex is true. */
104
- flexibleWhitespace: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
105
- /** If true, ensures the search term matches only whole words by implicitly adding word boundaries (\b) around the pattern (unless boundaries already exist in regex). Applies to both regex and non-regex modes. Defaults to false. */
106
- wholeWord: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
107
- /** If true, includes the final content of the modified file in the response. Defaults to false. */
108
- returnContent: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
109
- }, "strip", z.ZodTypeAny, {
110
- caseSensitive: boolean;
111
- useRegex: boolean;
112
- targetType: "filePath" | "activeFile" | "periodicNote";
113
- replacements: {
114
- replace: string;
115
- search: string;
116
- }[];
117
- replaceAll: boolean;
118
- flexibleWhitespace: boolean;
119
- wholeWord: boolean;
120
- returnContent: boolean;
121
- targetIdentifier?: string | undefined;
122
- }, {
123
- targetType: "filePath" | "activeFile" | "periodicNote";
124
- replacements: {
125
- replace: string;
126
- search: string;
127
- }[];
128
- caseSensitive?: boolean | undefined;
129
- useRegex?: boolean | undefined;
130
- targetIdentifier?: string | undefined;
131
- replaceAll?: boolean | undefined;
132
- flexibleWhitespace?: boolean | undefined;
133
- wholeWord?: boolean | undefined;
134
- returnContent?: boolean | undefined;
135
- }>, {
136
- caseSensitive: boolean;
137
- useRegex: boolean;
138
- targetType: "filePath" | "activeFile" | "periodicNote";
139
- replacements: {
140
- replace: string;
141
- search: string;
142
- }[];
143
- replaceAll: boolean;
144
- flexibleWhitespace: boolean;
145
- wholeWord: boolean;
146
- returnContent: boolean;
147
- targetIdentifier?: string | undefined;
148
- }, {
149
- targetType: "filePath" | "activeFile" | "periodicNote";
150
- replacements: {
151
- replace: string;
152
- search: string;
153
- }[];
154
- caseSensitive?: boolean | undefined;
155
- useRegex?: boolean | undefined;
156
- targetIdentifier?: string | undefined;
157
- replaceAll?: boolean | undefined;
158
- flexibleWhitespace?: boolean | undefined;
159
- wholeWord?: boolean | undefined;
160
- returnContent?: boolean | undefined;
161
- }>;
162
- /**
163
- * The shape of the base input schema, used by `server.tool` for registration and initial validation.
164
- * @see BaseObsidianSearchReplaceInputSchema
165
- */
166
- export declare const ObsidianSearchReplaceInputSchemaShape: {
167
- /** Specifies the target note: 'filePath', 'activeFile', or 'periodicNote'. */
168
- targetType: z.ZodEnum<["filePath", "activeFile", "periodicNote"]>;
169
- /**
170
- * Identifier for the target. Required and must be a vault-relative path if targetType is 'filePath'.
171
- * Required and must be a valid period string (e.g., 'daily') if targetType is 'periodicNote'.
172
- * Not used if targetType is 'activeFile'. The tool attempts a case-insensitive fallback if the exact filePath is not found.
173
- */
174
- targetIdentifier: z.ZodOptional<z.ZodString>;
175
- /** An array of one or more search/replace operations to perform sequentially on the note content. */
176
- replacements: z.ZodArray<z.ZodObject<{
177
- /** The exact string or regex pattern to search for within the note content. Cannot be empty. */
178
- search: z.ZodString;
179
- /** The string to replace each match with. An empty string effectively deletes the matched text. */
180
- replace: z.ZodString;
181
- }, "strip", z.ZodTypeAny, {
182
- replace: string;
183
- search: string;
184
- }, {
185
- replace: string;
186
- search: string;
187
- }>, "many">;
188
- /** If true, treats the 'search' field in each replacement block as a JavaScript regular expression pattern. Defaults to false (exact string matching). */
189
- useRegex: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
190
- /** If true (default), replaces all occurrences matching each search pattern within the note. If false, replaces only the first occurrence of each pattern. */
191
- replaceAll: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
192
- /** If true (default), the search operation is case-sensitive. If false, it's case-insensitive. Applies to both string and regex searches. */
193
- caseSensitive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
194
- /** If true (and useRegex is false), treats sequences of whitespace in the search string as matching one or more whitespace characters (\s+). Defaults to false. Cannot be true if useRegex is true. */
195
- flexibleWhitespace: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
196
- /** If true, ensures the search term matches only whole words by implicitly adding word boundaries (\b) around the pattern (unless boundaries already exist in regex). Applies to both regex and non-regex modes. Defaults to false. */
197
- wholeWord: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
198
- /** If true, includes the final content of the modified file in the response. Defaults to false. */
199
- returnContent: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
200
- };
201
- /**
202
- * TypeScript type inferred from the base registration schema. Represents the raw input
203
- * received by the tool handler *before* refinement.
204
- * @see BaseObsidianSearchReplaceInputSchema
205
- */
206
- export type ObsidianSearchReplaceRegistrationInput = z.infer<typeof BaseObsidianSearchReplaceInputSchema>;
207
- /**
208
- * TypeScript type inferred from the *refined* input schema (`ObsidianSearchReplaceInputSchema`).
209
- * This type represents the validated and structured input used within the core processing logic.
210
- */
211
- export type ObsidianSearchReplaceInput = z.infer<typeof ObsidianSearchReplaceInputSchema>;
212
- /**
213
- * Represents the structure of file statistics after formatting, including
214
- * human-readable timestamps and an estimated token count.
215
- */
216
- type FormattedStat = {
217
- /** Creation time formatted as a standard date-time string. */
218
- createdTime: string;
219
- /** Last modified time formatted as a standard date-time string. */
220
- modifiedTime: string;
221
- /** Estimated token count of the file content (using tiktoken 'gpt-4o'). */
222
- tokenCountEstimate: number;
223
- };
224
- /**
225
- * Defines the structure of the successful response returned by the `processObsidianSearchReplace` function.
226
- * This object is typically serialized to JSON and sent back to the client.
227
- */
228
- export interface ObsidianSearchReplaceResponse {
229
- /** Indicates whether the operation was successful. */
230
- success: boolean;
231
- /** A human-readable message describing the outcome of the operation (e.g., number of replacements). */
232
- message: string;
233
- /** The total number of replacements made across all search/replace blocks. */
234
- totalReplacementsMade: number;
235
- /** Optional file statistics (creation/modification times, token count) if the file could be read after the update. */
236
- stats?: FormattedStat;
237
- /** Optional final content of the file, included only if `returnContent` was true in the request. */
238
- finalContent?: string;
239
- }
240
- /**
241
- * Processes the core logic for the 'obsidian_search_replace' tool.
242
- * Reads the target note content, performs a sequence of search and replace operations
243
- * based on the provided parameters (handling regex, case sensitivity, etc.),
244
- * writes the modified content back to Obsidian, retrieves the final state,
245
- * and constructs the response object.
246
- *
247
- * @param {ObsidianSearchReplaceInput} params - The validated input parameters conforming to the refined schema.
248
- * @param {RequestContext} context - The request context for logging and correlation.
249
- * @param {ObsidianRestApiService} obsidianService - The instance of the Obsidian REST API service.
250
- * @returns {Promise<ObsidianSearchReplaceResponse>} A promise resolving to the structured success response.
251
- * @throws {McpError} Throws an McpError if validation fails, reading/writing fails, or an unexpected error occurs during processing.
252
- */
253
- export declare const processObsidianSearchReplace: (params: ObsidianSearchReplaceInput, // Use the refined, validated type
254
- context: RequestContext, obsidianService: ObsidianRestApiService, vaultCacheService: VaultCacheService | undefined) => Promise<ObsidianSearchReplaceResponse>;
255
- export {};