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
| Name | Required | Description | Default |
|---|---|---|---|
| filename | Yes | 文章文件名 | |
| content | Yes | 新的文章正文内容(Markdown) | |
| title | No | 可选,修改标题 | |
| tags | No | 可选,修改标签 |
Implementation Reference
- src/utils/post-manager.ts:160-174 (handler)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"); } - src/tools/post-tools.ts:113-136 (registration)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 }; } } );