Skip to main content
Glama
leejersey

Hexo Blog MCP Server

by leejersey

search_posts

Search Hexo blog posts by keyword to find specific articles in titles and content using this MCP server tool.

Instructions

按关键词搜索文章标题和正文内容

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes搜索关键词

Implementation Reference

  • The core logic for searching posts, which iterates through markdown files and checks if the title or content contains the query string.
    export async function searchPosts(query: string): Promise<PostMeta[]> {
        const files = await fs.readdir(POSTS_DIR);
        const mdFiles = files.filter((f) => f.endsWith(".md"));
        const q = query.toLowerCase();
        const results: PostMeta[] = [];
    
        for (const file of mdFiles) {
            const fullPath = path.join(POSTS_DIR, file);
            const raw = await fs.readFile(fullPath, "utf-8");
            const { data, content } = matter(raw);
    
            if (
                (data.title && String(data.title).toLowerCase().includes(q)) ||
                content.toLowerCase().includes(q)
            ) {
                results.push({
                    title: data.title || file.replace(/\.md$/, ""),
                    date: data.date ? String(data.date) : "未知",
                    tags: Array.isArray(data.tags) ? data.tags : data.tags ? [data.tags] : [],
                    filename: file,
                    wordCount: content.length,
                });
            }
        }
    
        return results;
    }
  • Tool registration for "search_posts" which uses the Zod schema for input validation and calls the handler from `post-manager.ts`.
    server.tool(
        "search_posts",
        "按关键词搜索文章标题和正文内容",
        { query: z.string().describe("搜索关键词") },
        async ({ query }) => {
            try {
                const results = await searchPosts(query);
                if (results.length === 0) {
                    return { content: [{ type: "text" as const, text: `未找到包含 "${query}" 的文章。` }] };
                }
                const summary = results
                    .map((p, i) => `${i + 1}. 【${p.title}】 (${p.date}) - ${p.filename}`)
                    .join("\n");
                return {
                    content: [
                        { type: "text" as const, text: `找到 ${results.length} 篇相关文章:\n\n${summary}` },
                    ],
                };
            } catch (e: any) {
                return { content: [{ type: "text" as const, text: `错误: ${e.message}` }], isError: true };
            }
        }
    );

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/leejersey/hexo-mcp-server'

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