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.
- package/README.md +248 -104
- package/dist/config/index.d.ts +41 -0
- package/dist/config/index.js +191 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.js +296 -18
- package/dist/mcp-server/server.d.ts +33 -0
- package/dist/mcp-server/server.js +211 -0
- package/dist/mcp-server/tools/obsidianDeleteFileTool/index.d.ts +12 -0
- package/dist/mcp-server/tools/obsidianDeleteFileTool/index.js +12 -0
- package/dist/mcp-server/tools/obsidianDeleteFileTool/logic.d.ts +51 -0
- package/dist/mcp-server/tools/obsidianDeleteFileTool/logic.js +168 -0
- package/dist/mcp-server/tools/obsidianDeleteFileTool/registration.d.ts +19 -0
- package/dist/mcp-server/tools/obsidianDeleteFileTool/registration.js +91 -0
- package/dist/mcp-server/tools/obsidianGlobalSearchTool/index.d.ts +12 -0
- package/dist/mcp-server/tools/obsidianGlobalSearchTool/index.js +12 -0
- package/dist/mcp-server/tools/obsidianGlobalSearchTool/logic.d.ts +77 -0
- package/dist/mcp-server/tools/obsidianGlobalSearchTool/logic.js +341 -0
- package/dist/mcp-server/tools/obsidianGlobalSearchTool/registration.d.ts +18 -0
- package/dist/mcp-server/tools/obsidianGlobalSearchTool/registration.js +69 -0
- package/dist/mcp-server/tools/obsidianListFilesTool/index.d.ts +12 -0
- package/dist/mcp-server/tools/obsidianListFilesTool/index.js +12 -0
- package/dist/mcp-server/tools/obsidianListFilesTool/logic.d.ts +64 -0
- package/dist/mcp-server/tools/obsidianListFilesTool/logic.js +179 -0
- package/dist/mcp-server/tools/obsidianListFilesTool/registration.d.ts +19 -0
- package/dist/mcp-server/tools/obsidianListFilesTool/registration.js +96 -0
- package/dist/mcp-server/tools/obsidianManageFrontmatterTool/index.d.ts +3 -0
- package/dist/mcp-server/tools/obsidianManageFrontmatterTool/index.js +2 -0
- package/dist/mcp-server/tools/obsidianManageFrontmatterTool/logic.d.ts +42 -0
- package/dist/mcp-server/tools/obsidianManageFrontmatterTool/logic.js +152 -0
- package/dist/mcp-server/tools/obsidianManageFrontmatterTool/registration.d.ts +3 -0
- package/dist/mcp-server/tools/obsidianManageFrontmatterTool/registration.js +52 -0
- package/dist/mcp-server/tools/obsidianManageTagsTool/index.d.ts +3 -0
- package/dist/mcp-server/tools/obsidianManageTagsTool/index.js +2 -0
- package/dist/mcp-server/tools/obsidianManageTagsTool/logic.d.ts +28 -0
- package/dist/mcp-server/tools/obsidianManageTagsTool/logic.js +161 -0
- package/dist/mcp-server/tools/obsidianManageTagsTool/registration.d.ts +3 -0
- package/dist/mcp-server/tools/obsidianManageTagsTool/registration.js +52 -0
- package/dist/mcp-server/tools/obsidianReadFileTool/index.d.ts +12 -0
- package/dist/mcp-server/tools/obsidianReadFileTool/index.js +12 -0
- package/dist/mcp-server/tools/obsidianReadFileTool/logic.d.ts +87 -0
- package/dist/mcp-server/tools/obsidianReadFileTool/logic.js +216 -0
- package/dist/mcp-server/tools/obsidianReadFileTool/registration.d.ts +20 -0
- package/dist/mcp-server/tools/obsidianReadFileTool/registration.js +101 -0
- package/dist/mcp-server/tools/obsidianSearchReplaceTool/index.d.ts +12 -0
- package/dist/mcp-server/tools/obsidianSearchReplaceTool/index.js +12 -0
- package/dist/mcp-server/tools/obsidianSearchReplaceTool/logic.d.ts +255 -0
- package/dist/mcp-server/tools/obsidianSearchReplaceTool/logic.js +583 -0
- package/dist/mcp-server/tools/obsidianSearchReplaceTool/registration.d.ts +22 -0
- package/dist/mcp-server/tools/obsidianSearchReplaceTool/registration.js +111 -0
- package/dist/mcp-server/tools/obsidianUpdateFileTool/index.d.ts +12 -0
- package/dist/mcp-server/tools/obsidianUpdateFileTool/index.js +12 -0
- package/dist/mcp-server/tools/obsidianUpdateFileTool/logic.d.ts +183 -0
- package/dist/mcp-server/tools/obsidianUpdateFileTool/logic.js +490 -0
- package/dist/mcp-server/tools/obsidianUpdateFileTool/registration.d.ts +21 -0
- package/dist/mcp-server/tools/obsidianUpdateFileTool/registration.js +108 -0
- package/dist/mcp-server/transports/authentication/authContext.d.ts +33 -0
- package/dist/mcp-server/transports/authentication/authContext.js +24 -0
- package/dist/mcp-server/transports/authentication/authMiddleware.d.ts +30 -0
- package/dist/mcp-server/transports/authentication/authMiddleware.js +145 -0
- package/dist/mcp-server/transports/authentication/authUtils.d.ts +18 -0
- package/dist/mcp-server/transports/authentication/authUtils.js +45 -0
- package/dist/mcp-server/transports/authentication/oauthMiddleware.d.ts +24 -0
- package/dist/mcp-server/transports/authentication/oauthMiddleware.js +109 -0
- package/dist/mcp-server/transports/authentication/types.d.ts +17 -0
- package/dist/mcp-server/transports/authentication/types.js +5 -0
- package/dist/mcp-server/transports/httpTransport.d.ts +24 -0
- package/dist/mcp-server/transports/httpTransport.js +496 -0
- package/dist/mcp-server/transports/stdioTransport.d.ts +42 -0
- package/dist/mcp-server/transports/stdioTransport.js +63 -0
- package/dist/services/obsidianRestAPI/index.d.ts +15 -0
- package/dist/services/obsidianRestAPI/index.js +17 -0
- package/dist/services/obsidianRestAPI/methods/activeFileMethods.d.ts +38 -0
- package/dist/services/obsidianRestAPI/methods/activeFileMethods.js +62 -0
- package/dist/services/obsidianRestAPI/methods/commandMethods.d.ts +22 -0
- package/dist/services/obsidianRestAPI/methods/commandMethods.js +31 -0
- package/dist/services/obsidianRestAPI/methods/openMethods.d.ts +16 -0
- package/dist/services/obsidianRestAPI/methods/openMethods.js +21 -0
- package/dist/services/obsidianRestAPI/methods/patchMethods.d.ts +37 -0
- package/dist/services/obsidianRestAPI/methods/patchMethods.js +94 -0
- package/dist/services/obsidianRestAPI/methods/periodicNoteMethods.d.ts +42 -0
- package/dist/services/obsidianRestAPI/methods/periodicNoteMethods.js +66 -0
- package/dist/services/obsidianRestAPI/methods/searchMethods.d.ts +25 -0
- package/dist/services/obsidianRestAPI/methods/searchMethods.js +36 -0
- package/dist/services/obsidianRestAPI/methods/vaultMethods.d.ts +58 -0
- package/dist/services/obsidianRestAPI/methods/vaultMethods.js +144 -0
- package/dist/services/obsidianRestAPI/service.d.ts +195 -0
- package/dist/services/obsidianRestAPI/service.js +379 -0
- package/dist/services/obsidianRestAPI/types.d.ts +127 -0
- package/dist/services/obsidianRestAPI/types.js +7 -0
- package/dist/services/obsidianRestAPI/vaultCache/index.d.ts +4 -0
- package/dist/services/obsidianRestAPI/vaultCache/index.js +4 -0
- package/dist/services/obsidianRestAPI/vaultCache/service.d.ts +88 -0
- package/dist/services/obsidianRestAPI/vaultCache/service.js +299 -0
- package/dist/types-global/errors.d.ts +73 -0
- package/dist/types-global/errors.js +71 -0
- package/dist/utils/index.d.ts +5 -8
- package/dist/utils/index.js +13 -9
- package/dist/utils/internal/asyncUtils.d.ts +54 -0
- package/dist/utils/internal/asyncUtils.js +101 -0
- package/dist/utils/internal/errorHandler.d.ts +176 -0
- package/dist/utils/internal/errorHandler.js +351 -0
- package/dist/utils/internal/index.d.ts +4 -0
- package/dist/utils/internal/index.js +4 -0
- package/dist/utils/internal/logger.d.ts +141 -0
- package/dist/utils/internal/logger.js +406 -0
- package/dist/utils/internal/requestContext.d.ts +83 -0
- package/dist/utils/internal/requestContext.js +72 -0
- package/dist/utils/metrics/index.d.ts +1 -0
- package/dist/utils/metrics/index.js +1 -0
- package/dist/utils/metrics/tokenCounter.d.ts +27 -0
- package/dist/utils/metrics/tokenCounter.js +128 -0
- package/dist/utils/obsidian/index.d.ts +5 -0
- package/dist/utils/obsidian/index.js +5 -0
- package/dist/utils/obsidian/obsidianApiUtils.d.ts +14 -0
- package/dist/utils/obsidian/obsidianApiUtils.js +29 -0
- package/dist/utils/obsidian/obsidianStatUtils.d.ts +68 -0
- package/dist/utils/obsidian/obsidianStatUtils.js +143 -0
- package/dist/utils/parsing/dateParser.d.ts +56 -0
- package/dist/utils/parsing/dateParser.js +104 -0
- package/dist/utils/parsing/index.d.ts +2 -0
- package/dist/utils/parsing/index.js +3 -0
- package/dist/utils/parsing/jsonParser.d.ts +80 -0
- package/dist/utils/parsing/jsonParser.js +133 -0
- package/dist/utils/security/idGenerator.d.ts +140 -0
- package/dist/utils/security/idGenerator.js +194 -0
- package/dist/utils/security/index.d.ts +3 -0
- package/dist/utils/security/index.js +3 -0
- package/dist/utils/security/rateLimiter.d.ts +156 -0
- package/dist/utils/security/rateLimiter.js +235 -0
- package/dist/utils/security/sanitization.d.ts +244 -0
- package/dist/utils/security/sanitization.js +599 -0
- package/package.json +58 -37
- package/dist/index.js.map +0 -1
- package/dist/mcp/handlers.d.ts +0 -29
- package/dist/mcp/handlers.js +0 -305
- package/dist/mcp/handlers.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -6
- package/dist/mcp/index.js +0 -7
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/server.d.ts +0 -18
- package/dist/mcp/server.js +0 -240
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/types.d.ts +0 -70
- package/dist/mcp/types.js +0 -49
- package/dist/mcp/types.js.map +0 -1
- package/dist/obsidian/client.d.ts +0 -109
- package/dist/obsidian/client.js +0 -403
- package/dist/obsidian/client.js.map +0 -1
- package/dist/obsidian/errors.d.ts +0 -28
- package/dist/obsidian/errors.js +0 -75
- package/dist/obsidian/errors.js.map +0 -1
- package/dist/obsidian/index.d.ts +0 -6
- package/dist/obsidian/index.js +0 -7
- package/dist/obsidian/index.js.map +0 -1
- package/dist/obsidian/types.d.ts +0 -107
- package/dist/obsidian/types.js +0 -12
- package/dist/obsidian/types.js.map +0 -1
- package/dist/resources/index.d.ts +0 -13
- package/dist/resources/index.js +0 -15
- package/dist/resources/index.js.map +0 -1
- package/dist/resources/tags.d.ts +0 -39
- package/dist/resources/tags.js +0 -257
- package/dist/resources/tags.js.map +0 -1
- package/dist/resources/types.d.ts +0 -27
- package/dist/resources/types.js +0 -5
- package/dist/resources/types.js.map +0 -1
- package/dist/tools/base.d.ts +0 -46
- package/dist/tools/base.js +0 -88
- package/dist/tools/base.js.map +0 -1
- package/dist/tools/files/content.d.ts +0 -58
- package/dist/tools/files/content.js +0 -171
- package/dist/tools/files/content.js.map +0 -1
- package/dist/tools/files/index.d.ts +0 -14
- package/dist/tools/files/index.js +0 -22
- package/dist/tools/files/index.js.map +0 -1
- package/dist/tools/files/list.d.ts +0 -35
- package/dist/tools/files/list.js +0 -133
- package/dist/tools/files/list.js.map +0 -1
- package/dist/tools/index.d.ts +0 -21
- package/dist/tools/index.js +0 -31
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/properties/index.d.ts +0 -14
- package/dist/tools/properties/index.js +0 -19
- package/dist/tools/properties/index.js.map +0 -1
- package/dist/tools/properties/manager.d.ts +0 -62
- package/dist/tools/properties/manager.js +0 -302
- package/dist/tools/properties/manager.js.map +0 -1
- package/dist/tools/properties/tools.d.ts +0 -47
- package/dist/tools/properties/tools.js +0 -239
- package/dist/tools/properties/tools.js.map +0 -1
- package/dist/tools/properties/types.d.ts +0 -141
- package/dist/tools/properties/types.js +0 -70
- package/dist/tools/properties/types.js.map +0 -1
- package/dist/tools/search/complex.d.ts +0 -38
- package/dist/tools/search/complex.js +0 -270
- package/dist/tools/search/complex.js.map +0 -1
- package/dist/tools/search/index.d.ts +0 -14
- package/dist/tools/search/index.js +0 -20
- package/dist/tools/search/index.js.map +0 -1
- package/dist/tools/search/simple.d.ts +0 -25
- package/dist/tools/search/simple.js +0 -127
- package/dist/tools/search/simple.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -24
- package/dist/utils/errors.js +0 -59
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/idGenerator.d.ts +0 -15
- package/dist/utils/idGenerator.js +0 -21
- package/dist/utils/idGenerator.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/logging.d.ts +0 -245
- package/dist/utils/logging.js +0 -417
- package/dist/utils/logging.js.map +0 -1
- package/dist/utils/rate-limiting.d.ts +0 -50
- package/dist/utils/rate-limiting.js +0 -94
- package/dist/utils/rate-limiting.js.map +0 -1
- package/dist/utils/tokenization.d.ts +0 -28
- package/dist/utils/tokenization.js +0 -75
- package/dist/utils/tokenization.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -22
- package/dist/utils/validation.js +0 -92
- package/dist/utils/validation.js.map +0 -1
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resources module exports
|
|
3
|
-
*/
|
|
4
|
-
export * from './tags.js';
|
|
5
|
-
export * from './types.js';
|
|
6
|
-
import { ObsidianClient } from '../obsidian/client.js';
|
|
7
|
-
import { TagResource } from './tags.js';
|
|
8
|
-
/**
|
|
9
|
-
* Create and return the tag resource
|
|
10
|
-
* @param client The ObsidianClient instance
|
|
11
|
-
* @returns The tag resource
|
|
12
|
-
*/
|
|
13
|
-
export declare function createTagResource(client: ObsidianClient): TagResource;
|
package/dist/resources/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resources module exports
|
|
3
|
-
*/
|
|
4
|
-
export * from './tags.js';
|
|
5
|
-
export * from './types.js';
|
|
6
|
-
import { TagResource } from './tags.js';
|
|
7
|
-
/**
|
|
8
|
-
* Create and return the tag resource
|
|
9
|
-
* @param client The ObsidianClient instance
|
|
10
|
-
* @returns The tag resource
|
|
11
|
-
*/
|
|
12
|
-
export function createTagResource(client) {
|
|
13
|
-
return new TagResource(client);
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB;IACtD,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/resources/tags.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tag resource implementation
|
|
3
|
-
*/
|
|
4
|
-
import { Resource, TextContent } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import { ObsidianClient } from "../obsidian/client.js";
|
|
6
|
-
/**
|
|
7
|
-
* Resource for providing tags used in the Obsidian vault
|
|
8
|
-
*/
|
|
9
|
-
export declare class TagResource {
|
|
10
|
-
private client;
|
|
11
|
-
private tagCache;
|
|
12
|
-
private propertyManager;
|
|
13
|
-
private isInitialized;
|
|
14
|
-
private isUpdating;
|
|
15
|
-
private lastUpdate;
|
|
16
|
-
private updateInterval;
|
|
17
|
-
constructor(client: ObsidianClient);
|
|
18
|
-
/**
|
|
19
|
-
* Get resource description for the MCP server
|
|
20
|
-
*/
|
|
21
|
-
getResourceDescription(): Resource;
|
|
22
|
-
/**
|
|
23
|
-
* Initialize the tag cache
|
|
24
|
-
*/
|
|
25
|
-
private initializeCache;
|
|
26
|
-
/**
|
|
27
|
-
* Add a tag to the cache
|
|
28
|
-
*/
|
|
29
|
-
private addTag;
|
|
30
|
-
/**
|
|
31
|
-
* Update the cache if needed, preventing race conditions.
|
|
32
|
-
*/
|
|
33
|
-
private updateCacheIfNeeded;
|
|
34
|
-
/**
|
|
35
|
-
* Get the content for the resource, optionally filtering by path.
|
|
36
|
-
* Note: The path filtering logic assumes the tool handler passes the path correctly.
|
|
37
|
-
*/
|
|
38
|
-
getContent(filterPath?: string): Promise<TextContent[]>;
|
|
39
|
-
}
|
package/dist/resources/tags.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import pLimit from 'p-limit'; // Import p-limit
|
|
2
|
-
import { sep } from "path";
|
|
3
|
-
import { PropertyManager } from "../tools/properties/manager.js";
|
|
4
|
-
import { createLogger, ErrorCategoryType } from "../utils/logging.js";
|
|
5
|
-
// Create a logger for tag resources
|
|
6
|
-
const logger = createLogger('TagResource');
|
|
7
|
-
/**
|
|
8
|
-
* Helper function to safely convert any error to an object
|
|
9
|
-
*/
|
|
10
|
-
function errorToObject(error) {
|
|
11
|
-
if (error instanceof Error) {
|
|
12
|
-
return {
|
|
13
|
-
name: error.name,
|
|
14
|
-
message: error.message,
|
|
15
|
-
stack: error.stack,
|
|
16
|
-
errorCategory: ErrorCategoryType.CATEGORY_SYSTEM
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
else if (typeof error === 'object' && error !== null) {
|
|
20
|
-
return error;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return {
|
|
24
|
-
error: String(error),
|
|
25
|
-
errorCategory: ErrorCategoryType.CATEGORY_UNKNOWN
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Resource for providing tags used in the Obsidian vault
|
|
31
|
-
*/
|
|
32
|
-
export class TagResource {
|
|
33
|
-
client;
|
|
34
|
-
tagCache = new Map();
|
|
35
|
-
propertyManager;
|
|
36
|
-
isInitialized = false;
|
|
37
|
-
isUpdating = false; // Flag to prevent concurrent updates
|
|
38
|
-
lastUpdate = 0;
|
|
39
|
-
updateInterval = 5000; // 5 seconds
|
|
40
|
-
constructor(client) {
|
|
41
|
-
this.client = client;
|
|
42
|
-
this.propertyManager = new PropertyManager(client);
|
|
43
|
-
this.initializeCache();
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Get resource description for the MCP server
|
|
47
|
-
*/
|
|
48
|
-
getResourceDescription() {
|
|
49
|
-
return {
|
|
50
|
-
uri: "obsidian://tags",
|
|
51
|
-
name: "Obsidian Tags",
|
|
52
|
-
description: "List of all tags used across the Obsidian vault with their usage counts",
|
|
53
|
-
mimeType: "application/json"
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Initialize the tag cache
|
|
58
|
-
*/
|
|
59
|
-
async initializeCache() {
|
|
60
|
-
logger.startTimer('init_tag_cache');
|
|
61
|
-
try {
|
|
62
|
-
logger.info('Initializing tag cache');
|
|
63
|
-
// Get all markdown files using platform-agnostic path pattern
|
|
64
|
-
const query = {
|
|
65
|
-
"glob": [`**${sep}*.md`.replace(/\\/g, '/'), { "var": "path" }]
|
|
66
|
-
};
|
|
67
|
-
const results = await this.client.searchJson(query);
|
|
68
|
-
this.tagCache.clear();
|
|
69
|
-
// Create a limiter with a concurrency of 3 (reduced from 10)
|
|
70
|
-
const limit = pLimit(3);
|
|
71
|
-
// Create promises for processing each file with concurrency limiting
|
|
72
|
-
const processingPromises = results
|
|
73
|
-
.filter(result => 'filename' in result) // Ensure filename exists
|
|
74
|
-
.map((result) => limit(async () => {
|
|
75
|
-
const filename = result.filename;
|
|
76
|
-
try {
|
|
77
|
-
// This call is now rate-limited
|
|
78
|
-
const content = await this.client.getFileContents(filename);
|
|
79
|
-
// Only extract tags from frontmatter YAML
|
|
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 || [] };
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
logger.error(`Failed to process file ${filename}:`, errorToObject(error));
|
|
90
|
-
return { filename, error: true }; // Mark as failed
|
|
91
|
-
}
|
|
92
|
-
})); // Close the limiter wrapper
|
|
93
|
-
// Execute promises in parallel and wait for all to settle
|
|
94
|
-
const processedResults = await Promise.allSettled(processingPromises);
|
|
95
|
-
// Populate the cache from settled results
|
|
96
|
-
processedResults.forEach(settledResult => {
|
|
97
|
-
// Check if the promise was fulfilled and didn't encounter a processing error
|
|
98
|
-
if (settledResult.status === 'fulfilled' && !settledResult.value.error) {
|
|
99
|
-
const { filename, tags } = settledResult.value;
|
|
100
|
-
// Ensure tags is an array before iterating
|
|
101
|
-
if (tags && Array.isArray(tags)) {
|
|
102
|
-
tags.forEach((tag) => {
|
|
103
|
-
this.addTag(tag, filename);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (settledResult.status === 'rejected') {
|
|
108
|
-
// Log unexpected rejections from the async map function itself
|
|
109
|
-
logger.error(`Unexpected error during file processing setup:`, errorToObject(settledResult.reason));
|
|
110
|
-
}
|
|
111
|
-
// Errors during getFileContents/parseProperties are already logged within the map function
|
|
112
|
-
});
|
|
113
|
-
this.isInitialized = true;
|
|
114
|
-
this.lastUpdate = Date.now();
|
|
115
|
-
const elapsedMs = logger.endTimer('init_tag_cache');
|
|
116
|
-
logger.logOperationResult(true, 'initialize_tag_cache', elapsedMs, {
|
|
117
|
-
tagCount: this.tagCache.size,
|
|
118
|
-
fileCount: results.length
|
|
119
|
-
});
|
|
120
|
-
logger.info(`Tag cache initialized with ${this.tagCache.size} unique tags`);
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
const elapsedMs = logger.endTimer('init_tag_cache');
|
|
124
|
-
logger.logOperationResult(false, 'initialize_tag_cache', elapsedMs);
|
|
125
|
-
logger.error("Failed to initialize tag cache:", errorToObject(error));
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Add a tag to the cache
|
|
131
|
-
*/
|
|
132
|
-
addTag(tag, filepath) {
|
|
133
|
-
if (!this.tagCache.has(tag)) {
|
|
134
|
-
this.tagCache.set(tag, new Set());
|
|
135
|
-
}
|
|
136
|
-
this.tagCache.get(tag).add(filepath);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Update the cache if needed, preventing race conditions.
|
|
140
|
-
*/
|
|
141
|
-
async updateCacheIfNeeded() {
|
|
142
|
-
const now = Date.now();
|
|
143
|
-
// Check if cache is fresh enough
|
|
144
|
-
if (now - this.lastUpdate <= this.updateInterval) {
|
|
145
|
-
return; // Cache is up-to-date
|
|
146
|
-
}
|
|
147
|
-
// Check if an update is already in progress
|
|
148
|
-
if (this.isUpdating) {
|
|
149
|
-
logger.debug('Cache update already in progress, skipping redundant update.');
|
|
150
|
-
// Optionally, wait for the ongoing update instead of returning immediately
|
|
151
|
-
// For now, we return to avoid complexity, potentially serving slightly stale data.
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
// Acquire the update lock
|
|
155
|
-
this.isUpdating = true;
|
|
156
|
-
logger.debug('Acquired cache update lock.');
|
|
157
|
-
try {
|
|
158
|
-
// Double-check the update condition after acquiring the lock
|
|
159
|
-
// to handle cases where another process finished updating
|
|
160
|
-
// while this one was waiting for the lock (though less likely with a simple flag).
|
|
161
|
-
const nowAfterLock = Date.now();
|
|
162
|
-
if (nowAfterLock - this.lastUpdate > this.updateInterval) {
|
|
163
|
-
logger.info('Tag cache needs update, refreshing...');
|
|
164
|
-
await this.initializeCache(); // This method updates this.lastUpdate internally
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
logger.debug('Cache was updated by another process while waiting for lock.');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
// Log error during update, but don't necessarily block other operations
|
|
172
|
-
logger.error('Error during cache update:', errorToObject(error));
|
|
173
|
-
// Decide if the error should be re-thrown or handled gracefully
|
|
174
|
-
// For now, we log and continue, allowing the lock to be released.
|
|
175
|
-
}
|
|
176
|
-
finally {
|
|
177
|
-
// Release the update lock
|
|
178
|
-
this.isUpdating = false;
|
|
179
|
-
logger.debug('Released cache update lock.');
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
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.
|
|
185
|
-
*/
|
|
186
|
-
// TODO: Verify how the path argument is passed from the tool handler
|
|
187
|
-
async getContent(filterPath) {
|
|
188
|
-
logger.startTimer('get_tags_content');
|
|
189
|
-
try {
|
|
190
|
-
if (!this.isInitialized) {
|
|
191
|
-
logger.info('Tag cache not initialized, initializing now');
|
|
192
|
-
await this.initializeCache();
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
await this.updateCacheIfNeeded();
|
|
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
|
-
}
|
|
216
|
-
const response = {
|
|
217
|
-
tags: filteredTagEntries
|
|
218
|
-
.map(({ name, files }) => ({
|
|
219
|
-
name,
|
|
220
|
-
count: files.size,
|
|
221
|
-
files: Array.from(files).sort()
|
|
222
|
-
}))
|
|
223
|
-
.sort((a, b) => b.count - a.count || a.name.localeCompare(b.name)), // Sort filtered results
|
|
224
|
-
metadata: {
|
|
225
|
-
// Note: Metadata currently reflects the entire vault cache, even when filtered.
|
|
226
|
-
// Adjust calculation here if path-specific metadata is desired.
|
|
227
|
-
totalOccurrences: Array.from(this.tagCache.values())
|
|
228
|
-
.reduce((sum, files) => sum + files.size, 0),
|
|
229
|
-
uniqueTags: this.tagCache.size,
|
|
230
|
-
scannedFiles: new Set(Array.from(this.tagCache.values())
|
|
231
|
-
.flatMap(files => Array.from(files))).size,
|
|
232
|
-
lastUpdate: this.lastUpdate
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
logger.debug(`Returning tag resource with ${response.tags.length} tags`);
|
|
236
|
-
const elapsedMs = logger.endTimer('get_tags_content');
|
|
237
|
-
logger.logOperationResult(true, 'get_tags', elapsedMs, {
|
|
238
|
-
tagCount: response.tags.length,
|
|
239
|
-
totalOccurrences: response.metadata.totalOccurrences,
|
|
240
|
-
uniqueTags: response.metadata.uniqueTags,
|
|
241
|
-
scannedFiles: response.metadata.scannedFiles
|
|
242
|
-
});
|
|
243
|
-
return [{
|
|
244
|
-
type: "text",
|
|
245
|
-
text: JSON.stringify(response, null, 2),
|
|
246
|
-
uri: this.getResourceDescription().uri
|
|
247
|
-
}];
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
const elapsedMs = logger.endTimer('get_tags_content');
|
|
251
|
-
logger.logOperationResult(false, 'get_tags', elapsedMs);
|
|
252
|
-
logger.error("Failed to get tags:", errorToObject(error));
|
|
253
|
-
throw error;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
//# sourceMappingURL=tags.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/resources/tags.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,SAAS,CAAC,CAAC,iBAAiB;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAG3B,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGtE,oCAAoC;AACpC,MAAM,MAAM,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;AAE3C;;GA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,CAAC,kBAAkB,CAAC,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE;gBACrD,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;gBAC9B,gBAAgB,EAAE,QAAQ,CAAC,QAAQ,CAAC,gBAAgB;gBACpD,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,UAAU;gBACxC,YAAY,EAAE,QAAQ,CAAC,QAAQ,CAAC,YAAY;aAC7C,CAAC,CAAC;YAEH,OAAO,CAAC;oBACN,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;oBACvC,GAAG,EAAE,IAAI,CAAC,sBAAsB,EAAE,CAAC,GAAG;iBACvC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;YACtD,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;YACxD,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;YAC1D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resource types for the MCP server
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Tag information structure
|
|
6
|
-
*/
|
|
7
|
-
export interface TagInfo {
|
|
8
|
-
name: string;
|
|
9
|
-
count: number;
|
|
10
|
-
files: string[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Tag metadata structure
|
|
14
|
-
*/
|
|
15
|
-
export interface TagMetadata {
|
|
16
|
-
totalOccurrences: number;
|
|
17
|
-
uniqueTags: number;
|
|
18
|
-
scannedFiles: number;
|
|
19
|
-
lastUpdate: number;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Tag resource response structure
|
|
23
|
-
*/
|
|
24
|
-
export interface TagResponse {
|
|
25
|
-
tags: TagInfo[];
|
|
26
|
-
metadata: TagMetadata;
|
|
27
|
-
}
|
package/dist/resources/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/resources/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/tools/base.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base class for all tool handlers
|
|
3
|
-
*/
|
|
4
|
-
import { TextContent, Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import { ObsidianClient } from "../obsidian/client.js";
|
|
6
|
-
/**
|
|
7
|
-
* Interface that all tool handlers must implement
|
|
8
|
-
*/
|
|
9
|
-
export interface ToolHandler<T = any> {
|
|
10
|
-
name: string;
|
|
11
|
-
getToolDescription(): Tool;
|
|
12
|
-
runTool(args: T): Promise<Array<TextContent>>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Base class for all tool handlers with common functionality
|
|
16
|
-
*/
|
|
17
|
-
export declare abstract class BaseToolHandler<T = Record<string, unknown>> implements ToolHandler<T> {
|
|
18
|
-
readonly name: string;
|
|
19
|
-
protected client: ObsidianClient;
|
|
20
|
-
/**
|
|
21
|
-
* Create a new tool handler
|
|
22
|
-
* @param name The name of the tool
|
|
23
|
-
* @param client The ObsidianClient instance
|
|
24
|
-
*/
|
|
25
|
-
constructor(name: string, client: ObsidianClient);
|
|
26
|
-
/**
|
|
27
|
-
* Get the tool description for MCP server
|
|
28
|
-
*/
|
|
29
|
-
abstract getToolDescription(): Tool;
|
|
30
|
-
/**
|
|
31
|
-
* Run the tool with the provided arguments
|
|
32
|
-
*/
|
|
33
|
-
abstract runTool(args: T): Promise<Array<TextContent>>;
|
|
34
|
-
/**
|
|
35
|
-
* Create a standardized response from any content type
|
|
36
|
-
* @param content The content to format for response
|
|
37
|
-
* @returns An array of TextContent objects
|
|
38
|
-
*/
|
|
39
|
-
protected createResponse(content: unknown): TextContent[];
|
|
40
|
-
/**
|
|
41
|
-
* Standard error handling for tool execution
|
|
42
|
-
* @param error The error to handle
|
|
43
|
-
* @throws ObsidianError
|
|
44
|
-
*/
|
|
45
|
-
protected handleError(error: unknown): never;
|
|
46
|
-
}
|
package/dist/tools/base.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { McpErrorCode } from "../mcp/types.js";
|
|
2
|
-
import { ObsidianError } from "../utils/errors.js";
|
|
3
|
-
import { createLogger, ErrorCategoryType } from "../utils/logging.js";
|
|
4
|
-
import { tokenCounter } from "../utils/tokenization.js";
|
|
5
|
-
// Create a logger for tool operations
|
|
6
|
-
const logger = createLogger('Tools');
|
|
7
|
-
/**
|
|
8
|
-
* Base class for all tool handlers with common functionality
|
|
9
|
-
*/
|
|
10
|
-
export class BaseToolHandler {
|
|
11
|
-
name;
|
|
12
|
-
client;
|
|
13
|
-
/**
|
|
14
|
-
* Create a new tool handler
|
|
15
|
-
* @param name The name of the tool
|
|
16
|
-
* @param client The ObsidianClient instance
|
|
17
|
-
*/
|
|
18
|
-
constructor(name, client) {
|
|
19
|
-
this.name = name;
|
|
20
|
-
this.client = client;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a standardized response from any content type
|
|
24
|
-
* @param content The content to format for response
|
|
25
|
-
* @returns An array of TextContent objects
|
|
26
|
-
*/
|
|
27
|
-
createResponse(content) {
|
|
28
|
-
let text;
|
|
29
|
-
// Handle different content types
|
|
30
|
-
if (typeof content === 'string') {
|
|
31
|
-
text = content;
|
|
32
|
-
}
|
|
33
|
-
else if (content instanceof Buffer) {
|
|
34
|
-
text = content.toString('utf-8');
|
|
35
|
-
}
|
|
36
|
-
else if (Array.isArray(content) && content.every(item => typeof item === 'string')) {
|
|
37
|
-
text = content.join('\n');
|
|
38
|
-
}
|
|
39
|
-
else if (content instanceof Error) {
|
|
40
|
-
text = `Error: ${content.message}\n${content.stack || ''}`;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
try {
|
|
44
|
-
text = JSON.stringify(content, null, 2);
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
text = String(content);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Count tokens and truncate if necessary
|
|
51
|
-
const originalTokenCount = tokenCounter.countTokens(text);
|
|
52
|
-
const truncatedText = tokenCounter.truncateToTokenLimit(text);
|
|
53
|
-
const finalTokenCount = tokenCounter.countTokens(truncatedText);
|
|
54
|
-
if (originalTokenCount > finalTokenCount) {
|
|
55
|
-
logger.debug(`[${this.name}] Response truncated`, {
|
|
56
|
-
toolName: this.name,
|
|
57
|
-
originalTokens: originalTokenCount,
|
|
58
|
-
truncatedTokens: finalTokenCount,
|
|
59
|
-
truncationPercent: Math.round((1 - finalTokenCount / originalTokenCount) * 100)
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return [{
|
|
63
|
-
type: "text",
|
|
64
|
-
text: truncatedText
|
|
65
|
-
}];
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Standard error handling for tool execution
|
|
69
|
-
* @param error The error to handle
|
|
70
|
-
* @throws ObsidianError
|
|
71
|
-
*/
|
|
72
|
-
handleError(error) {
|
|
73
|
-
if (error instanceof ObsidianError) {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
logger.error(`Tool '${this.name}' execution failed`, {
|
|
77
|
-
toolName: this.name,
|
|
78
|
-
errorMessage: error instanceof Error ? error.message : String(error),
|
|
79
|
-
errorStack: error instanceof Error ? error.stack : undefined,
|
|
80
|
-
errorCategory: ErrorCategoryType.CATEGORY_SYSTEM
|
|
81
|
-
});
|
|
82
|
-
if (error instanceof Error) {
|
|
83
|
-
throw new ObsidianError(`Tool '${this.name}' execution failed: ${error.message}`, McpErrorCode.INTERNAL_SERVER_ERROR, { originalError: error.stack });
|
|
84
|
-
}
|
|
85
|
-
throw new ObsidianError(`Tool '${this.name}' execution failed with unknown error`, McpErrorCode.INTERNAL_SERVER_ERROR, { error: String(error) });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=base.js.map
|
package/dist/tools/base.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/tools/base.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,sCAAsC;AACtC,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;AAWrC;;GAEG;AACH,MAAM,OAAgB,eAAe;IAOjB;IACN;IAPZ;;;;OAIG;IACH,YACkB,IAAY,EAClB,MAAsB;QADhB,SAAI,GAAJ,IAAI,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAgB;IAC/B,CAAC;IAYJ;;;;OAIG;IACO,cAAc,CAAC,OAAgB;QACvC,IAAI,IAAY,CAAC;QAEjB,iCAAiC;QACjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,GAAG,OAAO,CAAC;QACjB,CAAC;aAAM,IAAI,OAAO,YAAY,MAAM,EAAE,CAAC;YACrC,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACnC,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,EAAE,CAAC;YACrF,IAAI,GAAG,OAAO,CAAC,IAA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AAI,oBAAoB,EAAE;YACnD,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,YAAY,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YACpE,UAAU,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;YAC5D,aAAa,EAAE,iBAAiB,CAAC,eAAe;SACjD,CAAC,CAAC;QAEH,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,IAAI,aAAa,CACrB,SAAS,IAAI,CAAC,IAAI,uBAAuB,KAAK,CAAC,OAAO,EAAE,EACxD,YAAY,CAAC,qBAAqB,EAClC,EAAE,aAAa,EAAE,KAAK,CAAC,KAAK,EAAE,CAC/B,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,aAAa,CACrB,SAAS,IAAI,CAAC,IAAI,uCAAuC,EACzD,YAAY,CAAC,qBAAqB,EAClC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CACzB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File content manipulation tools implementation
|
|
3
|
-
*/
|
|
4
|
-
import { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import { ObsidianClient } from "../../obsidian/client.js";
|
|
6
|
-
import { BaseToolHandler } from "../base.js";
|
|
7
|
-
/**
|
|
8
|
-
* Tool names for file content operations
|
|
9
|
-
*/
|
|
10
|
-
export declare const FILE_CONTENT_TOOL_NAMES: {
|
|
11
|
-
readonly GET_FILE_CONTENTS: "obsidian_get_file_contents";
|
|
12
|
-
readonly APPEND_CONTENT: "obsidian_append_content";
|
|
13
|
-
readonly UPDATE_CONTENT: "obsidian_update_content";
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Arguments for file content operations
|
|
17
|
-
*/
|
|
18
|
-
export interface FileContentsArgs {
|
|
19
|
-
filepath: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Arguments for appending content to a file
|
|
23
|
-
*/
|
|
24
|
-
export interface AppendContentArgs {
|
|
25
|
-
filepath: string;
|
|
26
|
-
content: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Arguments for updating content of a file
|
|
30
|
-
*/
|
|
31
|
-
export interface UpdateContentArgs {
|
|
32
|
-
filepath: string;
|
|
33
|
-
content: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Tool handler for getting file contents
|
|
37
|
-
*/
|
|
38
|
-
export declare class GetFileContentsToolHandler extends BaseToolHandler<FileContentsArgs> {
|
|
39
|
-
constructor(client: ObsidianClient);
|
|
40
|
-
getToolDescription(): Tool;
|
|
41
|
-
runTool(args: FileContentsArgs): Promise<Array<any>>;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Tool handler for appending content to a file
|
|
45
|
-
*/
|
|
46
|
-
export declare class AppendContentToolHandler extends BaseToolHandler<AppendContentArgs> {
|
|
47
|
-
constructor(client: ObsidianClient);
|
|
48
|
-
getToolDescription(): Tool;
|
|
49
|
-
runTool(args: AppendContentArgs): Promise<Array<any>>;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Tool handler for updating file content
|
|
53
|
-
*/
|
|
54
|
-
export declare class UpdateContentToolHandler extends BaseToolHandler<UpdateContentArgs> {
|
|
55
|
-
constructor(client: ObsidianClient);
|
|
56
|
-
getToolDescription(): Tool;
|
|
57
|
-
runTool(args: UpdateContentArgs): Promise<Array<any>>;
|
|
58
|
-
}
|