Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions actions/setup/js/mcp_cli_bridge.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,13 @@ function showToolHelp(serverName, toolName, tools) {
*/
function formatResponse(responseBody, serverName) {
const core = global.core;
const resp = /** @type {Record<string, unknown>} */ responseBody;
const resp = responseBody;

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

// Extract result content
if (resp && resp.result) {
const result = /** @type {Record<string, unknown>} */ resp.result;
if (Array.isArray(result.content)) {
if (resp && typeof resp === "object" && "result" in resp && resp.result && typeof resp.result === "object") {
const result = resp.result;
if ("content" in result && Array.isArray(result.content)) {
const outputParts = [];
for (const item of result.content) {
const entry = /** @type {Record<string, unknown>} */ item;
Expand Down
8 changes: 4 additions & 4 deletions actions/setup/js/mount_mcp_as_cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ async function fetchMCPTools(serverUrl, apiKey, core) {
// Step 3: tools/list – get the available tool definitions
try {
const listResp = await httpPostJSON(serverUrl, { ...authHeaders, ...sessionHeader }, { jsonrpc: "2.0", id: 2, method: "tools/list" }, DEFAULT_HTTP_TIMEOUT_MS);
const respBody = /** @type {Record<string, unknown>} */ listResp.body;
if (respBody && respBody.result && typeof respBody.result === "object") {
const result = /** @type {Record<string, unknown>} */ respBody.result;
if (Array.isArray(result.tools)) {
const respBody = listResp.body;
if (respBody && typeof respBody === "object" && "result" in respBody && respBody.result && typeof respBody.result === "object") {
const result = respBody.result;
if ("tools" in result && Array.isArray(result.tools)) {
return /** @type {Array<{name: string, description?: string, inputSchema?: unknown}>} */ result.tools;
}
}
Expand Down
2 changes: 0 additions & 2 deletions actions/setup/js/setup_globals.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ const { createRateLimitAwareGithub } = require("./github_rate_limit_logger.cjs")
* @param {typeof getOctokit} getOctokitFn - The getOctokit function (builtin in actions/github-script@v9)
*/
function setupGlobals(coreModule, githubModule, contextModule, execModule, ioModule, getOctokitFn) {
// @ts-expect-error - Assigning to global properties that are declared as const
global.core = coreModule;
// @ts-expect-error - Assigning to global properties that are declared as const
// Wrap the github object so every github.rest.*.*() call automatically logs
// x-ratelimit-* headers to github_rate_limits.jsonl for observability.
global.github = createRateLimitAwareGithub(githubModule);
// @ts-expect-error - Assigning to global properties that are declared as const
global.context = contextModule;
// @ts-expect-error - Assigning to global properties that are declared as const
global.exec = execModule;
Expand Down
4 changes: 0 additions & 4 deletions actions/setup/js/shim.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
* `github-script`) the respective block is a no-op.
*/

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

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

// @ts-expect-error - Assigning to global properties that are declared as const
global.context = {
eventName: process.env.GITHUB_EVENT_NAME || "",
sha: process.env.GITHUB_SHA || "",
Expand Down
20 changes: 14 additions & 6 deletions actions/setup/js/start_mcp_gateway.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,21 @@ async function main() {

// Validate gateway section
core.info("Validating gateway configuration...");
const gw = /** @type {Record<string, unknown> | undefined} */ configObj.gateway;
if (!gw) {
const gw = configObj.gateway;
if (!gw || typeof gw !== "object") {
core.error("ERROR: Configuration is missing required 'gateway' section");
core.error("Per MCP Gateway Specification v1.0.0 section 4.1.3, the gateway section is required");
process.exit(1);
}
if (gw.port == null) {
if (!("port" in gw) || gw.port == null) {
core.error("ERROR: Gateway configuration is missing required 'port' field");
process.exit(1);
}
if (gw.domain == null) {
if (!("domain" in gw) || gw.domain == null) {
core.error("ERROR: Gateway configuration is missing required 'domain' field");
process.exit(1);
}
if (gw.apiKey == null) {
if (!("apiKey" in gw) || gw.apiKey == null) {
core.error("ERROR: Gateway configuration is missing required 'apiKey' field");
process.exit(1);
}
Expand All @@ -274,7 +274,11 @@ async function main() {

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

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

// Write configuration to stdin then close
if (!child.stdin) {
core.error("ERROR: Gateway process stdin is not available");
process.exit(1);
}
child.stdin.write(mcpConfig);
child.stdin.end();

Expand Down
4 changes: 2 additions & 2 deletions actions/setup/js/types/github-script.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ declare global {
* GitHub Actions context object provided by github-script action
* Contains information about the workflow run context
*/
const context: Context;
var context: any;

/**
* Actions core utilities provided by github-script action
* For setting outputs, logging, and other workflow operations
*/
const core: typeof __actionsCore;
var core: any;

/**
* Actions exec utilities provided by github-script action
Expand Down
Loading