MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / createNote

Function createNote

apps/desktop/src/mcp/vault-ops.ts:602–622  ·  view source on GitHub ↗
(
  root: string,
  folder: NoteFolder,
  title?: string,
  subpath = '',
  body?: string
)

Source from the content-addressed store, hash-verified

600}
601
602export async function createNote(
603 root: string,
604 folder: NoteFolder,
605 title?: string,
606 subpath = '',
607 body?: string
608): Promise<NoteMeta> {
609 if (folder === 'trash') throw new Error('Refusing to create a note directly in trash/')
610 const base = sanitizeTitle(title ?? 'Untitled')
611 const clean = subpath.replace(/^\/+|\/+$/g, '')
612 const folderAbs = await folderRoot(root, folder)
613 const dir = clean
614 ? resolveSafe(folderAbs, clean)
615 : folderAbs
616 await fs.mkdir(dir, { recursive: true })
617 const finalTitle = await uniqueTitle(dir, base)
618 const abs = path.join(dir, `${finalTitle}.md`)
619 const content = body ?? `# ${finalTitle}\n\n`
620 await fs.writeFile(abs, content, 'utf8')
621 return await readMeta(root, abs, folder)
622}
623
624export async function renameNote(root: string, rel: string, nextTitle: string): Promise<NoteMeta> {
625 const abs = resolveSafe(root, rel)

Callers 1

server.tsFile · 0.70

Calls 5

sanitizeTitleFunction · 0.85
folderRootFunction · 0.70
resolveSafeFunction · 0.70
uniqueTitleFunction · 0.70
readMetaFunction · 0.70

Tested by

no test coverage detected