Skip to content

use better raw file handling and return resources #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025
Merged

Conversation

SamMorrowDrums
Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums commented Jun 12, 2025

Closes #372

This PR attempts to address some initially poor choices for how do handle files and resources.

  • Adds an API adaptor for raw file API
  • uses text response for text files, and base64 response for binary
  • Adds URL parsing so it works in all supported environments
  • Uses resource responses (getting much better results in VSCode for example), we already have the resource handles for these and resources are the right pattern for this.
  • Drops directory handling from the template resources (it just doesn't work well)
  • Keeps the directory handling as a fallback for the tool version of get repo content.
  • Adds mocks for the new URI patterns
  • Tests it all

image

image

image

#497
CC @ko1ynnky I decided to go a bit further and getting very good results now. Thanks for the encouragement.

@Copilot Copilot AI review requested due to automatic review settings June 12, 2025 01:58
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner June 12, 2025 01:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors file handling by introducing a dedicated raw content client and updating existing resource and tool handlers to return structured text or blob resources. It also updates the server bootstrap, default toolset configuration, mocks, and tests to support the new raw client, and adds missing third-party LICENSE files and updated license listings.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
third-party/*/LICENSE Added missing LICENSE files for vendored third-party dependencies.
third-party-licenses.{windows,linux,darwin}.md Updated markdown lists to include new BSD-3-Clause dependencies.
pkg/raw/raw.go, pkg/raw/raw_mock.go, pkg/raw/raw_test.go New raw package: client adapter, mocks, and tests for raw API.
pkg/github/repository_resource.go, pkg/github/repository_resource_test.go Updated resource handler to use raw client and return resources.
pkg/github/repositories.go, pkg/github/repositories_test.go Updated GetFileContents tool to fetch via raw client and return resource results.
pkg/github/tools.go, pkg/github/server_test.go Injected getRawClient into default toolset and server tests.
internal/ghmcp/server.go Configured rawURL in API host and getRawClient in server setup.
pkg/github/helper_test.go New test helpers for extracting text and blob resources.
Comments suppressed due to low confidence (2)

pkg/raw/raw.go:22

  • The SemanticSearchRequest type is unrelated to raw file handling and is unused; consider removing it to keep the package focused.
type SemanticSearchRequest struct {

pkg/github/repository_resource.go:176

  • The code uses base64.StdEncoding.EncodeToString but the encoding/base64 package is not imported; add import "encoding/base64".
Blob:     base64.StdEncoding.EncodeToString(content),

tonytrg
tonytrg previously approved these changes Jun 12, 2025
@SamMorrowDrums SamMorrowDrums merged commit 3e32f75 into main Jun 12, 2025
16 checks passed
@SamMorrowDrums SamMorrowDrums deleted the raw-file-api branch June 12, 2025 12:54
@ko1ynnky
Copy link

@SamMorrowDrums
Thanks Sam! Great work taking this much further - your solution is way better than mine. Glad I could provide some encouragement to get the ball rolling!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_file_contents tool should have non-base64 option
3 participants