From a7665d369844457f375050352d7352ee9cad490d Mon Sep 17 00:00:00 2001 From: Derek Bredensteiner Date: Mon, 30 Jun 2025 21:56:37 -0500 Subject: [PATCH] fix: resolve CI issues - formatting and TypeScript errors (#217) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed file ingestion * working binary files * added replaced baseUrl * fix: add type assertion for GitHub blob API response Fixes TypeScript error where blobData was of type 'unknown' by adding proper type assertion for the blob creation response. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Andrew Grosser Co-Authored-By: Claude --------- Co-authored-by: Andrew Grosser Co-authored-by: Claude --- src/mcp/github-file-ops-server.ts | 59 +++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/src/mcp/github-file-ops-server.ts b/src/mcp/github-file-ops-server.ts index 9a769af..ef03178 100644 --- a/src/mcp/github-file-ops-server.ts +++ b/src/mcp/github-file-ops-server.ts @@ -125,13 +125,58 @@ server.tool( ? filePath : join(REPO_DIR, filePath); - const content = await readFile(fullPath, "utf-8"); - return { - path: filePath, - mode: "100644", - type: "blob", - content: content, - }; + // Check if file is binary (images, etc.) + const isBinaryFile = + /\.(png|jpg|jpeg|gif|webp|ico|pdf|zip|tar|gz|exe|bin|woff|woff2|ttf|eot)$/i.test( + filePath, + ); + + if (isBinaryFile) { + // For binary files, create a blob first using the Blobs API + const binaryContent = await readFile(fullPath); + + // Create blob using Blobs API (supports encoding parameter) + const blobUrl = `${GITHUB_API_URL}/repos/${owner}/${repo}/git/blobs`; + const blobResponse = await fetch(blobUrl, { + method: "POST", + headers: { + Accept: "application/vnd.github+json", + Authorization: `Bearer ${githubToken}`, + "X-GitHub-Api-Version": "2022-11-28", + "Content-Type": "application/json", + }, + body: JSON.stringify({ + content: binaryContent.toString("base64"), + encoding: "base64", + }), + }); + + if (!blobResponse.ok) { + const errorText = await blobResponse.text(); + throw new Error( + `Failed to create blob for ${filePath}: ${blobResponse.status} - ${errorText}`, + ); + } + + const blobData = (await blobResponse.json()) as { sha: string }; + + // Return tree entry with blob SHA + return { + path: filePath, + mode: "100644", + type: "blob", + sha: blobData.sha, + }; + } else { + // For text files, include content directly in tree + const content = await readFile(fullPath, "utf-8"); + return { + path: filePath, + mode: "100644", + type: "blob", + content: content, + }; + } }), );