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
@@ -1,403 +0,0 @@
1
- import axios from "axios";
2
- import { readFileSync } from "fs";
3
- import { Agent } from "node:https";
4
- import { dirname, join } from "path";
5
- import { fileURLToPath } from 'url';
6
- import { ObsidianError } from '../utils/errors.js';
7
- import { createLogger } from '../utils/logging.js';
8
- import { sanitizeHeader, validateFilePath } from '../utils/validation.js';
9
- import { createMissingAPIKeyMessage, handleAxiosError } from './errors.js';
10
- import { DEFAULT_OBSIDIAN_CONFIG } from './types.js';
11
- // Logger for the ObsidianClient
12
- const logger = createLogger('ObsidianClient');
13
- // Get package version for user agent
14
- const __filename = fileURLToPath(import.meta.url);
15
- const __dirname = dirname(__filename);
16
- const VERSION = (() => {
17
- try {
18
- // Look for package.json in the same directory as the built files
19
- const packagePath = join(__dirname, '..', '..', 'package.json');
20
- const pkg = JSON.parse(readFileSync(packagePath, 'utf-8'));
21
- return pkg.version;
22
- }
23
- catch (error) {
24
- // Try alternative location for development
25
- try {
26
- const devPackagePath = join(__dirname, '..', '..', '..', 'package.json');
27
- const pkg = JSON.parse(readFileSync(devPackagePath, 'utf-8'));
28
- return pkg.version;
29
- }
30
- catch (devError) {
31
- logger.warn('Could not read package.json version, using fallback');
32
- return '1.1.0'; // Fallback version
33
- }
34
- }
35
- })();
36
- /**
37
- * Client for interacting with the Obsidian Local REST API
38
- */
39
- export class ObsidianClient {
40
- client;
41
- config;
42
- /**
43
- * Create a new ObsidianClient
44
- * @param config Configuration for the client
45
- */
46
- constructor(config) {
47
- if (!config.apiKey) {
48
- throw new ObsidianError(createMissingAPIKeyMessage(), 40100 // Unauthorized
49
- );
50
- }
51
- // Determine if we're in a development environment
52
- const isDev = process.env.NODE_ENV === 'development' || !process.env.NODE_ENV;
53
- // Read environment variables with fallbacks
54
- const envConfig = {
55
- protocol: process.env.OBSIDIAN_PROTOCOL || DEFAULT_OBSIDIAN_CONFIG.protocol,
56
- host: process.env.OBSIDIAN_HOST || DEFAULT_OBSIDIAN_CONFIG.host,
57
- port: parseInt(process.env.OBSIDIAN_PORT || String(DEFAULT_OBSIDIAN_CONFIG.port)),
58
- verifySSL: process.env.VERIFY_SSL ? process.env.VERIFY_SSL === 'true' : (isDev ? false : true),
59
- timeout: parseInt(process.env.REQUEST_TIMEOUT || '5000'),
60
- maxContentLength: parseInt(process.env.MAX_CONTENT_LENGTH || String(50 * 1024 * 1024)),
61
- maxBodyLength: parseInt(process.env.MAX_BODY_LENGTH || String(50 * 1024 * 1024))
62
- };
63
- // Combine defaults with provided config and environment variables
64
- this.config = {
65
- protocol: envConfig.protocol,
66
- host: envConfig.host,
67
- port: envConfig.port,
68
- verifySSL: config.verifySSL ?? envConfig.verifySSL,
69
- apiKey: config.apiKey,
70
- timeout: config.timeout ?? envConfig.timeout,
71
- maxContentLength: config.maxContentLength ?? envConfig.maxContentLength,
72
- maxBodyLength: config.maxBodyLength ?? envConfig.maxBodyLength
73
- };
74
- // Configure HTTPS agent
75
- const httpsAgent = new Agent({
76
- rejectUnauthorized: this.config.verifySSL
77
- });
78
- const axiosConfig = {
79
- baseURL: this.getBaseUrl(),
80
- headers: {
81
- ...this.getHeaders(),
82
- // Security headers
83
- 'X-Content-Type-Options': 'nosniff',
84
- 'X-Frame-Options': 'DENY',
85
- 'X-XSS-Protection': '1; mode=block',
86
- 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
87
- },
88
- validateStatus: (status) => status >= 200 && status < 300,
89
- timeout: this.config.timeout,
90
- maxRedirects: 5,
91
- maxContentLength: this.config.maxContentLength,
92
- maxBodyLength: this.config.maxBodyLength,
93
- httpsAgent,
94
- // Additional security configurations
95
- xsrfCookieName: 'XSRF-TOKEN',
96
- xsrfHeaderName: 'X-XSRF-TOKEN',
97
- withCredentials: true,
98
- decompress: true
99
- };
100
- if (!this.config.verifySSL) {
101
- logger.warn("WARNING: SSL verification is disabled. While this works for development, it's not recommended for production.\n" +
102
- "To properly configure SSL certificates:\n" +
103
- "1. Go to Obsidian Settings > Local REST API\n" +
104
- "2. Under 'How to Access', copy the certificate\n" +
105
- "3. For Windows users:\n" +
106
- " - Open 'certmgr.msc' (Windows Certificate Manager)\n" +
107
- " - Go to 'Trusted Root Certification Authorities' > 'Certificates'\n" +
108
- " - Right-click > 'All Tasks' > 'Import' and follow the wizard\n" +
109
- " - Select the certificate file you copied from Obsidian\n" +
110
- "4. For other systems:\n" +
111
- " - macOS: Add to Keychain Access\n" +
112
- " - Linux: Add to ca-certificates");
113
- }
114
- this.client = axios.create(axiosConfig);
115
- }
116
- /**
117
- * Get the base URL for the Obsidian API
118
- */
119
- getBaseUrl() {
120
- return `${this.config.protocol}://${this.config.host}:${this.config.port}`;
121
- }
122
- /**
123
- * Get headers for requests to the Obsidian API
124
- */
125
- getHeaders() {
126
- const headers = {
127
- Authorization: `Bearer ${this.config.apiKey}`,
128
- 'Accept': 'application/json',
129
- 'User-Agent': `obsidian-mcp-server/${VERSION}`
130
- };
131
- // Sanitize headers
132
- return Object.fromEntries(Object.entries(headers).map(([key, value]) => [
133
- key,
134
- sanitizeHeader(value)
135
- ]));
136
- }
137
- /**
138
- * Safely execute an API request with error handling
139
- */
140
- async safeRequest(operation) {
141
- try {
142
- return await operation();
143
- }
144
- catch (error) {
145
- if (axios.isAxiosError(error)) {
146
- throw handleAxiosError(error, this.config.host, this.config.port);
147
- }
148
- if (error instanceof Error) {
149
- throw new ObsidianError(error.message, 50000, error);
150
- }
151
- throw new ObsidianError("Unknown error occurred", 50000, error);
152
- }
153
- }
154
- /**
155
- * List all files in the vault
156
- */
157
- async listFilesInVault() {
158
- return this.safeRequest(async () => {
159
- logger.debug('Listing all files in vault');
160
- const response = await this.client.get("/vault/");
161
- return response.data.files;
162
- });
163
- }
164
- /**
165
- * List files in a specific directory
166
- */
167
- async listFilesInDir(dirpath) {
168
- validateFilePath(dirpath);
169
- return this.safeRequest(async () => {
170
- logger.debug(`Listing files in directory: ${dirpath}`);
171
- const response = await this.client.get(`/vault/${dirpath}/`);
172
- return response.data.files;
173
- });
174
- }
175
- /**
176
- * Get the contents of a file
177
- */
178
- async getFileContents(filepath) {
179
- validateFilePath(filepath);
180
- return this.safeRequest(async () => {
181
- logger.debug(`Getting contents of file: ${filepath}`);
182
- const response = await this.client.get(`/vault/${filepath}`);
183
- return response.data;
184
- });
185
- }
186
- /**
187
- * Search for a string across all files
188
- */
189
- async search(query, contextLength = 100) {
190
- return this.safeRequest(async () => {
191
- logger.debug(`Searching for: ${query} with context length: ${contextLength}`);
192
- const response = await this.client.post("/search/simple/", null, { params: { query, contextLength } });
193
- return response.data;
194
- });
195
- }
196
- /**
197
- * Append content to a file
198
- */
199
- async appendContent(filepath, content) {
200
- validateFilePath(filepath);
201
- if (!content || typeof content !== 'string') {
202
- throw new ObsidianError('Invalid content: Content must be a non-empty string', 40003);
203
- }
204
- return this.safeRequest(async () => {
205
- logger.debug(`Appending content to file: ${filepath}`);
206
- await this.client.post(`/vault/${filepath}`, content, {
207
- headers: {
208
- "Content-Type": "text/markdown"
209
- }
210
- });
211
- });
212
- }
213
- /**
214
- * Update the entire content of a file
215
- */
216
- async updateContent(filepath, content) {
217
- validateFilePath(filepath);
218
- if (!content || typeof content !== 'string') {
219
- throw new ObsidianError('Invalid content: Content must be a non-empty string', 40003);
220
- }
221
- return this.safeRequest(async () => {
222
- logger.debug(`Updating content of file: ${filepath}`);
223
- await this.client.put(`/vault/${filepath}`, content, {
224
- headers: {
225
- "Content-Type": "text/markdown"
226
- }
227
- });
228
- });
229
- }
230
- /**
231
- * Execute a complex search using JsonLogic query
232
- */
233
- async searchJson(query) {
234
- return this.safeRequest(async () => {
235
- logger.debug(`Executing JSON search with query: ${JSON.stringify(query)}`);
236
- const isTagSearch = JSON.stringify(query).includes('"contains"') &&
237
- JSON.stringify(query).includes('"#"');
238
- const response = await this.client.post("/search/", query, {
239
- headers: {
240
- "Content-Type": "application/vnd.olrapi.jsonlogic+json",
241
- "Accept": "application/vnd.olrapi.note+json"
242
- }
243
- });
244
- return response.data;
245
- });
246
- }
247
- /**
248
- * Get server status
249
- */
250
- async getStatus() {
251
- return this.safeRequest(async () => {
252
- logger.debug('Getting server status');
253
- const response = await this.client.get("/");
254
- return response.data;
255
- });
256
- }
257
- /**
258
- * List available commands
259
- */
260
- async listCommands() {
261
- return this.safeRequest(async () => {
262
- logger.debug('Listing commands');
263
- const response = await this.client.get("/commands/");
264
- return response.data.commands;
265
- });
266
- }
267
- /**
268
- * Execute a command by ID
269
- */
270
- async executeCommand(commandId) {
271
- return this.safeRequest(async () => {
272
- logger.debug(`Executing command: ${commandId}`);
273
- await this.client.post(`/commands/${commandId}/`);
274
- });
275
- }
276
- /**
277
- * Open a file in Obsidian
278
- */
279
- async openFile(filepath, newLeaf = false) {
280
- validateFilePath(filepath);
281
- return this.safeRequest(async () => {
282
- logger.debug(`Opening file: ${filepath}, newLeaf: ${newLeaf}`);
283
- await this.client.post(`/open/${filepath}`, null, {
284
- params: { newLeaf }
285
- });
286
- });
287
- }
288
- /**
289
- * Get the currently active file
290
- */
291
- async getActiveFile() {
292
- return this.safeRequest(async () => {
293
- logger.debug('Getting active file');
294
- const response = await this.client.get("/active/", {
295
- headers: {
296
- "Accept": "application/vnd.olrapi.note+json"
297
- }
298
- });
299
- return response.data;
300
- });
301
- }
302
- /**
303
- * Update the active file
304
- */
305
- async updateActiveFile(content) {
306
- return this.safeRequest(async () => {
307
- logger.debug('Updating active file');
308
- await this.client.put("/active/", content, {
309
- headers: {
310
- "Content-Type": "text/markdown"
311
- }
312
- });
313
- });
314
- }
315
- /**
316
- * Delete the active file
317
- */
318
- async deleteActiveFile() {
319
- return this.safeRequest(async () => {
320
- logger.debug('Deleting active file');
321
- await this.client.delete("/active/");
322
- });
323
- }
324
- /**
325
- * Patch the active file
326
- */
327
- async patchActiveFile(operation, targetType, target, content, options) {
328
- return this.safeRequest(async () => {
329
- logger.debug(`Patching active file: ${operation} ${targetType} "${target}"`);
330
- const headers = {
331
- "Operation": operation,
332
- "Target-Type": targetType,
333
- "Target": target,
334
- "Content-Type": options?.contentType || "text/markdown"
335
- };
336
- if (options?.delimiter) {
337
- headers["Target-Delimiter"] = options.delimiter;
338
- }
339
- if (options?.trimWhitespace !== undefined) {
340
- headers["Trim-Target-Whitespace"] = options.trimWhitespace.toString();
341
- }
342
- await this.client.patch("/active/", content, { headers });
343
- });
344
- }
345
- /**
346
- * Get a periodic note (e.g., daily, weekly)
347
- */
348
- async getPeriodicNote(period) {
349
- return this.safeRequest(async () => {
350
- logger.debug(`Getting ${period} periodic note`);
351
- const response = await this.client.get(`/periodic/${period}/`, {
352
- headers: {
353
- "Accept": "application/vnd.olrapi.note+json"
354
- }
355
- });
356
- return response.data;
357
- });
358
- }
359
- /**
360
- * Update a periodic note
361
- */
362
- async updatePeriodicNote(period, content) {
363
- return this.safeRequest(async () => {
364
- logger.debug(`Updating ${period} periodic note`);
365
- await this.client.put(`/periodic/${period}/`, content, {
366
- headers: {
367
- "Content-Type": "text/markdown"
368
- }
369
- });
370
- });
371
- }
372
- /**
373
- * Delete a periodic note
374
- */
375
- async deletePeriodicNote(period) {
376
- return this.safeRequest(async () => {
377
- logger.debug(`Deleting ${period} periodic note`);
378
- await this.client.delete(`/periodic/${period}/`);
379
- });
380
- }
381
- /**
382
- * Patch a periodic note
383
- */
384
- async patchPeriodicNote(period, operation, targetType, target, content, options) {
385
- return this.safeRequest(async () => {
386
- logger.debug(`Patching ${period} periodic note: ${operation} ${targetType} "${target}"`);
387
- const headers = {
388
- "Operation": operation,
389
- "Target-Type": targetType,
390
- "Target": target,
391
- "Content-Type": options?.contentType || "text/markdown"
392
- };
393
- if (options?.delimiter) {
394
- headers["Target-Delimiter"] = options.delimiter;
395
- }
396
- if (options?.trimWhitespace !== undefined) {
397
- headers["Trim-Target-Whitespace"] = options.trimWhitespace.toString();
398
- }
399
- await this.client.patch(`/periodic/${period}/`, content, { headers });
400
- });
401
- }
402
- }
403
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/obsidian/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EAWxB,MAAM,YAAY,CAAC;AAEpB,gC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C;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CACrB,MAA0B,EAC1B,SAA2C,EAC3C,UAA+C,EAC/C,MAAc,EACd,OAAe,EACf,OAIC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE;YACjC,MAAM,CAAC,KAAK,CAAC,YAAY,MAAM,mBAAmB,SAAS,IAAI,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC;YACzF,MAAM,OAAO,GAA2B;gBACtC,WAAW,EAAE,SAAS;gBACtB,aAAa,EAAE,UAAU;gBACzB,QAAQ,EAAE,MAAM;gBAChB,cAAc,EAAE,OAAO,EAAE,WAAW,IAAI,eAAe;aACxD,CAAC;YAEF,IAAI,OAAO,EAAE,SAAS,EAAE,CAAC;gBACvB,OAAO,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;YAClD,CAAC;YACD,IAAI,OAAO,EAAE,cAAc,KAAK,SAAS,EAAE,CAAC;gBAC1C,OAAO,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YACxE,CAAC;YAED,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,MAAM,GAAG,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,28 +0,0 @@
1
- /**
2
- * Error handling for Obsidian client
3
- */
4
- import { AxiosError } from "axios";
5
- import type { ApiError } from '../utils/errors.js';
6
- import { ObsidianError } from '../utils/errors.js';
7
- /**
8
- * Helper function to create a descriptive error message for SSL certificate issues
9
- */
10
- export declare function createSSLErrorMessage(error: Error, config: {
11
- verifySSL: boolean;
12
- }): string;
13
- /**
14
- * Helper function to create a descriptive error message for connection refused issues
15
- */
16
- export declare function createConnectionRefusedMessage(host: string, port: number): string;
17
- /**
18
- * Helper function to create a descriptive error message for authentication failures
19
- */
20
- export declare function createAuthFailedMessage(): string;
21
- /**
22
- * Helper function to create a descriptive error message for missing API key
23
- */
24
- export declare function createMissingAPIKeyMessage(): string;
25
- /**
26
- * Helper function to handle Axios errors consistently
27
- */
28
- export declare function handleAxiosError(error: AxiosError<ApiError>, host: string, port: number): ObsidianError;
@@ -1,75 +0,0 @@
1
- import { ObsidianError, getErrorCodeFromStatus } from '../utils/errors.js';
2
- /**
3
- * Helper function to create a descriptive error message for SSL certificate issues
4
- */
5
- export function createSSLErrorMessage(error, config) {
6
- return (`SSL certificate verification failed. You have two options:\n\n` +
7
- `Option 1 - Enable HTTP (not recommended for production):\n` +
8
- `1. Go to Obsidian Settings > Local REST API\n` +
9
- `2. Enable "Enable Non-encrypted (HTTP) Server"\n` +
10
- `3. Update your client config to use "http" protocol\n\n` +
11
- `Option 2 - Configure HTTPS (recommended):\n` +
12
- `1. Go to Obsidian Settings > Local REST API\n` +
13
- `2. Under 'How to Access', copy the certificate\n` +
14
- `3. Add the certificate to your system's trusted certificates:\n` +
15
- ` - On macOS: Add to Keychain Access\n` +
16
- ` - On Windows: Add to Certificate Manager\n` +
17
- ` - On Linux: Add to ca-certificates\n` +
18
- ` For development only: Set verifySSL: false in client config\n\n` +
19
- `Original error: ${error.message}`);
20
- }
21
- /**
22
- * Helper function to create a descriptive error message for connection refused issues
23
- */
24
- export function createConnectionRefusedMessage(host, port) {
25
- return (`Connection refused. To fix this:\n` +
26
- `1. Ensure Obsidian is running\n` +
27
- `2. Verify the 'Local REST API' plugin is enabled in Obsidian Settings\n` +
28
- `3. Check that you're using the correct host (${host}) and port (${port})\n` +
29
- `4. Make sure HTTPS is enabled in the plugin settings`);
30
- }
31
- /**
32
- * Helper function to create a descriptive error message for authentication failures
33
- */
34
- export function createAuthFailedMessage() {
35
- return (`Authentication failed. To fix this:\n` +
36
- `1. Go to Obsidian Settings > Local REST API\n` +
37
- `2. Copy your API key from the settings\n` +
38
- `3. Update your configuration with the new API key\n` +
39
- `Note: The API key changes when you regenerate certificates`);
40
- }
41
- /**
42
- * Helper function to create a descriptive error message for missing API key
43
- */
44
- export function createMissingAPIKeyMessage() {
45
- return (`Missing API key. To fix this:\n` +
46
- `1. Install the 'Local REST API' plugin in Obsidian\n` +
47
- `2. Enable the plugin in Obsidian Settings\n` +
48
- `3. Copy your API key from Obsidian Settings > Local REST API\n` +
49
- `4. Provide the API key in your configuration`);
50
- }
51
- /**
52
- * Helper function to handle Axios errors consistently
53
- */
54
- export function handleAxiosError(error, host, port) {
55
- const response = error.response;
56
- const errorData = response?.data;
57
- // Handle common connection errors with helpful messages
58
- if (error.code === 'DEPTH_ZERO_SELF_SIGNED_CERT' || error.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE') {
59
- return new ObsidianError(createSSLErrorMessage(error, { verifySSL: true }), 50001, // SSL error code
60
- { code: error.code });
61
- }
62
- if (error.code === 'ECONNREFUSED') {
63
- return new ObsidianError(createConnectionRefusedMessage(host, port), 50002, // Connection refused
64
- { code: error.code });
65
- }
66
- if (response?.status === 401) {
67
- return new ObsidianError(createAuthFailedMessage(), 40100, // Unauthorized
68
- { code: error.code });
69
- }
70
- // For other errors, use API error code if available
71
- const errorCode = errorData?.errorCode ?? getErrorCodeFromStatus(response?.status ?? 500);
72
- const message = errorData?.message ?? error.message ?? "Unknown error";
73
- return new ObsidianError(message, errorCode, errorData);
74
- }
75
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/obsidian/errors.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE3E;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAY,EAAE,MAA8B;IAChF,OAAO,CACL,gEAAgE;QAChE,4DAA4D;QAC5D,+CAA+C;QAC/C,kDAAkD;QAClD,yDAAyD;QACzD,6CAA6C;QAC7C,+CAA+C;QAC/C,kDAAkD;QAClD,iEAAiE;QACjE,yCAA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EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CACrB,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,aAAa,CACtB,uBAAuB,EAAE,EACzB,KAAK,EAAE,eAAe;QACtB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CACrB,CAAC;IACJ,CAAC;IAED,oDAAoD;IACpD,MAAM,SAAS,GAAG,SAAS,EAAE,SAAS,IAAI,sBAAsB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC;IAC1F,MAAM,OAAO,GAAG,SAAS,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,IAAI,eAAe,CAAC;IACvE,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC1D,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Exports for the Obsidian module
3
- */
4
- export * from './client.js';
5
- export * from './errors.js';
6
- export * from './types.js';
@@ -1,7 +0,0 @@
1
- /**
2
- * Exports for the Obsidian module
3
- */
4
- export * from './client.js';
5
- export * from './errors.js';
6
- export * from './types.js';
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/obsidian/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
@@ -1,107 +0,0 @@
1
- /**
2
- * Type definitions for Obsidian client
3
- */
4
- /**
5
- * Configuration for the Obsidian client
6
- */
7
- export interface ObsidianConfig {
8
- apiKey: string;
9
- verifySSL?: boolean;
10
- timeout?: number;
11
- maxContentLength?: number;
12
- maxBodyLength?: number;
13
- }
14
- /**
15
- * Server configuration for Obsidian
16
- */
17
- export interface ObsidianServerConfig {
18
- protocol: "http" | "https";
19
- host: string;
20
- port: number;
21
- }
22
- /**
23
- * Default configuration for Obsidian server
24
- */
25
- export declare const DEFAULT_OBSIDIAN_CONFIG: ObsidianServerConfig;
26
- /**
27
- * JSON representation of an Obsidian note
28
- */
29
- export interface NoteJson {
30
- content: string;
31
- frontmatter: Record<string, unknown>;
32
- path: string;
33
- stat: {
34
- ctime: number;
35
- mtime: number;
36
- size: number;
37
- };
38
- tags: string[];
39
- }
40
- /**
41
- * Obsidian file/folder information
42
- */
43
- export interface ObsidianFile {
44
- path: string;
45
- type: "file" | "folder";
46
- children?: ObsidianFile[];
47
- }
48
- /**
49
- * Obsidian command
50
- */
51
- export interface ObsidianCommand {
52
- id: string;
53
- name: string;
54
- }
55
- /**
56
- * Obsidian server status
57
- */
58
- export interface ObsidianStatus {
59
- authenticated: boolean;
60
- ok: string;
61
- service: string;
62
- versions: {
63
- obsidian: string;
64
- self: string;
65
- };
66
- }
67
- /**
68
- * Period type for periodic notes
69
- */
70
- export interface PeriodType {
71
- type: "daily" | "weekly" | "monthly" | "quarterly" | "yearly";
72
- }
73
- /**
74
- * Search match with context
75
- */
76
- export interface SearchMatch {
77
- context: string;
78
- match: {
79
- start: number;
80
- end: number;
81
- };
82
- }
83
- /**
84
- * Standard search result
85
- */
86
- export interface SearchResult {
87
- filename: string;
88
- result: unknown;
89
- }
90
- /**
91
- * Simple search result with context
92
- */
93
- export interface SimpleSearchResult {
94
- filename: string;
95
- score: number;
96
- matches: SearchMatch[];
97
- }
98
- /**
99
- * Union type for search responses
100
- */
101
- export type SearchResponse = SearchResult | SimpleSearchResult;
102
- /**
103
- * JSON Logic query for complex searches
104
- */
105
- export interface JsonLogicQuery {
106
- [operator: string]: unknown;
107
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Type definitions for Obsidian client
3
- */
4
- /**
5
- * Default configuration for Obsidian server
6
- */
7
- export const DEFAULT_OBSIDIAN_CONFIG = {
8
- protocol: "https", // HTTPS required by default in Obsidian REST API plugin
9
- host: "127.0.0.1",
10
- port: 27124
11
- };
12
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/obsidian/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAsBH;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAyB;IAC3D,QAAQ,EAAE,OAAO,EAAE,wDAAwD;IAC3E,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,KAAK;CACH,CAAC"}