list-notes.ts•1.2 kB
import { z } from "zod";
import { ObsidianAPI } from "../api/obsidian-api.js";
import { formatErrorResponse, formatSuccessResponse } from "../utils/response-utils.js";
import { ToolDefinition, ToolHandler, ToolResponse } from "../types.js";
// Schema for list-notes tool parameters
export const ListNotesSchema = {
path: z.string().optional().describe("Optional folder path to list notes from")
};
/**
* Tool definition for listing notes
*/
export const listNotesDefinition: ToolDefinition = {
name: "listNotes",
description: "Recursively lists files and folders in the entire Vault or under a specified folder and returns the result as a tree-format string",
schema: ListNotesSchema
};
/**
* Creates a tool handler for listing notes
* @param api ObsidianAPI instance
* @returns Tool handler function
*/
export function createListNotesTool(api: ObsidianAPI): ToolHandler {
return async (params: { path?: string }): Promise<ToolResponse> => {
try {
const result = await api.listAllItemsAsTree(params.path);
return formatSuccessResponse(result);
} catch (error) {
return formatErrorResponse(`Error listing notes: ${(error as Error).message}`);
}
};
}