Skip to content

Commit 4dfcc2c

Browse files
committed
refactor: avoid utils package name to fix revive issue
1 parent ccfec3d commit 4dfcc2c

40 files changed

+993
-990
lines changed

.github/agents/go-sdk-tool-migrator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ When generating the migration guide, consider the following aspects:
1818
* The return type for the tool constructor function should be updated from `mcp.Tool, server.ToolHandlerFunc` to `(mcp.Tool, mcp.ToolHandlerFor[map[string]any, any])`.
1919
* The tool handler function signature should be updated to use generics, changing from `func(ctx context.Context, mcp.CallToolRequest) (*mcp.CallToolResult, error)` to `func(context.Context, *mcp.CallToolRequest, map[string]any) (*mcp.CallToolResult, any, error)`.
2020
* The `RequiredParam`, `RequiredInt`, `RequiredBigInt`, `OptionalParamOK`, `OptionalParam`, `OptionalIntParam`, `OptionalIntParamWithDefault`, `OptionalBoolParamWithDefault`, `OptionalStringArrayParam`, `OptionalBigIntArrayParam` and `OptionalCursorPaginationParams` functions should be changed to use the tool arguments that are now passed as a map in the tool handler function, rather than extracting them from the `mcp.CallToolRequest`.
21-
* `mcp.NewToolResultText`, `mcp.NewToolResultError`, `mcp.NewToolResultErrorFromErr` and `mcp.NewToolResultResource` no longer available in `modelcontextprotocol/go-sdk`. There are a few helper functions available in `pkg/utils/result.go` that can be used to replace these, in the `utils` package.
21+
* `mcp.NewToolResultText`, `mcp.NewToolResultError`, `mcp.NewToolResultErrorFromErr` and `mcp.NewToolResultResource` no longer available in `modelcontextprotocol/go-sdk`. There are a few helper functions available in `pkg/mcpresult/mcpresult.go` that can be used to replace these, in the `mcpresult` package.
2222

2323
### Schema Changes
2424

internal/ghmcp/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414

1515
"github.com/github/github-mcp-server/pkg/errors"
1616
"github.com/github/github-mcp-server/pkg/github"
17+
"github.com/github/github-mcp-server/pkg/githubapi"
1718
"github.com/github/github-mcp-server/pkg/http/transport"
1819
"github.com/github/github-mcp-server/pkg/inventory"
1920
"github.com/github/github-mcp-server/pkg/lockdown"
2021
mcplog "github.com/github/github-mcp-server/pkg/log"
2122
"github.com/github/github-mcp-server/pkg/raw"
2223
"github.com/github/github-mcp-server/pkg/scopes"
2324
"github.com/github/github-mcp-server/pkg/translations"
24-
"github.com/github/github-mcp-server/pkg/utils"
2525
gogithub "github.com/google/go-github/v79/github"
2626
"github.com/modelcontextprotocol/go-sdk/mcp"
2727
"github.com/shurcooL/githubv4"
@@ -37,7 +37,7 @@ type githubClients struct {
3737
}
3838

3939
// createGitHubClients creates all the GitHub API clients needed by the server.
40-
func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolver) (*githubClients, error) {
40+
func createGitHubClients(cfg github.MCPServerConfig, apiHost githubapi.HostResolver) (*githubClients, error) {
4141
restURL, err := apiHost.BaseRESTURL(context.Background())
4242
if err != nil {
4343
return nil, fmt.Errorf("failed to get base REST URL: %w", err)
@@ -102,7 +102,7 @@ func createGitHubClients(cfg github.MCPServerConfig, apiHost utils.APIHostResolv
102102
}
103103

104104
func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Server, error) {
105-
apiHost, err := utils.NewAPIHost(cfg.Host)
105+
apiHost, err := githubapi.NewHost(cfg.Host)
106106
if err != nil {
107107
return nil, fmt.Errorf("failed to parse API host: %w", err)
108108
}
@@ -361,7 +361,7 @@ func addUserAgentsMiddleware(cfg github.MCPServerConfig, restClient *gogithub.Cl
361361
// fetchTokenScopesForHost fetches the OAuth scopes for a token from the GitHub API.
362362
// It constructs the appropriate API host URL based on the configured host.
363363
func fetchTokenScopesForHost(ctx context.Context, token, host string) ([]string, error) {
364-
apiHost, err := utils.NewAPIHost(host)
364+
apiHost, err := githubapi.NewHost(host)
365365
if err != nil {
366366
return nil, fmt.Errorf("failed to parse API host: %w", err)
367367
}

pkg/context/token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package context
33
import (
44
"context"
55

6-
"github.com/github/github-mcp-server/pkg/utils"
6+
"github.com/github/github-mcp-server/pkg/githubapi"
77
)
88

99
// tokenCtxKey is a context key for authentication token information
@@ -13,7 +13,7 @@ var tokenCtxKey tokenCtx = "tokenctx"
1313

1414
type TokenInfo struct {
1515
Token string
16-
TokenType utils.TokenType
16+
TokenType githubapi.TokenType
1717
ScopesFetched bool
1818
Scopes []string
1919
}

pkg/errors/error.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"net/http"
77

8-
"github.com/github/github-mcp-server/pkg/utils"
8+
"github.com/github/github-mcp-server/pkg/mcpresult"
99
"github.com/google/go-github/v79/github"
1010
"github.com/modelcontextprotocol/go-sdk/mcp"
1111
)
@@ -153,31 +153,31 @@ func addRawAPIErrorToContext(ctx context.Context, err *GitHubRawAPIError) (conte
153153
return nil, fmt.Errorf("context does not contain GitHubCtxErrors")
154154
}
155155

156-
// NewGitHubAPIErrorResponse returns an mcp.NewToolResultError and retains the error in the context for access via middleware
156+
// NewGitHubAPIErrorResponse returns an mcp.CallToolResult and retains the error in the context for access via middleware
157157
func NewGitHubAPIErrorResponse(ctx context.Context, message string, resp *github.Response, err error) *mcp.CallToolResult {
158158
apiErr := newGitHubAPIError(message, resp, err)
159159
if ctx != nil {
160160
_, _ = addGitHubAPIErrorToContext(ctx, apiErr) // Explicitly ignore error for graceful handling
161161
}
162-
return utils.NewToolResultErrorFromErr(message, err)
162+
return mcpresult.NewErrorFromErr(message, err)
163163
}
164164

165-
// NewGitHubGraphQLErrorResponse returns an mcp.NewToolResultError and retains the error in the context for access via middleware
165+
// NewGitHubGraphQLErrorResponse returns an mcp.CallToolResult and retains the error in the context for access via middleware
166166
func NewGitHubGraphQLErrorResponse(ctx context.Context, message string, err error) *mcp.CallToolResult {
167167
graphQLErr := newGitHubGraphQLError(message, err)
168168
if ctx != nil {
169169
_, _ = addGitHubGraphQLErrorToContext(ctx, graphQLErr) // Explicitly ignore error for graceful handling
170170
}
171-
return utils.NewToolResultErrorFromErr(message, err)
171+
return mcpresult.NewErrorFromErr(message, err)
172172
}
173173

174-
// NewGitHubRawAPIErrorResponse returns an mcp.NewToolResultError and retains the error in the context for access via middleware
174+
// NewGitHubRawAPIErrorResponse returns an mcp.CallToolResult and retains the error in the context for access via middleware
175175
func NewGitHubRawAPIErrorResponse(ctx context.Context, message string, resp *http.Response, err error) *mcp.CallToolResult {
176176
rawErr := newGitHubRawAPIError(message, resp, err)
177177
if ctx != nil {
178178
_, _ = addRawAPIErrorToContext(ctx, rawErr) // Explicitly ignore error for graceful handling
179179
}
180-
return utils.NewToolResultErrorFromErr(message, err)
180+
return mcpresult.NewErrorFromErr(message, err)
181181
}
182182

183183
// NewGitHubAPIStatusErrorResponse handles cases where the API call succeeds (err == nil)

0 commit comments

Comments
 (0)