Skip to main content
Glama
create-note.ts2.36 kB
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; import type { ContentConverter } from "../converter"; import type { XiaomiNoteClient } from "../client"; import { NotesCache } from "../cache"; import type { WriteNoteEntry } from "../types"; import { buildExtraInfoString, extractSnippetFromXml } from "../note"; interface CreateNoteArgs { title?: string; content: string; folderId?: string; colorId?: number; } export function registerCreateNoteTool( server: McpServer, client: XiaomiNoteClient, converter: ContentConverter, cache: NotesCache, ): void { server.registerTool( "create_note", { description: "创建一条新的笔记", inputSchema: { title: z.string().optional().describe("笔记标题,可选"), content: z.string().min(1, "笔记内容不能为空").describe("笔记 Markdown 内容"), folderId: z.string().optional().describe("目标文件夹 ID,默认 0"), colorId: z.number().int().optional().describe("笔记颜色 ID"), }, }, async ({ title, content, folderId = "0", colorId = 0 }: CreateNoteArgs) => { const now = Date.now(); const xmlContent = converter.markdownToXml(content); const entry: WriteNoteEntry = { colorId, folderId, createDate: now, modifyDate: now, content: xmlContent, alertDate: 0, setting: { themeId: 0, stickyTime: 0, version: 0, }, extraInfo: buildExtraInfoString(title), snippet: extractSnippetFromXml(xmlContent), }; const created = await client.createNote(entry); const id = String(created.data.entry.id); const detail = await client.getNote(id); const note = detail.data.entry; cache.upsertNote(note); server.sendResourceListChanged(); await server.server.sendResourceUpdated({ uri: `minote://notes/${id}` }); return { content: [ { type: "text" as const, text: `创建成功:${id}`, }, { type: "resource_link" as const, uri: `minote://notes/${id}`, name: note.id, description: title ?? "", mimeType: "text/markdown", }, ], }; }, ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LaelLuo/mi_note_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server