obsidian-mcp-server 1.5.4 → 1.5.7

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 (47) hide show
  1. package/Dockerfile +3 -2
  2. package/README.md +72 -212
  3. package/build/index.js +1 -1
  4. package/build/mcp/handlers.js +3 -6
  5. package/build/mcp/index.js +1 -1
  6. package/build/mcp/server.js +5 -5
  7. package/build/obsidian/client.js +5 -8
  8. package/build/obsidian/index.js +1 -1
  9. package/build/resources/index.js +1 -1
  10. package/build/resources/tags.js +36 -8
  11. package/build/tools/base.js +2 -2
  12. package/build/tools/files/content.js +10 -10
  13. package/build/tools/files/index.js +4 -4
  14. package/build/tools/files/list.js +3 -3
  15. package/build/tools/index.js +2 -2
  16. package/build/tools/properties/index.js +1 -1
  17. package/build/tools/properties/manager.js +160 -59
  18. package/build/tools/properties/tools.js +8 -7
  19. package/build/tools/properties/types.js +1 -0
  20. package/build/tools/search/complex.js +35 -19
  21. package/build/tools/search/index.js +2 -2
  22. package/build/tools/search/simple.js +6 -6
  23. package/docs/tree.md +5 -1
  24. package/package.json +10 -7
  25. package/src/index.ts +2 -1
  26. package/src/mcp/handlers.ts +12 -15
  27. package/src/mcp/index.ts +3 -2
  28. package/src/mcp/server.ts +13 -13
  29. package/src/mcp/types.ts +0 -2
  30. package/src/obsidian/client.ts +17 -17
  31. package/src/obsidian/errors.ts +1 -1
  32. package/src/obsidian/index.ts +2 -1
  33. package/src/resources/index.ts +1 -1
  34. package/src/resources/tags.ts +42 -11
  35. package/src/tools/base.ts +3 -3
  36. package/src/tools/files/content.ts +13 -13
  37. package/src/tools/files/index.ts +11 -11
  38. package/src/tools/files/list.ts +4 -4
  39. package/src/tools/index.ts +3 -3
  40. package/src/tools/properties/index.ts +1 -1
  41. package/src/tools/properties/manager.ts +188 -60
  42. package/src/tools/properties/tools.ts +10 -9
  43. package/src/tools/properties/types.ts +1 -0
  44. package/src/tools/search/complex.ts +54 -38
  45. package/src/tools/search/index.ts +2 -2
  46. package/src/tools/search/simple.ts +7 -7
  47. package/src/utils/index.ts +1 -1
package/Dockerfile CHANGED
@@ -24,7 +24,8 @@ RUN npm prune --production
24
24
  FROM node:22-slim
25
25
 
26
26
  ENV NODE_ENV=production \
27
- PATH="/home/service-user/.local/bin:${PATH}"
27
+ PATH="/home/service-user/.local/bin:${PATH}" \
28
+ OBSIDIAN_API_KEY="abc"
28
29
 
29
30
  # Install mcp-proxy globally for runtime use
30
31
  # Combine update, install, and clean in one layer
@@ -59,4 +60,4 @@ USER service-user
59
60
 
60
61
  # Define the command to run the application
61
62
  # CMD ["mcp-proxy", "node", "build/index.js"] # Keep original for reference
62
- CMD ["mcp-proxy", "node", "build/index.js"]
63
+ CMD ["node", "build/index.js"]
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Obsidian MCP Server
2
2
 
3
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.1-green.svg)](https://modelcontextprotocol.io/)
5
- [![Version](https://img.shields.io/badge/Version-1.5.4-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
+ [![Model Context Protocol](https://img.shields.io/badge/MCP-1.10.2-green.svg)](https://modelcontextprotocol.io/)
5
+ [![Version](https://img.shields.io/badge/Version-1.5.7-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
6
  [![Status](https://img.shields.io/badge/Status-Stable-green.svg)]()
7
7
  [![GitHub](https://img.shields.io/github/stars/cyanheads/obsidian-mcp-server?style=social)](https://github.com/cyanheads/obsidian-mcp-server)
8
8
 
@@ -10,55 +10,51 @@ A Model Context Protocol server designed for LLMs to interact with Obsidian vaul
10
10
 
11
11
  The Model Context Protocol (MCP) enables AI models to interact with external tools and resources through a standardized interface.
12
12
 
13
- Requires the Local REST API plugin in Obsidian.
13
+ Requires the [Local REST API plugin](https://github.com/coddingtonbear/obsidian-local-rest-api) in Obsidian.
14
14
 
15
- ## Features
15
+ ## 📋 Table of Contents
16
16
 
17
- ### File Operations
17
+ [Features](#-features) | [Installation](#-installation) | [Configuration](#-configuration) | [Tools](#-tools) | [Resources](#-resources) | [Project Structure](#-project-structure) | [Contributing](#-contributing) | [Publishing](#-publishing) | [License](#-license)
18
18
 
19
- - Atomic file/directory operations with validation
20
- - Resource monitoring and cleanup
21
- - Error handling and graceful failure
19
+ ## Features
22
20
 
23
- ### Search System
21
+ - **File Operations**: Atomic file/directory operations with validation, resource monitoring, and error handling.
22
+ - **Search System**: Full-text search with configurable context, advanced JsonLogic queries, glob patterns, and frontmatter field support.
23
+ - **Property Management**: YAML frontmatter parsing, intelligent merging, automatic timestamps, and custom field support.
24
+ - **Security & Performance**: API key authentication, rate limiting, SSL options, resource monitoring, and graceful shutdown.
24
25
 
25
- - Full-text search with configurable context
26
- - Advanced JsonLogic queries for files, tags, and metadata
27
- - Support for glob patterns and frontmatter fields
26
+ ## 🚀 Installation
28
27
 
29
- ### Property Management
28
+ Note: Requires Node.js and the [Local REST API plugin](https://github.com/coddingtonbear/obsidian-local-rest-api) enabled in Obsidian.
30
29
 
31
- - YAML frontmatter parsing and intelligent merging
32
- - Automatic timestamps (created by Obsidian, modified by server)
33
- - Custom field support
30
+ ### Option 1: Clone and Build (for development or direct use)
34
31
 
35
- ### Security & Performance
32
+ 1. Enable the Local REST API plugin in Obsidian.
33
+ 2. Clone the repository, install dependencies, and build the project:
34
+ ```bash
35
+ git clone git@github.com:cyanheads/obsidian-mcp-server.git
36
+ cd obsidian-mcp-server
37
+ npm install
38
+ npm run build
39
+ ```
40
+ 3. Configure the server using environment variables and run it using `node build/index.js` (see Configuration section below).
36
41
 
37
- - API key auth with rate limiting and SSL options
38
- - Resource monitoring and health checks
39
- - Graceful shutdown handling
42
+ ### Option 2: Install via npm (as a dependency or globally)
40
43
 
41
- ## Installation
44
+ 1. Enable the Local REST API plugin in Obsidian.
45
+ 2. Install the package using npm:
42
46
 
43
- Note: Requires Node.js
47
+ ```bash
48
+ # Install locally (e.g., within another project)
49
+ npm install obsidian-mcp-server
44
50
 
45
- 1. Enable Local REST API plugin in Obsidian
46
- 2. Clone and build:
51
+ # Or install globally
52
+ npm install -g obsidian-mcp-server
53
+ ```
47
54
 
48
- ```bash
49
- git clone git@github.com:cyanheads/obsidian-mcp-server.git
50
- cd obsidian-mcp-server
51
- npm install
52
- npm run build
53
- ```
54
-
55
- Or install from npm:
56
-
57
- ```bash
58
- npm install obsidian-mcp-server
59
- ```
55
+ 3. Configure the server using environment variables and run it (see Configuration section below).
60
56
 
61
- ## Configuration
57
+ ## ⚙️ Configuration
62
58
 
63
59
  Add to your MCP client settings (e.g., `claude_desktop_config.json` or `cline_mcp_settings.json`):
64
60
 
@@ -86,35 +82,42 @@ Add to your MCP client settings (e.g., `claude_desktop_config.json` or `cline_mc
86
82
  }
87
83
  ```
88
84
 
89
- Environment Variables:
90
-
91
- Required:
92
-
93
- - `OBSIDIAN_API_KEY`: Your API key from Obsidian's Local REST API plugin settings
94
-
95
- Connection Settings:
96
-
97
- - `VERIFY_SSL`: Enable SSL certificate verification (default: false) # This must be set to false for self-signed certificates. If you are running locally or don't understand what this means, this should be set to false.
98
- - `OBSIDIAN_PROTOCOL`: Protocol to use (default: "https")
99
- - `OBSIDIAN_HOST`: Host address (default: "127.0.0.1")
100
- - `OBSIDIAN_PORT`: Port number (default: 27124)
101
-
102
- Request Limits:
103
-
104
- - `REQUEST_TIMEOUT`: Request timeout in milliseconds (default: 5000)
105
- - `MAX_CONTENT_LENGTH`: Maximum response content length in bytes (default: 52428800 [50MB])
106
- - `MAX_BODY_LENGTH`: Maximum request body length in bytes (default: 52428800 [50MB])
107
-
108
- Rate Limiting:
109
-
110
- - `RATE_LIMIT_WINDOW_MS`: Rate limit window in milliseconds (default: 900000 [15 minutes])
111
- - `RATE_LIMIT_MAX_REQUESTS`: Maximum requests per window (default: 200)
112
-
113
- Tool Execution:
114
-
115
- - `TOOL_TIMEOUT_MS`: Tool execution timeout in milliseconds (default: 60000 [1 minute])
116
-
117
- ## Project Structure
85
+ **Environment Variables:**
86
+
87
+ - `OBSIDIAN_API_KEY` (Required): Your API key from Obsidian's Local REST API plugin settings.
88
+ - `VERIFY_SSL` (Default: `false`): Enable SSL verification. Set to `false` for self-signed certificates or local use.
89
+ - `OBSIDIAN_PROTOCOL` (Default: `"https"`): Protocol (`http` or `https`).
90
+ - `OBSIDIAN_HOST` (Default: `"127.0.0.1"`): Host address.
91
+ - `OBSIDIAN_PORT` (Default: `27124`): Port number.
92
+ - `REQUEST_TIMEOUT` (Default: `5000`): Request timeout (ms).
93
+ - `MAX_CONTENT_LENGTH` (Default: `52428800` [50MB]): Max response content length (bytes).
94
+ - `MAX_BODY_LENGTH` (Default: `52428800` [50MB]): Max request body length (bytes).
95
+ - `RATE_LIMIT_WINDOW_MS` (Default: `900000` [15 min]): Rate limit window (ms).
96
+ - `RATE_LIMIT_MAX_REQUESTS` (Default: `200`): Max requests per window.
97
+ - `TOOL_TIMEOUT_MS` (Default: `60000` [1 min]): Tool execution timeout (ms).
98
+
99
+ ## 🛠️ Tools
100
+
101
+ | Tool | Description | Parameters |
102
+ | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103
+ | **obsidian_list_files_in_vault** | Lists all files and directories within the root of your Obsidian vault. Returns a hierarchical structure detailing files, folders, and their types. | None |
104
+ | **obsidian_list_files_in_dir** | Lists files and directories within a specific folder in your Obsidian vault. Returns a hierarchical structure. Note: Empty directories may not be included in the results. Useful for exploring vault organization. | `dirpath*`: Path to list files from (relative to vault root). Note that empty directories will not be returned. |
105
+ | **obsidian_get_file_contents** | Retrieves the full content of a specified file within your Obsidian vault. Supports various readable file formats. | `filepath*`: Path to the relevant file (relative to your vault root). |
106
+ | **obsidian_append_content** | Appends the provided content to the end of a specified file in the vault. If the file does not exist, it will be created. | `filepath*`: Path to the file (relative to vault root)<br>`content*`: Content to append to the file |
107
+ | **obsidian_update_content** | Overwrites the entire content of a specified file in the vault with the provided content. If the file does not exist, it will be created. | `filepath*`: Path to the file (relative to vault root)<br>`content*`: The new, complete content for the file (overwrites existing content). |
108
+ | **obsidian_find_in_file** | Performs a full-text search across all files in your Obsidian vault. Returns matching files with context around each match. If more than 5 files match, only filenames and match counts are returned to avoid excessive output. Ideal for locating specific text, tags, or patterns. | `query*`: Text pattern to search for. Can include tags, keywords, or phrases.<br>`contextLength`: Number of characters surrounding each match to provide context (default: 10). |
109
+ | **obsidian_complex_search** | Finds files based on path patterns using JsonLogic queries. Primarily supports `glob` for pattern matching (e.g., '\*.md') and `var` for accessing the 'path' variable. Note: For content-based searches (full-text, tags within content, dates), use `obsidian_find_in_file`. | `query*`: A JsonLogic query object targeting file paths. Example: `{"glob": ["*.md", {"var": "path"}]}` matches all markdown files. |
110
+ | **obsidian_get_tags** | Retrieves all tags defined in the YAML frontmatter of markdown files within your Obsidian vault, along with their usage counts and associated file paths. Optionally, limit the search to a specific folder. | `path`: Optional folder path (relative to vault root) to restrict the tag search. |
111
+ | **obsidian_get_properties** | Retrieves properties (like title, tags, status) from the YAML frontmatter of a specified Obsidian note. Returns all defined properties, including any custom fields. | `filepath*`: Path to the note file (relative to vault root) |
112
+ | **obsidian_update_properties** | Updates properties within the YAML frontmatter of a specified Obsidian note. By default, array properties (like tags, type, status) are merged; use the 'replace' option to overwrite them instead. Handles custom fields and manages timestamps automatically. See schema for supported standard fields (title, author, tags, status, etc.). | `filepath*`: Path to the note file (relative to vault root)<br>`properties*`: Properties to update<br>`replace`: If true, array properties (like tags, status) will be completely replaced with the provided values instead of being merged with existing values. Defaults to false (merge). |
113
+
114
+ ## 🔗 Resources
115
+
116
+ | Resource | Description | Returns |
117
+ | ------------------- | ----------------------------------------------------------------------- | ---------------- |
118
+ | **obsidian://tags** | List of all tags used across the Obsidian vault with their usage counts | application/json |
119
+
120
+ ## 📁 Project Structure
118
121
 
119
122
  The project follows a modular architecture with clear separation of concerns:
120
123
 
@@ -131,140 +134,7 @@ src/
131
134
  └── utils/ # Shared utilities
132
135
  ```
133
136
 
134
- ## Tools
135
-
136
- ### File Management
137
-
138
- ```typescript
139
- // List vault contents
140
- obsidian_list_files_in_vault: {
141
- }
142
-
143
- // List directory contents
144
- obsidian_list_files_in_dir: {
145
- dirpath: string; // Path relative to vault root
146
- }
147
-
148
- // Get file contents
149
- obsidian_get_file_contents: {
150
- filepath: string; // Path relative to vault root
151
- }
152
- ```
153
-
154
- ### Search Operations
155
-
156
- ```typescript
157
- // Text search with context
158
- obsidian_find_in_file: {
159
- query: string,
160
- contextLength?: number // Default: 10
161
- }
162
-
163
- // Advanced search with JsonLogic
164
- obsidian_complex_search: {
165
- query: JsonLogicQuery
166
- // Examples:
167
- // Find by tag:
168
- // {"in": ["#mytag", {"var": "frontmatter.tags"}]}
169
- //
170
- // Find markdown files in a directory:
171
- // {"glob": ["docs/*.md", {"var": "path"}]}
172
- //
173
- // Combine conditions:
174
- // {"and": [
175
- // {"glob": ["*.md", {"var": "path"}]},
176
- // {"in": ["#mytag", {"var": "frontmatter.tags"}]}
177
- // ]}
178
- }
179
-
180
- // Get all tags in vault or directory
181
- obsidian_get_tags: {
182
- path?: string // Optional: limit to specific directory
183
- }
184
- ```
185
-
186
- ### Content Modification
187
-
188
- ```typescript
189
- // Append to file
190
- obsidian_append_content: {
191
- filepath: string, // Path relative to vault root
192
- content: string // Content to append
193
- }
194
-
195
- // Update file content
196
- obsidian_patch_content: {
197
- filepath: string, // Path relative to vault root
198
- content: string // New content (replaces existing)
199
- }
200
- ```
201
-
202
- ### Property Management
203
-
204
- ```typescript
205
- // Get note properties
206
- obsidian_get_properties: {
207
- filepath: string // Path relative to vault root
208
- }
209
-
210
- // Update note properties
211
- obsidian_update_properties: {
212
- filepath: string, // Path relative to vault root
213
- properties: {
214
- title?: string,
215
- author?: string,
216
- // Note: created/modified timestamps are managed automatically
217
- type?: Array<"concept" | "architecture" | "specification" |
218
- "protocol" | "api" | "research" | "implementation" |
219
- "guide" | "reference">,
220
- tags?: string[], // Must start with #
221
- status?: Array<"draft" | "in-progress" | "review" | "complete">,
222
- version?: string,
223
- platform?: string,
224
- repository?: string, // URL
225
- dependencies?: string[],
226
- sources?: string[],
227
- urls?: string[], // URLs
228
- papers?: string[],
229
- custom?: Record<string, unknown>
230
- }
231
- }
232
- ```
233
-
234
- ## Best Practices
235
-
236
- ### File Operations
237
-
238
- - Use atomic operations with validation
239
- - Handle errors and monitor performance
240
-
241
- ### Search Implementation
242
-
243
- - Use appropriate search tool for the task:
244
- - obsidian_find_in_file for text search
245
- - obsidian_complex_search for metadata/tag filtering
246
- - Keep context size reasonable (default: 10 chars)
247
-
248
- ### Property Management
249
-
250
- - Use appropriate types and validate updates
251
- - Handle arrays and custom fields properly
252
- - Never set timestamps (managed automatically)
253
-
254
- ### Error Prevention
255
-
256
- - Validate inputs and handle errors gracefully
257
- - Monitor patterns and respect rate limits
258
-
259
- ## Resources
260
-
261
- The MCP server exposes the following resources:
262
-
263
- ```
264
- obsidian://tags # List of all tags used across the vault
265
- ```
266
-
267
- ## Contributing
137
+ ## 👥 Contributing
268
138
 
269
139
  1. Fork the repository
270
140
  2. Create a feature branch
@@ -272,19 +142,9 @@ obsidian://tags # List of all tags used across the vault
272
142
 
273
143
  For bugs and features, create an issue at [https://github.com/cyanheads/obsidian-mcp-server/issues](https://github.com/cyanheads/obsidian-mcp-server/issues).
274
144
 
275
- ## Publishing
276
-
277
- The package is automatically published to npm when version tags are pushed:
278
-
279
- ```bash
280
- # Update version in package.json
281
- npm version patch # or minor, or major
282
- git push --follow-tags
283
- ```
284
-
285
- This will trigger the GitHub Action to build and publish the package.
145
+ ## 📄 License
286
146
 
287
- ## License
147
+ [![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
288
148
 
289
149
  Apache License 2.0
290
150
 
package/build/index.js CHANGED
@@ -14,7 +14,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
14
14
  // Export the run function and other important modules
15
15
  export { run } from "./mcp/server.js";
16
16
  export * from "./obsidian/index.js";
17
- export * from "./tools/index.js";
18
17
  export * from "./resources/index.js";
18
+ export * from "./tools/index.js";
19
19
  export * from "./utils/index.js";
20
20
  //# sourceMappingURL=index.js.map
@@ -1,11 +1,8 @@
1
- /**
2
- * MCP server request handlers
3
- */
4
- import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema } from "@modelcontextprotocol/sdk/types.js";
1
+ import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
2
  import { ObsidianError } from "../utils/errors.js";
6
- import { validateToolArguments } from "../utils/validation.js";
7
- import { rateLimiter } from "../utils/rate-limiting.js";
8
3
  import { createLogger, ErrorCategoryType } from "../utils/logging.js";
4
+ import { rateLimiter } from "../utils/rate-limiting.js";
5
+ import { validateToolArguments } from "../utils/validation.js";
9
6
  import { DEFAULT_TIMEOUT_CONFIG, McpErrorCode } from "./types.js";
10
7
  // Create a logger for request handlers
11
8
  const logger = createLogger('McpHandlers');
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * MCP module exports
3
3
  */
4
- export * from './types.js';
5
4
  export * from './handlers.js';
6
5
  export * from './server.js';
6
+ export * from './types.js';
7
7
  //# sourceMappingURL=index.js.map
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * MCP server implementation
3
3
  */
4
- import { config } from "dotenv";
5
4
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
6
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+ import { config } from "dotenv";
7
+ import { ObsidianClient } from "../obsidian/client.js";
8
+ import { createTagResource } from "../resources/index.js";
9
+ import { createToolHandlerMap, createToolHandlers } from "../tools/index.js";
7
10
  import { ObsidianError } from "../utils/errors.js"; // Import ObsidianError
8
11
  import { createLogger, ErrorCategoryType } from "../utils/logging.js";
9
12
  import { rateLimiter } from "../utils/rate-limiting.js";
10
- import { createTagResource } from "../resources/index.js";
11
- import { createToolHandlers, createToolHandlerMap } from "../tools/index.js";
12
- import { ObsidianClient } from "../obsidian/client.js";
13
- import { setupToolListingHandler, setupToolCallingHandler, setupResourceListingHandler, setupResourceReadingHandler } from "./handlers.js";
13
+ import { setupResourceListingHandler, setupResourceReadingHandler, setupToolCallingHandler, setupToolListingHandler } from "./handlers.js";
14
14
  import { McpErrorCode } from "./types.js";
15
15
  // Create a logger for the server
16
16
  const logger = createLogger('McpServer');
@@ -1,16 +1,13 @@
1
- /**
2
- * Obsidian REST API client implementation
3
- */
4
1
  import axios from "axios";
5
- import { Agent } from "node:https";
6
2
  import { readFileSync } from "fs";
7
- import { fileURLToPath } from 'url';
3
+ import { Agent } from "node:https";
8
4
  import { dirname, join } from "path";
9
- import { createLogger } from '../utils/logging.js';
5
+ import { fileURLToPath } from 'url';
10
6
  import { ObsidianError } from '../utils/errors.js';
11
- import { validateFilePath, sanitizeHeader } from '../utils/validation.js';
12
- import { DEFAULT_OBSIDIAN_CONFIG } from './types.js';
7
+ import { createLogger } from '../utils/logging.js';
8
+ import { sanitizeHeader, validateFilePath } from '../utils/validation.js';
13
9
  import { createMissingAPIKeyMessage, handleAxiosError } from './errors.js';
10
+ import { DEFAULT_OBSIDIAN_CONFIG } from './types.js';
14
11
  // Logger for the ObsidianClient
15
12
  const logger = createLogger('ObsidianClient');
16
13
  // Get package version for user agent
@@ -2,6 +2,6 @@
2
2
  * Exports for the Obsidian module
3
3
  */
4
4
  export * from './client.js';
5
- export * from './types.js';
6
5
  export * from './errors.js';
6
+ export * from './types.js';
7
7
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Resources module exports
3
3
  */
4
- export * from './types.js';
5
4
  export * from './tags.js';
5
+ export * from './types.js';
6
6
  import { TagResource } from './tags.js';
7
7
  /**
8
8
  * Create and return the tag resource
@@ -1,6 +1,6 @@
1
1
  import pLimit from 'p-limit'; // Import p-limit
2
- import { PropertyManager } from "../tools/properties/manager.js";
3
2
  import { sep } from "path";
3
+ import { PropertyManager } from "../tools/properties/manager.js";
4
4
  import { createLogger, ErrorCategoryType } from "../utils/logging.js";
5
5
  // Create a logger for tag resources
6
6
  const logger = createLogger('TagResource');
@@ -77,8 +77,13 @@ export class TagResource {
77
77
  // This call is now rate-limited
78
78
  const content = await this.client.getFileContents(filename);
79
79
  // Only extract tags from frontmatter YAML
80
- const properties = this.propertyManager.parseProperties(content);
81
- return { filename, tags: properties.tags || [] };
80
+ const parseResult = this.propertyManager.parseProperties(content);
81
+ // Handle potential parsing errors before accessing properties
82
+ if (parseResult.error) {
83
+ logger.warn(`Skipping tags for ${filename} due to parsing error: ${parseResult.error.message}`);
84
+ return { filename, tags: [] }; // Return empty tags on error
85
+ }
86
+ return { filename, tags: parseResult.properties.tags || [] };
82
87
  }
83
88
  catch (error) {
84
89
  logger.error(`Failed to process file ${filename}:`, errorToObject(error));
@@ -175,9 +180,11 @@ export class TagResource {
175
180
  }
176
181
  }
177
182
  /**
178
- * Get the content for the resource
183
+ * Get the content for the resource, optionally filtering by path.
184
+ * Note: The path filtering logic assumes the tool handler passes the path correctly.
179
185
  */
180
- async getContent() {
186
+ // TODO: Verify how the path argument is passed from the tool handler
187
+ async getContent(filterPath) {
181
188
  logger.startTimer('get_tags_content');
182
189
  try {
183
190
  if (!this.isInitialized) {
@@ -187,15 +194,36 @@ export class TagResource {
187
194
  else {
188
195
  await this.updateCacheIfNeeded();
189
196
  }
197
+ let filteredTagEntries = [];
198
+ // Filter tags based on the provided path
199
+ if (filterPath) {
200
+ // Normalize path to ensure it ends with a separator for accurate startsWith check
201
+ const normalizedFilterPath = filterPath.endsWith(sep) ? filterPath : filterPath + sep;
202
+ logger.debug(`Filtering tags for path: ${normalizedFilterPath}`);
203
+ filteredTagEntries = Array.from(this.tagCache.entries())
204
+ .map(([name, files]) => {
205
+ // Filter files within each tag entry
206
+ const relevantFiles = Array.from(files).filter(file => file.startsWith(normalizedFilterPath));
207
+ return { name, files: new Set(relevantFiles) };
208
+ })
209
+ .filter(tagEntry => tagEntry.files.size > 0); // Keep only tags that exist in the filtered path
210
+ logger.debug(`Found ${filteredTagEntries.length} tags after filtering.`);
211
+ }
212
+ else {
213
+ // If no path provided, use all tags from the cache
214
+ filteredTagEntries = Array.from(this.tagCache.entries()).map(([name, files]) => ({ name, files }));
215
+ }
190
216
  const response = {
191
- tags: Array.from(this.tagCache.entries())
192
- .map(([name, files]) => ({
217
+ tags: filteredTagEntries
218
+ .map(({ name, files }) => ({
193
219
  name,
194
220
  count: files.size,
195
221
  files: Array.from(files).sort()
196
222
  }))
197
- .sort((a, b) => b.count - a.count || a.name.localeCompare(b.name)),
223
+ .sort((a, b) => b.count - a.count || a.name.localeCompare(b.name)), // Sort filtered results
198
224
  metadata: {
225
+ // Note: Metadata currently reflects the entire vault cache, even when filtered.
226
+ // Adjust calculation here if path-specific metadata is desired.
199
227
  totalOccurrences: Array.from(this.tagCache.values())
200
228
  .reduce((sum, files) => sum + files.size, 0),
201
229
  uniqueTags: this.tagCache.size,
@@ -1,7 +1,7 @@
1
+ import { McpErrorCode } from "../mcp/types.js";
1
2
  import { ObsidianError } from "../utils/errors.js";
2
- import { tokenCounter } from "../utils/tokenization.js";
3
3
  import { createLogger, ErrorCategoryType } from "../utils/logging.js";
4
- import { McpErrorCode } from "../mcp/types.js";
4
+ import { tokenCounter } from "../utils/tokenization.js";
5
5
  // Create a logger for tool operations
6
6
  const logger = createLogger('Tools');
7
7
  /**
@@ -1,5 +1,5 @@
1
- import { BaseToolHandler } from "../base.js";
2
1
  import { createLogger } from "../../utils/logging.js";
2
+ import { BaseToolHandler } from "../base.js";
3
3
  // Create a logger for file content operations
4
4
  const logger = createLogger('FileContentTools');
5
5
  /**
@@ -8,7 +8,7 @@ const logger = createLogger('FileContentTools');
8
8
  export const FILE_CONTENT_TOOL_NAMES = {
9
9
  GET_FILE_CONTENTS: "obsidian_get_file_contents",
10
10
  APPEND_CONTENT: "obsidian_append_content",
11
- PATCH_CONTENT: "obsidian_patch_content"
11
+ UPDATE_CONTENT: "obsidian_update_content" // Renamed from PATCH_CONTENT
12
12
  };
13
13
  /**
14
14
  * Tool handler for getting file contents
@@ -20,7 +20,7 @@ export class GetFileContentsToolHandler extends BaseToolHandler {
20
20
  getToolDescription() {
21
21
  return {
22
22
  name: this.name,
23
- description: "Return the content of a single file in your vault. Supports markdown files, text files, and other readable formats. Returns the raw content including any YAML frontmatter.",
23
+ description: "Retrieves the full content of a specified file within your Obsidian vault. Supports various readable file formats.",
24
24
  examples: [
25
25
  {
26
26
  description: "Get content of a markdown note",
@@ -69,7 +69,7 @@ export class AppendContentToolHandler extends BaseToolHandler {
69
69
  getToolDescription() {
70
70
  return {
71
71
  name: this.name,
72
- description: "Append content to a new or existing file in the vault.",
72
+ description: "Appends the provided content to the end of a specified file in the vault. If the file does not exist, it will be created.",
73
73
  examples: [
74
74
  {
75
75
  description: "Append a new task",
@@ -120,17 +120,17 @@ export class AppendContentToolHandler extends BaseToolHandler {
120
120
  /**
121
121
  * Tool handler for updating file content
122
122
  */
123
- export class PatchContentToolHandler extends BaseToolHandler {
123
+ export class UpdateContentToolHandler extends BaseToolHandler {
124
124
  constructor(client) {
125
- super(FILE_CONTENT_TOOL_NAMES.PATCH_CONTENT, client);
125
+ super(FILE_CONTENT_TOOL_NAMES.UPDATE_CONTENT, client); // Renamed from PATCH_CONTENT
126
126
  }
127
127
  getToolDescription() {
128
128
  return {
129
- name: this.name,
130
- description: "Update the entire content of an existing note or create a new one.",
129
+ name: this.name, // Will be obsidian_update_content
130
+ description: "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.",
131
131
  examples: [
132
132
  {
133
- description: "Update a note's content",
133
+ description: "Overwrite a note's content",
134
134
  args: {
135
135
  filepath: "project.md",
136
136
  content: "# Project Notes\n\nThis will replace the entire content of the note."
@@ -147,7 +147,7 @@ export class PatchContentToolHandler extends BaseToolHandler {
147
147
  },
148
148
  content: {
149
149
  type: "string",
150
- description: "New content for the note (replaces existing content)"
150
+ description: "The new, complete content for the file (overwrites existing content)."
151
151
  }
152
152
  },
153
153
  required: ["filepath", "content"]
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * File operation tools exports
3
3
  */
4
- export * from './list.js';
5
4
  export * from './content.js';
6
- import { ListFilesInVaultToolHandler, ListFilesInDirToolHandler } from './list.js';
7
- import { GetFileContentsToolHandler, AppendContentToolHandler, PatchContentToolHandler } from './content.js';
5
+ export * from './list.js';
6
+ import { AppendContentToolHandler, GetFileContentsToolHandler, UpdateContentToolHandler } from './content.js';
7
+ import { ListFilesInDirToolHandler, ListFilesInVaultToolHandler } from './list.js';
8
8
  /**
9
9
  * Create all file-related tool handlers
10
10
  * @param client The ObsidianClient instance
@@ -16,7 +16,7 @@ export function createFileToolHandlers(client) {
16
16
  new ListFilesInDirToolHandler(client),
17
17
  new GetFileContentsToolHandler(client),
18
18
  new AppendContentToolHandler(client),
19
- new PatchContentToolHandler(client)
19
+ new UpdateContentToolHandler(client)
20
20
  ];
21
21
  }
22
22
  //# sourceMappingURL=index.js.map