-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgists.go
More file actions
229 lines (213 loc) · 5.9 KB
/
Copy pathgists.go
File metadata and controls
229 lines (213 loc) · 5.9 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package main
import (
"encoding/json"
"fmt"
"github.com/extism/go-pdk"
)
var (
CreateGistTool = ToolDescription{
Name: "gh-create-gist",
Description: "Create a GitHub Gist",
InputSchema: schema{
"type": "object",
"properties": props{
"description": prop("string", "Description of the gist"),
"files": SchemaProperty{
Type: "object",
Description: "Files contained in the gist.",
AdditionalProperties: &schema{
"type": "object",
"properties": schema{
"content": schema{
"type": "string",
"description": "Content of the file",
},
},
"required": []string{"content"},
},
},
},
"required": []string{"files"},
},
}
GetGistTool = ToolDescription{
Name: "gh-get-gist",
Description: "Gets a specified gist.",
InputSchema: schema{
"type": "object",
"properties": props{
"gist_id": prop("string", "The unique identifier of the gist."),
},
"required": []string{"gist_id"},
},
}
UpdateGistTool = ToolDescription{
Name: "gh-update-gist",
Description: "Lists pull requests in a specified repository. Supports different response formats via accept parameter.",
InputSchema: schema{
"type": "object",
"properties": props{
"gist_id": prop("string", "The unique identifier of the gist."),
"description": prop("string", "Description of the gist"),
"files": SchemaProperty{
Type: "object",
Description: "Files contained in the gist.",
AdditionalProperties: &schema{
"type": "object",
"properties": schema{
"content": schema{
"type": "string",
"description": "Content of the file",
},
},
"required": []string{"content"},
},
},
},
"required": []string{"gist_id"},
},
}
DeleteGistTool = ToolDescription{
Name: "gh-delete-gist",
Description: "Delete a specified gist.",
InputSchema: schema{
"type": "object",
"properties": props{
"gist_id": prop("string", "The unique identifier of the gist."),
},
"required": []string{"gist_id"},
},
}
)
var GistTools = []ToolDescription{
CreateGistTool,
GetGistTool,
UpdateGistTool,
DeleteGistTool,
}
func gistCreate(apiKey, description string, files map[string]any) CallToolResult {
url := "https://api.github.com/gists"
req := pdk.NewHTTPRequest(pdk.MethodPost, url)
req.SetHeader("Authorization", fmt.Sprintf("token %s", apiKey))
req.SetHeader("Content-Type", "application/json")
req.SetHeader("Accept", "application/vnd.github+json")
req.SetHeader("User-Agent", "github-mcpx-servlet")
data := map[string]any{
"description": description,
"files": files,
}
res, err := json.Marshal(data)
if err != nil {
return CallToolResult{
IsError: some(true),
Content: []Content{{
Type: ContentTypeText,
Text: some(fmt.Sprintf("Failed to marshal gist data: %s", err)),
}},
}
}
req.SetBody(res)
resp := req.Send()
if resp.Status() != 201 {
return CallToolResult{
IsError: some(true),
Content: []Content{{
Type: ContentTypeText,
Text: some(fmt.Sprintf("Failed to create gist: %d %s", resp.Status(), string(resp.Body()))),
}},
}
}
return CallToolResult{
Content: []Content{{
Type: ContentTypeText,
Text: some(string(resp.Body())),
}},
}
}
func gistUpdate(apiKey, gistId, description string, files map[string]any) CallToolResult {
url := fmt.Sprintf("https://api.github.com/gists/%s", gistId)
req := pdk.NewHTTPRequest(pdk.MethodPatch, url)
req.SetHeader("Authorization", fmt.Sprintf("token %s", apiKey))
req.SetHeader("Content-Type", "application/json")
req.SetHeader("Accept", "application/vnd.github+json")
req.SetHeader("User-Agent", "github-mcpx-servlet")
data := map[string]any{
"description": description,
"files": files,
}
res, err := json.Marshal(data)
if err != nil {
return CallToolResult{
IsError: some(true),
Content: []Content{{
Type: ContentTypeText,
Text: some(fmt.Sprintf("Failed to marshal gist data: %s", err)),
}},
}
}
req.SetBody(res)
resp := req.Send()
if resp.Status() != 201 {
return CallToolResult{
IsError: some(true),
Content: []Content{{
Type: ContentTypeText,
Text: some(fmt.Sprintf("Failed to create gist: %d %s", resp.Status(), string(resp.Body()))),
}},
}
}
return CallToolResult{
Content: []Content{{
Type: ContentTypeText,
Text: some(string(resp.Body())),
}},
}
}
func gistGet(apiKey, gistId string) CallToolResult {
url := fmt.Sprintf("https://api.github.com/gists/%s", gistId)
req := pdk.NewHTTPRequest(pdk.MethodGet, url)
req.SetHeader("Authorization", fmt.Sprintf("token %s", apiKey))
req.SetHeader("Content-Type", "application/json")
req.SetHeader("Accept", "application/vnd.github+json")
req.SetHeader("User-Agent", "github-mcpx-servlet")
resp := req.Send()
if resp.Status() != 201 {
return CallToolResult{
IsError: some(true),
Content: []Content{{
Type: ContentTypeText,
Text: some(fmt.Sprintf("Failed to create branch: %d %s", resp.Status(), string(resp.Body()))),
}},
}
}
return CallToolResult{
Content: []Content{{
Type: ContentTypeText,
Text: some(string(resp.Body())),
}},
}
}
func gistDelete(apiKey, gistId string) CallToolResult {
url := fmt.Sprintf("https://api.github.com/gists/%s", gistId)
req := pdk.NewHTTPRequest(pdk.MethodDelete, url)
req.SetHeader("Authorization", fmt.Sprintf("token %s", apiKey))
req.SetHeader("Content-Type", "application/json")
req.SetHeader("Accept", "application/vnd.github+json")
req.SetHeader("User-Agent", "github-mcpx-servlet")
resp := req.Send()
if resp.Status() != 201 {
return CallToolResult{
IsError: some(true),
Content: []Content{{
Type: ContentTypeText,
Text: some(fmt.Sprintf("Failed to create branch: %d %s", resp.Status(), string(resp.Body()))),
}},
}
}
return CallToolResult{
Content: []Content{{
Type: ContentTypeText,
Text: some(string(resp.Body())),
}},
}
}