Skip to main content
Glama
search-notes.ts1.28 kB
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; import { NotesCache } from "../cache"; export function registerSearchNotesTool(server: McpServer, cache: NotesCache): void { server.registerTool( "search_notes", { description: "根据关键词搜索笔记标题和摘要", inputSchema: { keyword: z.string().min(1, "搜索关键词不能为空"), limit: z.number().int().positive().max(100).optional().describe("返回数量限制,默认 20"), }, }, async ({ keyword, limit = 20 }: { keyword: string; limit?: number }) => { const matches = cache.searchNotes(keyword).slice(0, limit); if (matches.length === 0) { return { content: [ { type: "text" as const, text: "未找到匹配的笔记。", }, ], }; } const lines = matches.map((match, index) => { const time = new Date(match.modifyDate).toISOString(); return `${index + 1}. [${match.id}] ${match.title} (${time})`; }); return { content: [ { type: "text" as const, text: lines.join("\n"), }, ], }; }, ); }

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