Skip to main content
Glama
leejersey

Hexo Blog MCP Server

by leejersey

create_post

Generate a new blog post for Hexo with title, Markdown content, and tags to publish articles directly from AI clients.

Instructions

创建一篇新的博客文章

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYes文章标题
contentNo文章正文内容(Markdown)
tagsNo文章标签列表

Implementation Reference

  • The core implementation of the createPost function, which handles path validation, existence checks, front-matter generation, and writing the markdown file.
    export async function createPost(
        title: string,
        content?: string,
        tags?: string[]
    ): Promise<string> {
        const date = new Date().toISOString().split("T")[0];
        const filename = `${title}.md`;
        const fullPath = postPath(filename);
    
        // 检查是否已存在
        try {
            await fs.access(fullPath);
            throw new Error(`文章 "${filename}" 已存在`);
        } catch (e: any) {
            if (e.code !== "ENOENT") throw e;
        }
    
        const frontMatter: Record<string, any> = { title, date };
        if (tags && tags.length > 0) frontMatter.tags = tags;
    
        const fileContent = matter.stringify(content || "", frontMatter);
        await fs.writeFile(fullPath, fileContent, "utf-8");
    
        return filename;
    }
  • Registration of the 'create_post' MCP tool, including input schema validation using Zod and invocation of the createPost helper.
    // 创建文章
    server.tool(
        "create_post",
        "创建一篇新的博客文章",
        {
            title: z.string().describe("文章标题"),
            content: z.string().optional().describe("文章正文内容(Markdown)"),
            tags: z.array(z.string()).optional().describe("文章标签列表"),
        },
        async ({ title, content, tags }) => {
            try {
                const filename = await createPost(title, content, tags);
                return {
                    content: [
                        {
                            type: "text" as const,
                            text: `✅ 文章已创建: ${filename}\n\n可使用 read_post 查看内容,或使用 preview_blog 在本地预览。`,
                        },
                    ],
                };
            } 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