import { CheckPathExistsArgs } from './types/CheckPathExistsArgs.js';
import { BaseTool, ToolMetadata, ToolResponse } from './base.js';
import { PathValidationUtil, PathValidationType } from '../utils/PathValidationUtil.js';
import { validateRequiredArgs, PATH_SCHEMA } from '../utils/validation.js';
export class CheckPathExistsTool extends BaseTool<CheckPathExistsArgs> {
name = 'obsidian_check_path_exists';
description = 'Check if note or folder exists in Obsidian vault. Returns type info.';
metadata: ToolMetadata = {
category: 'file-operations',
keywords: ['check', 'exists', 'path', 'file', 'directory'],
version: '1.0.0'
};
inputSchema = {
type: 'object' as const,
properties: {
path: PATH_SCHEMA
},
required: ['path']
};
async executeTyped(args: CheckPathExistsArgs): Promise<ToolResponse> {
try {
// Validate required arguments
validateRequiredArgs(args, ['path']);
// Validate the path (can be either file or directory)
PathValidationUtil.validate(args.path, 'path', { type: PathValidationType.ANY });
const client = this.getClient();
const result = await client.checkPathExists(args.path);
return this.formatResponse({
path: args.path,
exists: result.exists,
type: result.type, // 'file', 'directory', or null
message: result.exists
? `Path exists as ${result.type}: ${args.path}`
: `Path does not exist: ${args.path}`
});
} catch (error) {
return this.handleError(error);
}
}
}