Skip to main content
Glama
leejersey

Hexo Blog MCP Server

by leejersey

preview_blog

Start a local preview server for Hexo blogs to view content changes in real-time before publishing.

Instructions

启动 Hexo 本地预览服务器(localhost:4000)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The implementation of the preview_blog tool handler in hexo-tools.ts, which starts the Hexo server.
    server.tool(
        "preview_blog",
        "启动 Hexo 本地预览服务器(localhost:4000)",
        {},
        async () => {
            try {
                // 先清理和生成
                await hexoCommand("clean");
                await hexoCommand("generate");
    
                // 启动 server(后台进程)
                if (previewProcess) {
                    previewProcess.kill();
                    previewProcess = null;
                }
    
                previewProcess = exec("npx hexo server", { cwd: BLOG_ROOT });
    
                // 等待服务启动
                await new Promise((resolve) => setTimeout(resolve, 2000));
    
                return {
                    content: [
                        {
                            type: "text" as const,
                            text: `🚀 本地预览服务器已启动!\n\n请在浏览器中打开: http://localhost:4000\n\n完成预览后,可使用 stop_preview 停止服务器。`,
                        },
                    ],
                };
            } catch (e: any) {
                return { content: [{ type: "text" as const, text: `错误: ${e.message}` }], isError: true };
            }
        }
  • Registration function registerHexoTools where preview_blog is defined.
    export function registerHexoTools(server: McpServer): void {
        // 预览博客
        server.tool(
            "preview_blog",
            "启动 Hexo 本地预览服务器(localhost:4000)",
            {},
            async () => {
                try {
                    // 先清理和生成
                    await hexoCommand("clean");
                    await hexoCommand("generate");
    
                    // 启动 server(后台进程)
                    if (previewProcess) {
                        previewProcess.kill();
                        previewProcess = null;
                    }
    
                    previewProcess = exec("npx hexo server", { cwd: BLOG_ROOT });
    
                    // 等待服务启动
                    await new Promise((resolve) => setTimeout(resolve, 2000));
    
                    return {
                        content: [
                            {
                                type: "text" as const,
                                text: `🚀 本地预览服务器已启动!\n\n请在浏览器中打开: http://localhost:4000\n\n完成预览后,可使用 stop_preview 停止服务器。`,
                            },
                        ],
                    };
                } catch (e: any) {
                    return { content: [{ type: "text" as const, text: `错误: ${e.message}` }], isError: true };
                }
            }
        );
    
        // 停止预览
        server.tool(
            "stop_preview",
            "停止正在运行的 Hexo 本地预览服务器",
            {},
            async () => {
                if (previewProcess) {
                    previewProcess.kill();
                    previewProcess = null;
                    return {
                        content: [{ type: "text" as const, text: "✅ 预览服务器已停止。" }],
                    };
                }
                return {
                    content: [{ type: "text" as const, text: "ℹ️ 当前没有正在运行的预览服务器。" }],
                };
            }
        );
    
        // 部署博客
        server.tool(
            "deploy_blog",
            "构建并发布博客到 GitHub Pages(执行 hexo clean && hexo generate && hexo deploy)",
            {},
            async () => {
                try {
                    await hexoCommand("clean");
                    const genOutput = await hexoCommand("generate");
                    const deployOutput = await hexoCommand("deploy");
                    return {
                        content: [
                            {
                                type: "text" as const,
                                text: `🎉 博客已成功发布到 GitHub Pages!\n\n网址: https://leejersey.github.io\n\n⚠️ GitHub Pages 需要 1~3 分钟刷新缓存。\n\n建议接下来执行 backup_source 备份源码。`,
                            },
                        ],
                    };
                } 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