@fromsko/obsidian-mcp-server 1.1.8 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -150
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,27 +2,10 @@
|
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
-
import { exec } from "child_process";
|
|
6
5
|
import * as fs from "fs/promises";
|
|
7
6
|
import { glob } from "glob";
|
|
8
7
|
import matter from "gray-matter";
|
|
9
8
|
import * as path from "path";
|
|
10
|
-
import { promisify } from "util";
|
|
11
|
-
const execAsync = promisify(exec);
|
|
12
|
-
// Git Commit 类型定义
|
|
13
|
-
const COMMIT_TYPES = {
|
|
14
|
-
feat: { emoji: "✨", description: "新功能" },
|
|
15
|
-
fix: { emoji: "🐛", description: "Bug 修复" },
|
|
16
|
-
docs: { emoji: "📝", description: "文档更新" },
|
|
17
|
-
style: { emoji: "🎨", description: "代码格式" },
|
|
18
|
-
refactor: { emoji: "♻️", description: "重构" },
|
|
19
|
-
perf: { emoji: "⚡", description: "性能优化" },
|
|
20
|
-
test: { emoji: "✅", description: "测试" },
|
|
21
|
-
build: { emoji: "📦", description: "构建/依赖" },
|
|
22
|
-
ci: { emoji: "👷", description: "CI/CD" },
|
|
23
|
-
chore: { emoji: "🔧", description: "杂项" },
|
|
24
|
-
revert: { emoji: "⏪", description: "回滚" },
|
|
25
|
-
};
|
|
26
9
|
// 解析命令行参数
|
|
27
10
|
function parseArgs() {
|
|
28
11
|
const args = process.argv.slice(2);
|
|
@@ -369,60 +352,6 @@ created: 2024-12-26
|
|
|
369
352
|
`;
|
|
370
353
|
return guide;
|
|
371
354
|
}
|
|
372
|
-
// Git 相关函数
|
|
373
|
-
async function execGit(command, cwd) {
|
|
374
|
-
try {
|
|
375
|
-
return await execAsync(`git ${command}`, { cwd: cwd || VAULT_PATH });
|
|
376
|
-
}
|
|
377
|
-
catch (error) {
|
|
378
|
-
throw new Error(`Git 命令执行失败: ${error.message}`);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
// Git 提交
|
|
382
|
-
async function gitCommit(type, description, files, cwd) {
|
|
383
|
-
const workDir = cwd || VAULT_PATH;
|
|
384
|
-
// 验证提交类型
|
|
385
|
-
if (!COMMIT_TYPES[type]) {
|
|
386
|
-
const validTypes = Object.entries(COMMIT_TYPES)
|
|
387
|
-
.map(([k, v]) => `${v.emoji} ${k}: ${v.description}`)
|
|
388
|
-
.join("\n");
|
|
389
|
-
throw new Error(`无效的提交类型: ${type}\n\n可用类型:\n${validTypes}`);
|
|
390
|
-
}
|
|
391
|
-
const { emoji } = COMMIT_TYPES[type];
|
|
392
|
-
const commitMessage = `${emoji} ${type}: ${description}`;
|
|
393
|
-
// 添加文件
|
|
394
|
-
if (files && files.length > 0) {
|
|
395
|
-
for (const file of files) {
|
|
396
|
-
await execGit(`add "${file}"`, workDir);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
// 添加所有更改
|
|
401
|
-
await execGit("add -A", workDir);
|
|
402
|
-
}
|
|
403
|
-
// 检查是否有待提交的更改
|
|
404
|
-
const { stdout: status } = await execGit("status --porcelain", workDir);
|
|
405
|
-
if (!status.trim()) {
|
|
406
|
-
return "没有需要提交的更改";
|
|
407
|
-
}
|
|
408
|
-
// 执行提交
|
|
409
|
-
await execGit(`commit -m "${commitMessage}"`, workDir);
|
|
410
|
-
return `提交成功: ${commitMessage}`;
|
|
411
|
-
}
|
|
412
|
-
// 获取 Git 状态
|
|
413
|
-
async function gitStatus(cwd) {
|
|
414
|
-
const { stdout } = await execGit("status --short", cwd || VAULT_PATH);
|
|
415
|
-
if (!stdout.trim()) {
|
|
416
|
-
return "工作区干净,没有待提交的更改";
|
|
417
|
-
}
|
|
418
|
-
return stdout;
|
|
419
|
-
}
|
|
420
|
-
// 获取提交类型列表
|
|
421
|
-
function getCommitTypes() {
|
|
422
|
-
return Object.entries(COMMIT_TYPES)
|
|
423
|
-
.map(([type, { emoji, description }]) => `${emoji} ${type}: ${description}`)
|
|
424
|
-
.join("\n");
|
|
425
|
-
}
|
|
426
355
|
// 全文搜索
|
|
427
356
|
async function fullTextSearch(keyword) {
|
|
428
357
|
const files = await glob("**/*.md", {
|
|
@@ -586,67 +515,6 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
586
515
|
properties: {},
|
|
587
516
|
},
|
|
588
517
|
},
|
|
589
|
-
{
|
|
590
|
-
name: "git_commit",
|
|
591
|
-
description: "按照规范格式提交 Git 更改。格式: <emoji> <type>: <description>",
|
|
592
|
-
inputSchema: {
|
|
593
|
-
type: "object",
|
|
594
|
-
properties: {
|
|
595
|
-
type: {
|
|
596
|
-
type: "string",
|
|
597
|
-
description: "提交类型: feat(新功能), fix(Bug修复), docs(文档), style(格式), refactor(重构), perf(性能), test(测试), build(构建), ci(CI/CD), chore(杂项), revert(回滚)",
|
|
598
|
-
enum: [
|
|
599
|
-
"feat",
|
|
600
|
-
"fix",
|
|
601
|
-
"docs",
|
|
602
|
-
"style",
|
|
603
|
-
"refactor",
|
|
604
|
-
"perf",
|
|
605
|
-
"test",
|
|
606
|
-
"build",
|
|
607
|
-
"ci",
|
|
608
|
-
"chore",
|
|
609
|
-
"revert",
|
|
610
|
-
],
|
|
611
|
-
},
|
|
612
|
-
description: {
|
|
613
|
-
type: "string",
|
|
614
|
-
description: "提交描述(简洁明了,使用祈使语气)",
|
|
615
|
-
},
|
|
616
|
-
files: {
|
|
617
|
-
type: "array",
|
|
618
|
-
items: { type: "string" },
|
|
619
|
-
description: "要提交的文件列表(可选,留空则提交所有更改)",
|
|
620
|
-
},
|
|
621
|
-
cwd: {
|
|
622
|
-
type: "string",
|
|
623
|
-
description: "工作目录(可选,默认为笔记库路径)",
|
|
624
|
-
},
|
|
625
|
-
},
|
|
626
|
-
required: ["type", "description"],
|
|
627
|
-
},
|
|
628
|
-
},
|
|
629
|
-
{
|
|
630
|
-
name: "git_status",
|
|
631
|
-
description: "获取 Git 工作区状态",
|
|
632
|
-
inputSchema: {
|
|
633
|
-
type: "object",
|
|
634
|
-
properties: {
|
|
635
|
-
cwd: {
|
|
636
|
-
type: "string",
|
|
637
|
-
description: "工作目录(可选,默认为笔记库路径)",
|
|
638
|
-
},
|
|
639
|
-
},
|
|
640
|
-
},
|
|
641
|
-
},
|
|
642
|
-
{
|
|
643
|
-
name: "git_commit_types",
|
|
644
|
-
description: "获取所有可用的 Git 提交类型及其说明",
|
|
645
|
-
inputSchema: {
|
|
646
|
-
type: "object",
|
|
647
|
-
properties: {},
|
|
648
|
-
},
|
|
649
|
-
},
|
|
650
518
|
],
|
|
651
519
|
}));
|
|
652
520
|
// 处理工具调用
|
|
@@ -714,24 +582,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
714
582
|
content: [{ type: "text", text: guide }],
|
|
715
583
|
};
|
|
716
584
|
}
|
|
717
|
-
case "git_commit": {
|
|
718
|
-
const result = await gitCommit(args?.type, args?.description, args?.files, args?.cwd);
|
|
719
|
-
return {
|
|
720
|
-
content: [{ type: "text", text: result }],
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
case "git_status": {
|
|
724
|
-
const status = await gitStatus(args?.cwd);
|
|
725
|
-
return {
|
|
726
|
-
content: [{ type: "text", text: status }],
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
case "git_commit_types": {
|
|
730
|
-
const types = getCommitTypes();
|
|
731
|
-
return {
|
|
732
|
-
content: [{ type: "text", text: types }],
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
585
|
default:
|
|
736
586
|
throw new Error(`未知工具: ${name}`);
|
|
737
587
|
}
|