-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
325 lines (309 loc) · 7.85 KB
/
main.ts
File metadata and controls
325 lines (309 loc) · 7.85 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
/**
* MCP Server for GitHub Actions version lookup
*
* Provides secure GitHub Action references by looking up latest versions,
* commit SHAs, and immutability status.
*/
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import { formatResultAsText, lookupAction } from "./src/tools/lookup-action.ts";
import {
analyzeWorkflow,
formatAnalyzeResultAsText,
} from "./src/tools/analyze-workflow.ts";
import {
formatLatestInMajorAsText,
formatSuggestUpdatesAsText,
getLatestInMajorVersion,
suggestUpdates,
} from "./src/tools/suggest-updates.ts";
import {
formatDocumentationResultAsText,
getActionDocumentation,
} from "./src/tools/get-action-documentation.ts";
import {
compareActionVersions,
formatCompareResultAsText,
} from "./src/tools/compare-action-versions.ts";
// Create the MCP server
const server = new McpServer({
name: "github-actions",
version: "1.0.0",
});
// Register the lookup_action tool
server.tool(
"lookup_action",
"Look up information about a GitHub Action and get secure SHA-pinned references. " +
"Checks for immutable releases and provides security recommendations.",
{
action: z
.string()
.describe(
"Action reference, e.g., 'actions/checkout' or 'actions/checkout@v4'",
),
include_all_versions: z
.boolean()
.optional()
.describe("List all available versions (default: false)"),
},
async ({ action, include_all_versions }) => {
try {
const result = await lookupAction({
action,
include_all_versions,
});
const text = formatResultAsText(result);
return {
content: [
{
type: "text" as const,
text,
},
],
};
} catch (error) {
const message = error instanceof Error
? error.message
: "Unknown error occurred";
return {
content: [
{
type: "text" as const,
text: `Error: ${message}`,
},
],
isError: true,
};
}
},
);
// Register the analyze_workflow tool
server.tool(
"analyze_workflow",
"Analyze a GitHub Actions workflow file and show version status for all actions. " +
"Reports current vs latest versions, update levels (major/minor/patch), and risk assessment.",
{
workflow_content: z
.string()
.describe("The workflow YAML content to analyze"),
only_updates: z
.boolean()
.optional()
.describe("Only show actions that need updates (default: false)"),
},
async ({ workflow_content, only_updates }) => {
try {
const result = await analyzeWorkflow({
workflow_content,
only_updates,
});
const text = formatAnalyzeResultAsText(result);
return {
content: [
{
type: "text" as const,
text,
},
],
};
} catch (error) {
const message = error instanceof Error
? error.message
: "Unknown error occurred";
return {
content: [
{
type: "text" as const,
text: `Error: ${message}`,
},
],
isError: true,
};
}
},
);
// Register the suggest_updates tool
server.tool(
"suggest_updates",
"Suggest safe updates for GitHub Actions in a workflow. " +
"Returns only safe updates (minor/patch) and suggestions to stay current within major versions.",
{
workflow_content: z
.string()
.describe("The workflow YAML content to analyze"),
risk_tolerance: z
.enum(["patch", "minor", "all"])
.optional()
.describe(
"Risk tolerance: 'patch' = only patches, 'minor' = patch + minor (default), 'all' = include major",
),
},
async ({ workflow_content, risk_tolerance }) => {
try {
const result = await suggestUpdates({
workflow_content,
risk_tolerance,
});
const text = formatSuggestUpdatesAsText(result);
return {
content: [
{
type: "text" as const,
text,
},
],
};
} catch (error) {
const message = error instanceof Error
? error.message
: "Unknown error occurred";
return {
content: [
{
type: "text" as const,
text: `Error: ${message}`,
},
],
isError: true,
};
}
},
);
// Register the get_latest_in_major tool
server.tool(
"get_latest_in_major",
"Get the latest version of a GitHub Action within the same major version. " +
"Useful for safe updates that avoid breaking changes.",
{
action: z
.string()
.describe(
"Action reference with version, e.g., 'actions/checkout@v4' or 'actions/setup-node@v4.1.0'",
),
},
async ({ action }) => {
try {
const result = await getLatestInMajorVersion({ action });
const text = formatLatestInMajorAsText(result);
return {
content: [
{
type: "text" as const,
text,
},
],
};
} catch (error) {
const message = error instanceof Error
? error.message
: "Unknown error occurred";
return {
content: [
{
type: "text" as const,
text: `Error: ${message}`,
},
],
isError: true,
};
}
},
);
// Register the get_action_documentation tool
server.tool(
"get_action_documentation",
"Get README documentation for a GitHub Action at a specific version. " +
"Useful for understanding how to use an action at a particular release.",
{
action: z
.string()
.describe(
"Action reference (e.g., 'actions/checkout' or 'actions/checkout@v4')",
),
ref: z
.string()
.optional()
.describe("Optional ref override (tag/branch/commit)"),
},
async ({ action, ref }) => {
try {
const result = await getActionDocumentation({ action, ref });
const text = formatDocumentationResultAsText(result);
return {
content: [
{
type: "text" as const,
text,
},
],
};
} catch (error) {
const message = error instanceof Error
? error.message
: "Unknown error occurred";
return {
content: [
{
type: "text" as const,
text: `Error: ${message}`,
},
],
isError: true,
};
}
},
);
// Register the compare_action_versions tool
server.tool(
"compare_action_versions",
"Compare changes between two versions of a GitHub Action. " +
"Shows release notes and identifies version update levels to help with upgrade decisions.",
{
action: z
.string()
.describe(
"Action with current version (e.g., 'actions/checkout@v4.0.2')",
),
target_version: z
.string()
.optional()
.describe("Target version (defaults to latest)"),
},
async ({ action, target_version }) => {
try {
const result = await compareActionVersions({ action, target_version });
const text = formatCompareResultAsText(result);
return {
content: [
{
type: "text" as const,
text,
},
],
};
} catch (error) {
const message = error instanceof Error
? error.message
: "Unknown error occurred";
return {
content: [
{
type: "text" as const,
text: `Error: ${message}`,
},
],
isError: true,
};
}
},
);
// Start the server with stdio transport
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch((error) => {
console.error("Server error:", error);
Deno.exit(1);
});