-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresets-resource.ts
More file actions
51 lines (48 loc) · 1.56 KB
/
presets-resource.ts
File metadata and controls
51 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { join } from "node:path";
import type { FastMCP } from "fastmcp";
import { gitTopLevel } from "./git.js";
import { jsonRespond, spreadDefined } from "./json.js";
import { loadPresetsFromGitTop, PRESET_FILE_PATH, presetLoadErrorPayload } from "./presets.js";
import { requireGitAndRoots } from "./roots.js";
export function registerPresetsResource(server: FastMCP): void {
server.addResource({
uri: "rethunk-git://presets",
name: "git-mcp-presets",
mimeType: "application/json",
async load() {
const pre = requireGitAndRoots(server, {}, undefined);
if (!pre.ok) {
return { text: jsonRespond(pre.error) };
}
const ws = pre.roots[0];
if (!ws) {
return { text: jsonRespond({ error: "no_workspace_root" }) };
}
const top = gitTopLevel(ws);
if (!top) {
return { text: jsonRespond({ error: "not_a_git_repository", path: ws }) };
}
const loaded = loadPresetsFromGitTop(top);
if (!loaded.ok) {
if (loaded.reason === "missing") {
return {
text: jsonRespond({
presetFile: join(top, PRESET_FILE_PATH),
fileExists: false,
presets: {},
}),
};
}
return { text: jsonRespond(presetLoadErrorPayload(top, loaded)) };
}
return {
text: jsonRespond({
presetFile: join(top, PRESET_FILE_PATH),
fileExists: true,
...spreadDefined("presetSchemaVersion", loaded.schemaVersion),
presets: loaded.data,
}),
};
},
});
}