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
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | 文章标题 | |
| content | No | 文章正文内容(Markdown) | |
| tags | No | 文章标签列表 |
Implementation Reference
- src/utils/post-manager.ts:131-155 (handler)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; } - src/tools/post-tools.ts:87-111 (registration)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 }; } } );