backup_source
Backup Hexo blog source code to a dedicated Git branch for version control and safe storage.
Instructions
将博客源码通过 Git 备份到 hexo-source 分支
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | No | 可选的 Git 提交信息 |
Implementation Reference
- src/utils/git-runner.ts:7-23 (handler)The core implementation logic for backing up the source code via git add, commit, and push.
export async function backupSource(message?: string): Promise<string> { const commitMsg = message || `Auto backup: ${new Date().toISOString()}`; await runCommand("git add ."); try { await runCommand(`git commit -m "${commitMsg}"`); } catch (e: any) { if (e.message?.includes("nothing to commit")) { return "没有需要提交的更改。"; } throw e; } await runCommand(`git push origin ${GIT_BRANCH}`); return `源码已备份到 ${GIT_BRANCH} 分支。提交信息: ${commitMsg}`; } - src/tools/git-tools.ts:11-27 (registration)Registration of the 'backup_source' tool using MCP server, which calls the backupSource handler.
server.tool( "backup_source", "将博客源码通过 Git 备份到 hexo-source 分支", { message: z.string().optional().describe("可选的 Git 提交信息"), }, async ({ message }) => { try { const result = await backupSource(message); return { content: [{ type: "text" as const, text: `✅ ${result}` }], }; } catch (e: any) { return { content: [{ type: "text" as const, text: `备份失败: ${e.message}` }], isError: true }; } } );