-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtools.go
More file actions
335 lines (298 loc) · 13.3 KB
/
tools.go
File metadata and controls
335 lines (298 loc) · 13.3 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
package registry
import (
"context"
"fmt"
"strings"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/runners/hello"
"github.com/ActiveState/cli/internal/runners/mcp/createrevision"
"github.com/ActiveState/cli/internal/runners/mcp/downloadlogs"
"github.com/ActiveState/cli/internal/runners/mcp/downloadsource"
"github.com/ActiveState/cli/internal/runners/mcp/ingredientdetails"
"github.com/ActiveState/cli/internal/runners/mcp/projecterrors"
"github.com/ActiveState/cli/internal/runners/mcp/rebuildproject"
"github.com/ActiveState/cli/pkg/project"
"github.com/mark3labs/mcp-go/mcp"
)
func HelloWorldTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"hello",
mcp.WithDescription("Hello world tool"),
mcp.WithString("name", mcp.Required(), mcp.Description("The name to say hello to")),
),
Handler: func(ctx context.Context, p *primer.Values, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
name, err := request.RequireString("name")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
runner := hello.New(p)
params := hello.NewParams()
params.Name = name
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}
func ProjectErrorsTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"list_project_build_failures",
mcp.WithDescription("Retrieves all the failed artifact builds for a specific project"),
mcp.WithString("namespace", mcp.Description("Project namespace in format 'owner/project'")),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
namespace, err := mcpRequest.RequireString("namespace")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a project in the format 'owner/project' is required: %s", errs.JoinMessage(err))), nil
}
ns, err := project.ParseNamespace(namespace)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error parsing project namespace: %s", errs.JoinMessage(err))), nil
}
runner := projecterrors.New(p)
params := projecterrors.NewParams(ns)
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error executing GraphQL query: %s", errs.JoinMessage(err))), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}
func DownloadLogsTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"download_logs",
mcp.WithDescription("Downloads logs from a specified URL"),
mcp.WithString("url", mcp.Description("The URL to download logs from"), mcp.Required()),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
url, err := mcpRequest.RequireString("url")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a URL is required: %s", errs.JoinMessage(err))), nil
}
runner := downloadlogs.New(p)
params := downloadlogs.NewParams(url)
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error downloading logs: %s", errs.JoinMessage(err))), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}
func GetIngredientDetailsTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"get_ingredient_details",
mcp.WithDescription("Retrieves the details for a specified ingredient, including its dependencies, status, and source URI"),
mcp.WithString("package", mcp.Description("The package to retrieve the source URI for"), mcp.Required()),
mcp.WithString("version", mcp.Description("The version of the package to retrieve the source URI for"), mcp.Required()),
mcp.WithString("namespace", mcp.Description("The language namespace of the package to retrieve the source URI for (e.g. language/python)"), mcp.Required()),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
name, err := mcpRequest.RequireString("package")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a package name is required: %s", errs.JoinMessage(err))), nil
}
version, err := mcpRequest.RequireString("version")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a package version is required: %s", errs.JoinMessage(err))), nil
}
namespace, err := mcpRequest.RequireString("namespace")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a namespace is required: %s", errs.JoinMessage(err))), nil
}
runner := ingredientdetails.New(p)
params := ingredientdetails.NewParams(name, version, namespace)
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error executing GraphQL query: %s", errs.JoinMessage(err))), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}
func ListSourceFilesTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"list_source_code_files",
mcp.WithDescription("Lists source code files from a specified source URI (HTTPS or S3)"),
mcp.WithString("sourceUri", mcp.Description("The URI (e.g. .tar.gz) to list source code files from"), mcp.Required()),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
sourceUri, err := mcpRequest.RequireString("sourceUri")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a source URI is required: %s", errs.JoinMessage(err))), nil
}
runner := downloadsource.New(p)
params := downloadsource.NewParams(sourceUri, "")
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error downloading logs: %s", errs.JoinMessage(err))), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}
func DownloadSourceFileTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"download_source_code_file",
mcp.WithDescription("Downloads a specific source code file from a specified archive URI"),
mcp.WithString("sourceUri", mcp.Description("The archive URI (e.g. .tar.gz) to download the source code file from"), mcp.Required()),
mcp.WithString("targetFile", mcp.Description("The target source code file to download"), mcp.Required()),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
sourceUri, err := mcpRequest.RequireString("sourceUri")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a source URI is required: %s", errs.JoinMessage(err))), nil
}
targetFile, err := mcpRequest.RequireString("targetFile")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a target file is required: %s", errs.JoinMessage(err))), nil
}
runner := downloadsource.New(p)
params := downloadsource.NewParams(sourceUri, targetFile)
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error downloading source file: %s", errs.JoinMessage(err))), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}
func GetInstructionsTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"get_fix_instructions",
mcp.WithDescription("Retrieves the fix format and instructions in which fixes must be provided"),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
instructions := map[string]string{
"format": `
- description: Extracted from source distribution files X, Y, and Z.
feature: python-dotenv
namespace: language/python
original_requirement: python-dotenv >=0.21.0
conditions:
- feature: python
namespace: language
requirements:
- comparator: eq
version: 3.10
requirements:
- comparator: gte
version: 0.21.0
type: runtime
`,
"instructions": `
For dependencies needed in both build and runtime phases, create separate dependency lines (one with type: build, one with type: runtime).
If an individual file is missing, such as README.md or versions.txt, the issue might be that the source code used for build did not include these files by mistake.
`,
}
return mcp.NewToolResultText(fmt.Sprintf("%v", instructions)), nil
},
}
}
func CreateIngredientRevisionTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"create_ingredient_revision",
mcp.WithDescription("Creates a new revision for the specified ingredient version"),
mcp.WithString("namespace", mcp.Description("The namespace of the ingredient, e.g. language/python"), mcp.Required()),
mcp.WithString("name", mcp.Description("The name of the ingredient, e.g. numpy"), mcp.Required()),
mcp.WithString("version", mcp.Description("The version of the ingredient, e.g. 0.1.0"), mcp.Required()),
mcp.WithString("dependencies", mcp.Description(`The JSON representation of dependencies, e.g.
[ { "conditions": [ { "feature": "alternative-built-language", "namespace": "language", "requirements": [{"comparator": "eq", "sortable_version": []}] } ], "description": "Camel build dependency", "feature": "camel", "namespace": "builder", "requirements": [{"comparator": "gte", "sortable_version": ["0"], "version": "0"}], "type": "build" }, { "conditions": null, "description": "Extracted from source distribution in PyPI.", "feature": "cython", "namespace": "language/python", "original_requirement": "Cython <3.0,>=0.29.24", "requirements": [ {"comparator": "gte", "sortable_version": ["0","0","29","24"], "version": "0.29.24"}, {"comparator": "lt", "sortable_version": ["0","3"], "version": "3.0"} ], "type": "build" }, { "conditions": null, "description": "Extracted from source distribution in PyPI.", "feature": "setuptools", "namespace": "language/python", "original_requirement": "setuptools ==59.2.0", "requirements": [{"comparator": "eq", "sortable_version": ["0","59","2"], "version": "59.2.0"}], "type": "runtime" } ]
`), mcp.Required()),
mcp.WithString("comment", mcp.Description("A short summary of the changes you made, and why you made them - including the file that declares an added or updated dependency, e.g. updated dependencies and python version, as per pyproject.toml"), mcp.Required()),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
namespace, err := mcpRequest.RequireString("namespace")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("an ingredient namespace str is required: %s", errs.JoinMessage(err))), nil
}
name, err := mcpRequest.RequireString("name")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("an ingredient name str is required: %s", errs.JoinMessage(err))), nil
}
version, err := mcpRequest.RequireString("version")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("an ingredient version str is required: %s", errs.JoinMessage(err))), nil
}
dependencies, err := mcpRequest.RequireString("dependencies")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("the ingredient dependencies str is required: %s", errs.JoinMessage(err))), nil
}
comment, err := mcpRequest.RequireString("comment")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a comment str for the ingredient is required: %s", errs.JoinMessage(err))), nil
}
params := createrevision.NewParams(namespace, name, version, dependencies, comment)
runner := createrevision.New(p)
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error creating new ingredient version revision: %s", errs.JoinMessage(err))), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}
func RebuildProjectTool() Tool {
return Tool{
Category: CategoryDebug,
Tool: mcp.NewTool(
"rebuild_project",
mcp.WithDescription("Triggers a project rebuild after all errors have been addressed"),
mcp.WithString("project", mcp.Description("Project namespace in format 'owner/project'"), mcp.Required()),
),
Handler: func(ctx context.Context, p *primer.Values, mcpRequest mcp.CallToolRequest) (*mcp.CallToolResult, error) {
namespace, err := mcpRequest.RequireString("project")
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("a project in the format 'owner/project' is required: %s", errs.JoinMessage(err))), nil
}
ns, err := project.ParseNamespace(namespace)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error parsing project namespace: %s", errs.JoinMessage(err))), nil
}
params := rebuildproject.NewParams()
params.Namespace = ns
runner := rebuildproject.New(p)
err = runner.Run(params)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("error rebuilding project: %s", errs.JoinMessage(err))), nil
}
return mcp.NewToolResultText(
strings.Join(p.Output().History().Print, "\n"),
), nil
},
}
}