Skip to content

feature: repo resource #16

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 4 commits into from
Mar 18, 2025
Merged

feature: repo resource #16

merged 4 commits into from
Mar 18, 2025

Conversation

SamMorrowDrums
Copy link
Collaborator

@SamMorrowDrums SamMorrowDrums commented Mar 17, 2025

Closes: #6

Adds dynamic repository resources, providing the following templates:

repo://{owner}/{repo}/contents{/path*}
repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}
repo://{owner}/{repo}/sha/{sha}/contents{/path*}
repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}
repo://{owner}/{repo}/refs/pull/{pr_number}/head/contents{/path*}

Also the file mime type is not provided so we are using a best effort from the file extension, and using that to decide whether to send text or blob data to the consumer.

Another quirk of this, is that if you get a directory, you get the directory listing... I'm not sure if that's correct, but I have no other way to provide discovery, short of requesting all the files and returning them all too - and that seems way to greedy, even if paginated so that might need some thinking if we aren't ok with the folders returning the list of their content, rather than the actual content itself:

image

Also open to feedback regarding every part of this so far.

resources/templates/list

Request

echo '{"jsonrpc":"2.0","id":3,"params":{},"method":"resources/templates/list"}' | go run  cmd/server/main.go stdio  | jq .

Response

GitHub MCP Server running on stdio
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "resourceTemplates": [
      {
        "uriTemplate": "repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}",
        "name": "Repository Content for specific branch"
      },
      {
        "uriTemplate": "repo://{owner}/{repo}/sha/{sha}/contents{/path*}",
        "name": "Repository Content for specific commit"
      },
      {
        "uriTemplate": "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}",
        "name": "Repository Content for specific tag"
      },
      {
        "uriTemplate": "repo://{owner}/{repo}/refs/pull/{pr_number}/head/contents{/path*}",
        "name": "Repository Content for specific pull request"
      },
      {
        "uriTemplate": "repo://{owner}/{repo}/contents{/path*}",
        "name": "Repository Content"
      }
    ]
  }
}

resources/read

Request Folder

echo '{"jsonrpc":"2.0","id":3,"params":{"uri": "repo://mark3labs/mcp-go/contents/server"},"method":"resources/read"}' | go run  cmd/server/main.go stdio  | jq .

Response Folder

GitHub MCP Server running on stdio
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "contents": [
      {
        "uri": "https://github.com/mark3labs/mcp-go/blob/main/server/server.go",
        "mimeType": "file",
        "text": "server.go"
      },
      {
        "uri": "https://github.com/mark3labs/mcp-go/blob/main/server/server_test.go",
        "mimeType": "file",
        "text": "server_test.go"
      },
      {
        "uri": "https://github.com/mark3labs/mcp-go/blob/main/server/sse.go",
        "mimeType": "file",
        "text": "sse.go"
      },
      {
        "uri": "https://github.com/mark3labs/mcp-go/blob/main/server/sse_test.go",
        "mimeType": "file",
        "text": "sse_test.go"
      },
      {
        "uri": "https://github.com/mark3labs/mcp-go/blob/main/server/stdio.go",
        "mimeType": "file",
        "text": "stdio.go"
      },
      {
        "uri": "https://github.com/mark3labs/mcp-go/blob/main/server/stdio_test.go",
        "mimeType": "file",
        "text": "stdio_test.go"
      }
    ]
  }
}

Request File

echo '{"jsonrpc":"2.0","id":3,"params":{"uri": "repo://mark3labs/mcp-go/contents/README.md"},"method":"resources/read"}' | go run  cmd/server/main.go stdio  | jq .echo '{"jsonrpc":"2.0","id":3,"params":{"uri": "repo://mark3labs/mcp-go/contents/README.md"},"method":"resources/read"}' | go run  cmd/server/main.go stdio  | jq .

Response File

GitHub MCP Server running on stdio
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "contents": [
      {
        "uri": "repo://mark3labs/mcp-go/contents/README.md",
        "mimeType": "file",
        "text": "<!-- omit in toc -->\n# MCP Go 🚀\n[![Build](https://github.com/mark3labs/mcp-go/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mark3labs/mcp-go/actions/workflows/ci.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/mark3labs/mcp-go?cache)](https://goreportcard.com/report/github.com/mark3labs/mcp-go)\n[![GoDoc](https://pkg.go.dev/badge/github.com/mark3labs/mcp-go.svg)](https://pkg.go.dev/github.com/mark3labs/mcp-go)\n\n<div align=\"center\">\n\n<strong>A Go implementation of the Model Context Protocol (MCP)..."
      }
    ]
  }
}

@SamMorrowDrums SamMorrowDrums force-pushed the repo-resource branch 4 times, most recently from 3c3e6e4 to 4eb0a85 Compare March 18, 2025 16:37
@SamMorrowDrums SamMorrowDrums marked this pull request as ready for review March 18, 2025 16:45
@Copilot Copilot AI review requested due to automatic review settings March 18, 2025 16:45
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 adds dynamic repository resource support with multiple URI templates for fetching repository contents by branch, commit, tag, or pull request reference and updates the documentation accordingly.

  • Updated README.md with resource descriptions and parameters.
  • Introduced a new repository resource implementation in pkg/github/repository_resource.go.
  • Registered the new resource templates in pkg/github/server.go.

Reviewed Changes

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

File Description
README.md Added documentation for repository content endpoints and parameters.
pkg/github/repository_resource.go Introduces resource templates and handler for fetching repository content.
pkg/github/server.go Registers the new resource templates with the MCP server.
Files not reviewed (2)
  • go.mod: Language not supported
  • script/get-me: Language not supported

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

Co-authored-by: Copilot <[email protected]>
@SamMorrowDrums SamMorrowDrums merged commit 72e5f40 into main Mar 18, 2025
3 checks passed
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.

Expose Repos as Resources
2 participants