55 "errors"
66 "fmt"
77 "net/http"
8+ "strings"
89
9- ghcontext "github.com/github/github-mcp-server/pkg/context"
1010 "github.com/github/github-mcp-server/pkg/http/transport"
1111 "github.com/github/github-mcp-server/pkg/inventory"
1212 "github.com/github/github-mcp-server/pkg/lockdown"
@@ -213,6 +213,7 @@ type RequestDeps struct {
213213 RepoAccessCache * lockdown.RepoAccessCache
214214
215215 // Static dependencies
216+ token string
216217 apiHosts * utils.ApiHost
217218 version string
218219 lockdownMode bool
@@ -224,23 +225,29 @@ type RequestDeps struct {
224225
225226// NewRequestDeps creates a RequestDeps with the provided clients and configuration.
226227func NewRequestDeps (
228+ token string ,
227229 apiHosts * utils.ApiHost ,
228230 version string ,
229231 lockdownMode bool ,
230232 repoAccessOpts []lockdown.RepoAccessOption ,
231233 t translations.TranslationHelperFunc ,
232234 flags FeatureFlags ,
233235 contentWindowSize int ,
234- ) * RequestDeps {
236+ ) (* RequestDeps , error ) {
237+ if strings .TrimSpace (token ) == "" {
238+ return nil , fmt .Errorf ("token must be provided" )
239+ }
240+
235241 return & RequestDeps {
242+ token : token ,
236243 apiHosts : apiHosts ,
237244 version : version ,
238245 lockdownMode : lockdownMode ,
239246 RepoAccessOpts : repoAccessOpts ,
240247 T : t ,
241248 Flags : flags ,
242249 ContentWindowSize : contentWindowSize ,
243- }
250+ }, nil
244251}
245252
246253// GetClient implements ToolDependencies.
@@ -249,11 +256,8 @@ func (d *RequestDeps) GetClient(ctx context.Context) (*gogithub.Client, error) {
249256 return d .Client , nil
250257 }
251258
252- // extract the token from the context
253- token , _ := ghcontext .GetTokenInfo (ctx )
254-
255259 // Construct REST client
256- restClient := gogithub .NewClient (nil ).WithAuthToken (token )
260+ restClient := gogithub .NewClient (nil ).WithAuthToken (d . token )
257261 restClient .UserAgent = fmt .Sprintf ("github-mcp-server/%s" , d .version )
258262 restClient .BaseURL = d .apiHosts .BaseRESTURL
259263 restClient .UploadURL = d .apiHosts .UploadURL
@@ -266,15 +270,12 @@ func (d *RequestDeps) GetGQLClient(ctx context.Context) (*githubv4.Client, error
266270 return d .GQLClient , nil
267271 }
268272
269- // extract the token from the context
270- token , _ := ghcontext .GetTokenInfo (ctx )
271-
272273 // Construct GraphQL client
273274 // We use NewEnterpriseClient unconditionally since we already parsed the API host
274275 gqlHTTPClient := & http.Client {
275276 Transport : & transport.BearerAuthTransport {
276277 Transport : http .DefaultTransport ,
277- Token : token ,
278+ Token : d . token ,
278279 },
279280 }
280281 gqlClient := githubv4 .NewEnterpriseClient (d .apiHosts .GraphqlURL .String (), gqlHTTPClient )
0 commit comments