Skip to main content
Glama
leejersey

Hexo Blog MCP Server

by leejersey

update_post

Modify content or metadata of existing Hexo blog posts to update articles with new text, titles, or tags.

Instructions

修改指定文章的内容或元数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes文章文件名
contentYes新的文章正文内容(Markdown)
titleNo可选,修改标题
tagsNo可选,修改标签

Implementation Reference

  • The core handler logic for updating a post, reading existing front-matter and merging it with new content and provided metadata.
    export async function updatePost(
        filename: string,
        content: string,
        frontMatter?: Record<string, any>
    ): Promise<void> {
        const fullPath = postPath(filename);
    
        // 先读取现有 front-matter
        const raw = await fs.readFile(fullPath, "utf-8");
        const { data: existingData } = matter(raw);
    
        const mergedData = { ...existingData, ...frontMatter };
        const fileContent = matter.stringify(content, mergedData);
        await fs.writeFile(fullPath, fileContent, "utf-8");
    }
  • Registration of the "update_post" tool in the MCP server, defining its schema and mapping input parameters to the updatePost utility.
    // 更新文章
    server.tool(
        "update_post",
        "修改指定文章的内容或元数据",
        {
            filename: z.string().describe("文章文件名"),
            content: z.string().describe("新的文章正文内容(Markdown)"),
            title: z.string().optional().describe("可选,修改标题"),
            tags: z.array(z.string()).optional().describe("可选,修改标签"),
        },
        async ({ filename, content, title, tags }) => {
            try {
                const fm: Record<string, any> = {};
                if (title) fm.title = title;
                if (tags) fm.tags = tags;
                await updatePost(filename, content, Object.keys(fm).length > 0 ? fm : undefined);
                return {
                    content: [{ type: "text" as const, text: `✅ 文章 "${filename}" 已更新。` }],
                };
            } 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