Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Experiment: Make a working version of completions#451

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
SamMorrowDrums wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromcompletions-test
Draft
Show file tree
Hide file tree
Changes fromall 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
4 changes: 2 additions & 2 deletionse2e/e2e_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,8 +20,8 @@ import (
"github.com/github/github-mcp-server/pkg/github"
"github.com/github/github-mcp-server/pkg/translations"
gogithub "github.com/google/go-github/v69/github"
mcpClient "github.com/mark3labs/mcp-go/client"
"github.com/mark3labs/mcp-go/mcp"
mcpClient "github.com/sammorrowdrums/mcp-go/client"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletiongo.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,8 +5,8 @@ go 1.23.7
require (
github.com/google/go-github/v69 v69.2.0
github.com/josephburnett/jd v1.9.2
github.com/mark3labs/mcp-go v0.30.0
github.com/migueleliasweb/go-github-mock v1.3.0
github.com/sammorrowdrums/mcp-go v0.0.0-20250528234530-f0daf2216052
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1
Expand Down
4 changes: 2 additions & 2 deletionsgo.sum
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,8 +47,6 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mark3labs/mcp-go v0.30.0 h1:Taz7fiefkxY/l8jz1nA90V+WdM2eoMtlvwfWforVYbo=
github.com/mark3labs/mcp-go v0.30.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/migueleliasweb/go-github-mock v1.3.0 h1:2sVP9JEMB2ubQw1IKto3/fzF51oFC6eVWOOFDgQoq88=
github.com/migueleliasweb/go-github-mock v1.3.0/go.mod h1:ipQhV8fTcj/G6m7BKzin08GaJ/3B5/SonRAkgrk0zCY=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
Expand All@@ -62,6 +60,8 @@ github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWN
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.9.0 h1:GbgQGNtTrEmddYDSAH9QLRyfAHY12md+8YFTqyMTC9k=
github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk=
github.com/sammorrowdrums/mcp-go v0.0.0-20250528234530-f0daf2216052 h1:c9HI0HGuXED8zwXCdnk2iGyaSC8mvZlBGl+SdHxYJgs=
github.com/sammorrowdrums/mcp-go v0.0.0-20250528234530-f0daf2216052/go.mod h1:Kwt02UMWGJxJ1IHMO9Wrj4GabTSvv9uVUrpht1vjiuk=
github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7 h1:cYCy18SHPKRkvclm+pWm1Lk4YrREb4IOIb/YdFO0p2M=
github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8=
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZVHkmAsGEkcIu0oCe3AM420QDgGwZx0=
Expand Down
22 changes: 11 additions & 11 deletionsinternal/ghmcp/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,8 +16,8 @@ import (
mcplog "github.com/github/github-mcp-server/pkg/log"
"github.com/github/github-mcp-server/pkg/translations"
gogithub "github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
"github.com/shurcooL/githubv4"
"github.com/sirupsen/logrus"
)
Expand DownExpand Up@@ -91,7 +91,15 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
OnBeforeInitialize: []server.OnBeforeInitializeFunc{beforeInit},
}

ghServer := github.NewServer(cfg.Version, server.WithHooks(hooks))
getClient := func(_ context.Context) (*gogithub.Client, error) {
return restClient, nil // closing over client
}

getGQLClient := func(_ context.Context) (*githubv4.Client, error) {
return gqlClient, nil // closing over client
}

ghServer := github.NewServer(getClient, cfg.Version, server.WithHooks(hooks))

enabledToolsets := cfg.EnabledToolsets
if cfg.DynamicToolsets {
Expand All@@ -104,14 +112,6 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
}
}

getClient := func(_ context.Context) (*gogithub.Client, error) {
return restClient, nil // closing over client
}

getGQLClient := func(_ context.Context) (*githubv4.Client, error) {
return gqlClient, nil // closing over client
}

// Create default toolsets
toolsets, err := github.InitToolsets(
enabledToolsets,
Expand Down
4 changes: 2 additions & 2 deletionspkg/github/code_scanning.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,8 +9,8 @@ import (

"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
)

func GetCodeScanningAlert(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
Expand Down
4 changes: 2 additions & 2 deletionspkg/github/context_tools.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,8 @@ import (
"context"

"github.com/github/github-mcp-server/pkg/translations"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
)

// GetMe creates a tool to get details of the authenticated user.
Expand Down
4 changes: 2 additions & 2 deletionspkg/github/dynamic_tools.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,8 +7,8 @@ import (

"github.com/github/github-mcp-server/pkg/toolsets"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
)

func ToolsetEnum(toolsetGroup *toolsets.ToolsetGroup) mcp.PropertyOption {
Expand Down
2 changes: 1 addition & 1 deletionpkg/github/helper_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ import (
"net/http"
"testing"

"github.com/mark3labs/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
4 changes: 2 additions & 2 deletionspkg/github/issues.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@ import (
"github.com/github/github-mcp-server/pkg/translations"
"github.com/go-viper/mapstructure/v2"
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
"github.com/shurcooL/githubv4"
)

Expand Down
4 changes: 2 additions & 2 deletionspkg/github/notifications.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,8 @@ import (

"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
)

const (
Expand Down
4 changes: 2 additions & 2 deletionspkg/github/pullrequests.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,8 +9,8 @@ import (

"github.com/go-viper/mapstructure/v2"
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
"github.com/shurcooL/githubv4"

"github.com/github/github-mcp-server/pkg/translations"
Expand Down
5 changes: 3 additions & 2 deletionspkg/github/repositories.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,8 +9,8 @@ import (

"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
)

func GetCommit(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
Expand DownExpand Up@@ -132,6 +132,7 @@ func ListCommits(getClient GetClientFn, t translations.TranslationHelperFunc) (t
}

client, err := getClient(ctx)

if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}
Expand Down
160 changes: 160 additions & 0 deletionspkg/github/repository_completions.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
package github

import (
"context"
"fmt"
"strings"

"github.com/google/go-github/v69/github"
"github.com/sammorrowdrums/mcp-go/mcp"
)

// RepositoryResourceCompletionHandler returns a CompletionHandlerFunc for repository resource completions.
func RepositoryResourceCompletionHandler(getClient GetClientFn) func(ctx context.Context, req mcp.CompleteRequest) (*mcp.CompleteResult, error) {
return func(ctx context.Context, req mcp.CompleteRequest) (*mcp.CompleteResult, error) {
ref, ok := req.Params.Ref.(map[string]any)
if !ok || ref["type"] != "ref/resource" {
return nil, nil // Not a resource completion
}
uri, _ := ref["uri"].(string)
argName := req.Params.Argument.Name
argValue := req.Params.Argument.Value

client, err := getClient(ctx)
if err != nil {
return nil, err
}

var values []string

switch argName {
case "owner":
user, _, err := client.Users.Get(ctx, "")
if err == nil && user.GetLogin() != "" {
values = append(values, user.GetLogin())
}
orgs, _, _ := client.Organizations.List(ctx, "", nil)
for _, org := range orgs {
values = append(values, org.GetLogin())
}
case "repo":
// print the whole mcp complete request for debugging
fmt.Printf("MCP Complete Request: %+v\n", req)

fmt.Printf("URI: %s\n", uri)
owner := getArgFromURI(uri, "owner")
if owner != "" {
repos, _, err := client.Search.Repositories(ctx, fmt.Sprintf("user:%s", owner), &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}})
if err != nil || repos == nil {
break
}
for _, repo := range repos.Repositories {
if argValue == "" || strings.Contains(repo.GetName(), argValue) {
values = append(values, repo.GetName())
}
}
}
case "branch":
owner := getArgFromURI(uri, "owner")
repo := getArgFromURI(uri, "repo")
if owner != "" && repo != "" {
branches, _, _ := client.Repositories.ListBranches(ctx, owner, repo, nil)
for _, branch := range branches {
if argValue == "" || strings.Contains(branch.GetName(), argValue) {
values = append(values, branch.GetName())
}
}
}
case "sha":
owner := getArgFromURI(uri, "owner")
repo := getArgFromURI(uri, "repo")
if owner != "" && repo != "" {
commits, _, _ := client.Repositories.ListCommits(ctx, owner, repo, nil)
for _, commit := range commits {
sha := commit.GetSHA()
if argValue == "" || strings.HasPrefix(sha, argValue) {
values = append(values, sha)
}
}
}
case "tag":
owner := getArgFromURI(uri, "owner")
repo := getArgFromURI(uri, "repo")
if owner != "" && repo != "" {
tags, _, _ := client.Repositories.ListTags(ctx, owner, repo, nil)
for _, tag := range tags {
if argValue == "" || strings.Contains(tag.GetName(), argValue) {
values = append(values, tag.GetName())
}
}
}
case "prNumber":
owner := getArgFromURI(uri, "owner")
repo := getArgFromURI(uri, "repo")
if owner != "" && repo != "" {
prs, _, _ := client.PullRequests.List(ctx, owner, repo, nil)
for _, pr := range prs {
num := fmt.Sprintf("%d", pr.GetNumber())
if argValue == "" || strings.HasPrefix(num, argValue) {
values = append(values, num)
}
}
}
case "path":
owner := getArgFromURI(uri, "owner")
repo := getArgFromURI(uri, "repo")
refVal := getArgFromURI(uri, "branch")
if refVal == "" {
refVal = getArgFromURI(uri, "sha")
}
if refVal == "" {
refVal = getArgFromURI(uri, "tag")
}
if refVal == "" {
refVal = "main"
}
if owner != "" && repo != "" {
contents, dirContents, _, _ := client.Repositories.GetContents(ctx, owner, repo, "", &github.RepositoryContentGetOptions{Ref: refVal})
if dirContents != nil {
for _, entry := range dirContents {
if argValue == "" || strings.HasPrefix(entry.GetName(), argValue) {
values = append(values, entry.GetName())
}
}
} else if contents != nil {
if argValue == "" || strings.HasPrefix(contents.GetName(), argValue) {
values = append(values, contents.GetName())
}
}
}
}

if len(values) > 100 {
values = values[:100]
}

return &mcp.CompleteResult{
Completion: struct {
Values []string `json:"values"`
Total int `json:"total,omitempty"`
HasMore bool `json:"hasMore,omitempty"`
}{
Values: values,
Total: len(values),
HasMore: false,
},
}, nil
}
}

func getArgFromURI(uri, name string) string {
trimmed := strings.TrimPrefix(uri, "repo://")
parts := strings.Split(trimmed, "/")
if name == "owner" && len(parts) > 0 && parts[0] != "" {
return parts[0]
}
if name == "repo" && len(parts) > 1 && parts[1] != "" {
return parts[1]
}
return ""
}
31 changes: 31 additions & 0 deletionspkg/github/repository_completions_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
package github

import (
"context"
"testing"

"github.com/google/go-github/v69/github"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/stretchr/testify/require"
)

// Add more fake methods as needed for testing
func TestRepositoryResourceCompletionHandler_Owner(t *testing.T) {
// Stub getClient to return a fake client with a user and orgs
getClient := func(ctx context.Context) (*github.Client, error) {
client := github.NewClient(nil)
// You can use github's testing helpers or mock the methods as needed
return client, nil
}

handler := RepositoryResourceCompletionHandler(getClient)
request := mcp.CompleteRequest{}
request.Params.Ref = map[string]any{"type": "ref/resource", "uri": "repo://"}
request.Params.Argument.Name = "owner"
request.Params.Argument.Value = ""

result, err := handler(context.Background(), request)
require.NoError(t, err)
// In a real test, assert on result.Completion.Values
_ = result
}
6 changes: 3 additions & 3 deletionspkg/github/repository_resource.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,8 +13,8 @@ import (

"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/sammorrowdrums/mcp-go/server"
)

// GetRepositoryResourceContent defines the resource template and handler for getting repository content.
Expand DownExpand Up@@ -66,7 +66,7 @@ func GetRepositoryResourcePrContent(getClient GetClientFn, t translations.Transl
func RepositoryResourceContentsHandler(getClient GetClientFn) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
return func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
// the matcher will give []string with one element
// https://github.com/mark3labs/mcp-go/pull/54
// https://github.com/sammorrowdrums/mcp-go/pull/54
o, ok := request.Params.Arguments["owner"].([]string)
if !ok || len(o) == 0 {
return nil, errors.New("owner is required")
Expand Down
2 changes: 1 addition & 1 deletionpkg/github/repository_resource_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,8 +7,8 @@ import (

"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v69/github"
"github.com/mark3labs/mcp-go/mcp"
"github.com/migueleliasweb/go-github-mock/src/mock"
"github.com/sammorrowdrums/mcp-go/mcp"
"github.com/stretchr/testify/require"
)

Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp