Skip to content

Commit f7b9664

Browse files
committed
Add support for empty gist files
1 parent 160feee commit f7b9664

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Added the `refresh_gists` tool
44
- The list of gist resources are now sorted by modified date (descending)
5+
- Empty gist files can now be created (if desired)
56

67
## 📆 v0.4.4 (06/12/2025)
78

src/tools/files.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
22
import { Gist, RequestContext, ToolModule } from "../types.js";
3+
import { gistContent } from "../utils.js";
34

45
type FileAssertions = {
56
exists?: string;
@@ -154,7 +155,9 @@ export default {
154155

155156
await assertGistFile(context, id, { exists: filename });
156157

157-
await patchGistFile(context, id, filename, { content });
158+
await patchGistFile(context, id, filename, {
159+
content: gistContent(content),
160+
});
158161

159162
return "File updated successfully";
160163
},
@@ -168,7 +171,9 @@ export default {
168171

169172
await assertGistFile(context, id, { notExists: filename });
170173

171-
await patchGistFile(context, id, filename, { content });
174+
await patchGistFile(context, id, filename, {
175+
content: gistContent(content),
176+
});
172177

173178
return "File added successfully";
174179
},

src/tools/gist.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
22
import { Gist, ToolModule } from "../types.js";
33
import {
4+
gistContent,
45
isArchivedGist,
56
isDailyNoteGist,
67
isPromptGist,
@@ -138,7 +139,7 @@ export default {
138139
const {
139140
description = "",
140141
filename = "README.md",
141-
content,
142+
content = "",
142143
public: isPublic = false,
143144
} = args;
144145

@@ -154,7 +155,7 @@ export default {
154155
public: isPublic,
155156
files: {
156157
[filename as string]: {
157-
content,
158+
content: gistContent(content as string),
158159
},
159160
},
160161
});

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ export function isPromptGist(gist: Gist): boolean {
3636

3737
export function isContentLoaded(gist: Gist): boolean {
3838
return Object.values(gist.files).every((file) => file.content !== undefined);
39+
}
40+
41+
// Gist's aren't allowed to be empty, so we're using an
42+
// "invisible plus" as content when the content is empty.
43+
const EMPTY_FILE_CONTENT = "\u{2064}";
44+
export function gistContent(content: string): string {
45+
return content || EMPTY_FILE_CONTENT;
3946
}

0 commit comments

Comments
 (0)