github_code_scanning_upload_sarif
Upload SARIF data to GitHub for code scanning analysis, enabling automated detection of security vulnerabilities and code quality issues.
Instructions
Upload an analysis as SARIF data
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | owner | |
| repo | Yes | repo | |
| body | No | Request body (JSON object) |
Implementation Reference
- src/tools/code-scanning.ts:278-280 (handler)Handler function for github_code_scanning_upload_sarif that makes a POST request to /repos/{owner}/{repo}/code-scanning/sarifs with the provided body.
handler: async (args: Record<string, any>) => { return githubRequest("POST", `/repos/${args.owner}/${args.repo}/code-scanning/sarifs`, args.body, undefined); }, - src/tools/code-scanning.ts:273-277 (schema)Input schema defining the expected parameters: owner (string), repo (string), and optional body (record).
inputSchema: z.object({ owner: z.string().describe("owner"), repo: z.string().describe("repo"), body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON object)") }), - src/tools/code-scanning.ts:271-281 (registration)Tool definition registration within the codeScanningTools array, with name and description.
name: "github_code_scanning_upload_sarif", description: "Upload an analysis as SARIF data", inputSchema: z.object({ owner: z.string().describe("owner"), repo: z.string().describe("repo"), body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON object)") }), handler: async (args: Record<string, any>) => { return githubRequest("POST", `/repos/${args.owner}/${args.repo}/code-scanning/sarifs`, args.body, undefined); }, }, - src/client.ts:9-59 (helper)The githubRequest helper function that all handlers use to make authenticated API calls to GitHub.
export async function githubRequest<T>( method: string, path: string, body?: Record<string, unknown>, params?: Record<string, string | number | boolean | string[] | undefined> ): Promise<T> { const url = new URL(`${BASE_URL}${path}`); if (params) { for (const [key, value] of Object.entries(params)) { if (value === undefined || value === null || value === "") continue; if (Array.isArray(value)) { url.searchParams.set(key, value.join(",")); } else { url.searchParams.set(key, String(value)); } } } const headers: Record<string, string> = { Authorization: `Bearer ${getToken()}`, Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", "User-Agent": "github-mcp/1.0.0", }; if (body) { headers["Content-Type"] = "application/json"; } const res = await fetch(url.toString(), { method, headers, body: body ? JSON.stringify(body) : undefined, }); if (!res.ok) { const text = await res.text().catch(() => ""); let detail = text; try { const json = JSON.parse(text); detail = json.message || text; if (json.errors) detail += ` -- ${JSON.stringify(json.errors)}`; } catch {} throw new Error(`GitHub API error ${res.status}: ${detail}`); } if (res.status === 204) return {} as T; return res.json() as Promise<T>; }