Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 9 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ linters:
- -QF1008
- -ST1000
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
enable:
- gci
- gofumpt
settings:
gci:
sections:
- standard
- default
- localmodule
11 changes: 6 additions & 5 deletions cmd/github-mcp-server/generate_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"sort"
"strings"

"github.com/google/jsonschema-go/jsonschema"
"github.com/spf13/cobra"

"github.com/github/github-mcp-server/pkg/github"
"github.com/github/github-mcp-server/pkg/inventory"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/jsonschema-go/jsonschema"
"github.com/spf13/cobra"
)

var generateDocsCmd = &cobra.Command{
Expand Down Expand Up @@ -81,7 +82,7 @@ func generateReadmeDocs(readmePath string) error {
}

// Write back to file
err = os.WriteFile(readmePath, []byte(updatedContent), 0600)
err = os.WriteFile(readmePath, []byte(updatedContent), 0o600)
if err != nil {
return fmt.Errorf("failed to write README.md: %w", err)
}
Expand Down Expand Up @@ -110,7 +111,7 @@ func generateRemoteServerDocs(docsPath string) error {
return err
}

return os.WriteFile(docsPath, []byte(updatedContent), 0600) //#nosec G306
return os.WriteFile(docsPath, []byte(updatedContent), 0o600) //#nosec G306
}

// octiconImg returns an img tag for an Octicon that works with GitHub's light/dark theme.
Expand Down Expand Up @@ -436,7 +437,7 @@ func generateDeprecatedAliasesDocs(docsPath string) error {
}

// Write back to file
err = os.WriteFile(docsPath, []byte(updatedContent), 0600)
err = os.WriteFile(docsPath, []byte(updatedContent), 0o600)
if err != nil {
return fmt.Errorf("failed to write deprecated aliases docs: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/github-mcp-server/list_scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"sort"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/github/github-mcp-server/pkg/github"
"github.com/github/github-mcp-server/pkg/inventory"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// ToolScopeInfo contains scope information for a single tool.
Expand Down
15 changes: 9 additions & 6 deletions cmd/github-mcp-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import (
"strings"
"time"

"github.com/github/github-mcp-server/internal/ghmcp"
"github.com/github/github-mcp-server/pkg/github"
ghhttp "github.com/github/github-mcp-server/pkg/http"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/github/github-mcp-server/internal/ghmcp"
"github.com/github/github-mcp-server/pkg/github"
ghhttp "github.com/github/github-mcp-server/pkg/http"
)

// These variables are set by the build process using ldflags.
var version = "version"
var commit = "commit"
var date = "date"
var (
version = "version"
commit = "commit"
date = "date"
)

var (
rootCmd = &cobra.Command{
Expand Down
10 changes: 5 additions & 5 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import (
"testing"
"time"

"github.com/github/github-mcp-server/internal/ghmcp"
"github.com/github/github-mcp-server/pkg/github"
"github.com/github/github-mcp-server/pkg/translations"
gogithub "github.com/google/go-github/v82/github"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/stretchr/testify/require"

"github.com/github/github-mcp-server/internal/ghmcp"
"github.com/github/github-mcp-server/pkg/github"
"github.com/github/github-mcp-server/pkg/translations"
)

var (
Expand Down Expand Up @@ -277,7 +278,6 @@ func TestGetMe(t *testing.T) {
user, _, err := ghClient.Users.Get(context.Background(), "")
require.NoError(t, err, "expected to get user successfully")
require.Equal(t, trimmedContent.Login, *user.Login, "expected login to match")

}

func TestToolsets(t *testing.T) {
Expand All @@ -296,7 +296,7 @@ func TestToolsets(t *testing.T) {
// We could enumerate the tools here, but we'll need to expose that information
// declaratively in the MCP server, so for the moment let's just check the existence
// of an issue and repo tool, and the non-existence of a pull_request tool.
var toolsContains = func(expectedName string) bool {
toolsContains := func(expectedName string) bool {
return slices.ContainsFunc(response.Tools, func(tool *mcp.Tool) bool {
return tool.Name == expectedName
})
Expand Down
9 changes: 5 additions & 4 deletions internal/ghmcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"syscall"
"time"

gogithub "github.com/google/go-github/v82/github"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/shurcooL/githubv4"

"github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/github"
"github.com/github/github-mcp-server/pkg/http/transport"
Expand All @@ -22,9 +26,6 @@ import (
"github.com/github/github-mcp-server/pkg/scopes"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/github/github-mcp-server/pkg/utils"
gogithub "github.com/google/go-github/v82/github"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/shurcooL/githubv4"
)

// githubClients holds all the GitHub API clients created for a server instance.
Expand Down Expand Up @@ -235,7 +236,7 @@ func RunStdioServer(cfg StdioServerConfig) error {
var slogHandler slog.Handler
var logOutput io.Writer
if cfg.LogFilePath != "" {
file, err := os.OpenFile(cfg.LogFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600)
file, err := os.OpenFile(cfg.LogFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
if err != nil {
return fmt.Errorf("failed to open log file: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package profiler
import (
"context"
"fmt"
"log/slog"
"math"
"os"
"runtime"
"strconv"
"time"

"log/slog"
"math"
)

// Profile represents performance metrics for an operation
Expand Down
4 changes: 2 additions & 2 deletions internal/toolsnaps/toolsnaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func writeSnap(snapPath string, contents []byte) error {
}

// Ensure the directory exists
if err := os.MkdirAll(filepath.Dir(snapPath), 0700); err != nil {
if err := os.MkdirAll(filepath.Dir(snapPath), 0o700); err != nil {
return fmt.Errorf("failed to create snapshot directory: %w", err)
}

// Write the snapshot file
if err := os.WriteFile(snapPath, sortedJSON, 0600); err != nil {
if err := os.WriteFile(snapPath, sortedJSON, 0o600); err != nil {
return fmt.Errorf("failed to write snapshot file: %w", err)
}

Expand Down
16 changes: 8 additions & 8 deletions internal/toolsnaps/toolsnaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func TestSnapshotExistsMatch(t *testing.T) {
// Given a matching snapshot file exists
tool := dummyTool{"foo", 42}
b, _ := json.MarshalIndent(tool, "", " ")
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), b, 0600))
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), b, 0o600))

// When we test the snapshot
err := Test("dummy", tool)
Expand All @@ -82,8 +82,8 @@ func TestSnapshotExistsDiff(t *testing.T) {
t.Setenv("UPDATE_TOOLSNAPS", "false")

// Given a non-matching snapshot file exists
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0600))
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0o600))
tool := dummyTool{"foo", 2}

// When we test the snapshot
Expand All @@ -99,8 +99,8 @@ func TestUpdateToolsnaps(t *testing.T) {

// Given UPDATE_TOOLSNAPS is set, regardless of whether a matching snapshot file exists
t.Setenv("UPDATE_TOOLSNAPS", "true")
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0600))
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`{"name":"foo","value":1}`), 0o600))
tool := dummyTool{"foo", 42}

// When we test the snapshot
Expand All @@ -120,8 +120,8 @@ func TestMalformedSnapshotJSON(t *testing.T) {
t.Setenv("UPDATE_TOOLSNAPS", "false")

// Given a malformed snapshot file exists
require.NoError(t, os.MkdirAll("__toolsnaps__", 0700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`not-json`), 0600))
require.NoError(t, os.MkdirAll("__toolsnaps__", 0o700))
require.NoError(t, os.WriteFile(filepath.Join("__toolsnaps__", "dummy.snap"), []byte(`not-json`), 0o600))
tool := dummyTool{"foo", 42}

// When we test the snapshot
Expand Down
17 changes: 10 additions & 7 deletions pkg/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"fmt"
"net/http"

"github.com/github/github-mcp-server/pkg/utils"
"github.com/google/go-github/v82/github"
"github.com/modelcontextprotocol/go-sdk/mcp"

"github.com/github/github-mcp-server/pkg/utils"
)

type GitHubAPIError struct {
Expand Down Expand Up @@ -63,12 +64,14 @@ func (e *GitHubRawAPIError) Error() string {
return fmt.Errorf("%s: %w", e.Message, e.Err).Error()
}

type GitHubErrorKey struct{}
type GitHubCtxErrors struct {
api []*GitHubAPIError
graphQL []*GitHubGraphQLError
raw []*GitHubRawAPIError
}
type (
GitHubErrorKey struct{}
GitHubCtxErrors struct {
api []*GitHubAPIError
graphQL []*GitHubGraphQLError
raw []*GitHubRawAPIError
}
)

// ContextWithGitHubErrors updates or creates a context with a pointer to GitHub error information (to be used by middleware).
func ContextWithGitHubErrors(ctx context.Context) context.Context {
Expand Down
7 changes: 4 additions & 3 deletions pkg/github/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
"strconv"
"strings"

"github.com/google/go-github/v82/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"

"github.com/github/github-mcp-server/internal/profiler"
buffer "github.com/github/github-mcp-server/pkg/buffer"
ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/inventory"
"github.com/github/github-mcp-server/pkg/scopes"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/github/github-mcp-server/pkg/utils"
"github.com/google/go-github/v82/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions pkg/github/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"net/http"
"testing"

"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v82/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/translations"
)

// Tests for consolidated actions tools
Expand Down
7 changes: 4 additions & 3 deletions pkg/github/code_scanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"io"
"net/http"

"github.com/google/go-github/v82/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"

ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/inventory"
"github.com/github/github-mcp-server/pkg/scopes"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/github/github-mcp-server/pkg/utils"
"github.com/google/go-github/v82/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
)

func GetCodeScanningAlert(t translations.TranslationHelperFunc) inventory.ServerTool {
Expand Down
6 changes: 3 additions & 3 deletions pkg/github/code_scanning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"net/http"
"testing"

"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v82/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/translations"
)

func Test_GetCodeScanningAlert(t *testing.T) {
Expand Down Expand Up @@ -115,7 +116,6 @@ func Test_GetCodeScanningAlert(t *testing.T) {
assert.Equal(t, *tc.expectedAlert.State, *returnedAlert.State)
assert.Equal(t, *tc.expectedAlert.Rule.ID, *returnedAlert.Rule.ID)
assert.Equal(t, *tc.expectedAlert.HTMLURL, *returnedAlert.HTMLURL)

})
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/github/context_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"time"

"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/shurcooL/githubv4"

ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/inventory"
"github.com/github/github-mcp-server/pkg/scopes"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/github/github-mcp-server/pkg/utils"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/shurcooL/githubv4"
)

// GetMeUIResourceURI is the URI for the get_me tool's MCP App UI resource.
Expand Down
7 changes: 4 additions & 3 deletions pkg/github/context_tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"testing"
"time"

"github.com/github/github-mcp-server/internal/githubv4mock"
"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/google/go-github/v82/github"
"github.com/shurcooL/githubv4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/github/github-mcp-server/internal/githubv4mock"
"github.com/github/github-mcp-server/internal/toolsnaps"
"github.com/github/github-mcp-server/pkg/translations"
)

func Test_GetMe(t *testing.T) {
Expand Down
Loading
Loading