Skip to content

Commit b257846

Browse files
authored
Fix MCP setup JS typecheck failures in GitHub Actions workflow (#26546)
1 parent 4cc87b5 commit b257846

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

actions/setup/js/mcp_cli_bridge.cjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,13 @@ function showToolHelp(serverName, toolName, tools) {
565565
*/
566566
function formatResponse(responseBody, serverName) {
567567
const core = global.core;
568-
const resp = /** @type {Record<string, unknown>} */ responseBody;
568+
const resp = responseBody;
569569

570570
// Check for JSON-RPC error
571-
if (resp && resp.error) {
572-
const err = /** @type {Record<string, unknown>} */ resp.error;
573-
const message = String(err.message || "Unknown error");
574-
const code = err.code != null ? String(err.code) : "";
571+
if (resp && typeof resp === "object" && "error" in resp && resp.error && typeof resp.error === "object") {
572+
const errRecord = resp.error;
573+
const message = "message" in errRecord ? String(errRecord.message || "Unknown error") : "Unknown error";
574+
const code = "code" in errRecord && errRecord.code != null ? String(errRecord.code) : "";
575575
const errText = code ? `Error [${code}]: ${message}` : `Error: ${message}`;
576576
process.stderr.write(errText + "\n");
577577
core.error(`[${serverName}] Tool call error: ${errText}`);
@@ -581,9 +581,9 @@ function formatResponse(responseBody, serverName) {
581581
}
582582

583583
// Extract result content
584-
if (resp && resp.result) {
585-
const result = /** @type {Record<string, unknown>} */ resp.result;
586-
if (Array.isArray(result.content)) {
584+
if (resp && typeof resp === "object" && "result" in resp && resp.result && typeof resp.result === "object") {
585+
const result = resp.result;
586+
if ("content" in result && Array.isArray(result.content)) {
587587
const outputParts = [];
588588
for (const item of result.content) {
589589
const entry = /** @type {Record<string, unknown>} */ item;

actions/setup/js/mount_mcp_as_cli.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ async function fetchMCPTools(serverUrl, apiKey, core) {
196196
// Step 3: tools/list – get the available tool definitions
197197
try {
198198
const listResp = await httpPostJSON(serverUrl, { ...authHeaders, ...sessionHeader }, { jsonrpc: "2.0", id: 2, method: "tools/list" }, DEFAULT_HTTP_TIMEOUT_MS);
199-
const respBody = /** @type {Record<string, unknown>} */ listResp.body;
200-
if (respBody && respBody.result && typeof respBody.result === "object") {
201-
const result = /** @type {Record<string, unknown>} */ respBody.result;
202-
if (Array.isArray(result.tools)) {
199+
const respBody = listResp.body;
200+
if (respBody && typeof respBody === "object" && "result" in respBody && respBody.result && typeof respBody.result === "object") {
201+
const result = respBody.result;
202+
if ("tools" in result && Array.isArray(result.tools)) {
203203
return /** @type {Array<{name: string, description?: string, inputSchema?: unknown}>} */ result.tools;
204204
}
205205
}

actions/setup/js/setup_globals.cjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ const { createRateLimitAwareGithub } = require("./github_rate_limit_logger.cjs")
2525
* @param {typeof getOctokit} getOctokitFn - The getOctokit function (builtin in actions/github-script@v9)
2626
*/
2727
function setupGlobals(coreModule, githubModule, contextModule, execModule, ioModule, getOctokitFn) {
28-
// @ts-expect-error - Assigning to global properties that are declared as const
2928
global.core = coreModule;
3029
// @ts-expect-error - Assigning to global properties that are declared as const
3130
// Wrap the github object so every github.rest.*.*() call automatically logs
3231
// x-ratelimit-* headers to github_rate_limits.jsonl for observability.
3332
global.github = createRateLimitAwareGithub(githubModule);
34-
// @ts-expect-error - Assigning to global properties that are declared as const
3533
global.context = contextModule;
3634
// @ts-expect-error - Assigning to global properties that are declared as const
3735
global.exec = execModule;

actions/setup/js/shim.cjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
* `github-script`) the respective block is a no-op.
1313
*/
1414

15-
// @ts-expect-error - global.core is not declared in TypeScript but is provided by github-script
1615
if (!global.core) {
17-
// @ts-expect-error - Assigning to global properties that are declared as const
1816
global.core = {
1917
debug: /** @param {string} message */ message => console.debug(`[debug] ${message}`),
2018
info: /** @param {string} message */ message => console.info(`[info] ${message}`),
@@ -35,7 +33,6 @@ if (!global.core) {
3533
};
3634
}
3735

38-
// @ts-expect-error - global.context is not declared in TypeScript but is provided by github-script
3936
if (!global.context) {
4037
// Build a context object from GitHub Actions environment variables,
4138
// mirroring the shape of @actions/github's Context class.
@@ -59,7 +56,6 @@ if (!global.context) {
5956
const owner = slashIdx >= 0 ? repository.slice(0, slashIdx) : "";
6057
const repo = slashIdx >= 0 ? repository.slice(slashIdx + 1) : "";
6158

62-
// @ts-expect-error - Assigning to global properties that are declared as const
6359
global.context = {
6460
eventName: process.env.GITHUB_EVENT_NAME || "",
6561
sha: process.env.GITHUB_SHA || "",

actions/setup/js/start_mcp_gateway.cjs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,21 @@ async function main() {
236236

237237
// Validate gateway section
238238
core.info("Validating gateway configuration...");
239-
const gw = /** @type {Record<string, unknown> | undefined} */ configObj.gateway;
240-
if (!gw) {
239+
const gw = configObj.gateway;
240+
if (!gw || typeof gw !== "object") {
241241
core.error("ERROR: Configuration is missing required 'gateway' section");
242242
core.error("Per MCP Gateway Specification v1.0.0 section 4.1.3, the gateway section is required");
243243
process.exit(1);
244244
}
245-
if (gw.port == null) {
245+
if (!("port" in gw) || gw.port == null) {
246246
core.error("ERROR: Gateway configuration is missing required 'port' field");
247247
process.exit(1);
248248
}
249-
if (gw.domain == null) {
249+
if (!("domain" in gw) || gw.domain == null) {
250250
core.error("ERROR: Gateway configuration is missing required 'domain' field");
251251
process.exit(1);
252252
}
253-
if (gw.apiKey == null) {
253+
if (!("apiKey" in gw) || gw.apiKey == null) {
254254
core.error("ERROR: Gateway configuration is missing required 'apiKey' field");
255255
process.exit(1);
256256
}
@@ -274,7 +274,11 @@ async function main() {
274274

275275
// Split docker command into args, respecting simple quoting
276276
const args = dockerCommand.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || [];
277-
const cmd = /** @type {string} */ args.shift();
277+
const cmd = args.shift();
278+
if (!cmd) {
279+
core.error("ERROR: MCP_GATEWAY_DOCKER_COMMAND did not contain an executable command");
280+
process.exit(1);
281+
}
278282

279283
const outputFd = fs.openSync(outputPath, "w", 0o600);
280284
const stderrFd = fs.openSync(stderrLogPath, "w", 0o600);
@@ -286,6 +290,10 @@ async function main() {
286290
});
287291

288292
// Write configuration to stdin then close
293+
if (!child.stdin) {
294+
core.error("ERROR: Gateway process stdin is not available");
295+
process.exit(1);
296+
}
289297
child.stdin.write(mcpConfig);
290298
child.stdin.end();
291299

actions/setup/js/types/github-script.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ declare global {
2727
* GitHub Actions context object provided by github-script action
2828
* Contains information about the workflow run context
2929
*/
30-
const context: Context;
30+
var context: any;
3131

3232
/**
3333
* Actions core utilities provided by github-script action
3434
* For setting outputs, logging, and other workflow operations
3535
*/
36-
const core: typeof __actionsCore;
36+
var core: any;
3737

3838
/**
3939
* Actions exec utilities provided by github-script action

0 commit comments

Comments
 (0)