Skip to content

Commit b1cb614

Browse files
committed
parse lockdown header and update GetFlags to retrieve ff from ctx
1 parent de312ee commit b1cb614

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

pkg/github/dependencies.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type ToolDependencies interface {
8686
GetT() translations.TranslationHelperFunc
8787

8888
// GetFlags returns feature flags
89-
GetFlags() FeatureFlags
89+
GetFlags(ctx context.Context) FeatureFlags
9090

9191
// GetContentWindowSize returns the content window size for log truncation
9292
GetContentWindowSize() int
@@ -153,7 +153,7 @@ func (d BaseDeps) GetRepoAccessCache(_ context.Context) (*lockdown.RepoAccessCac
153153
func (d BaseDeps) GetT() translations.TranslationHelperFunc { return d.T }
154154

155155
// GetFlags implements ToolDependencies.
156-
func (d BaseDeps) GetFlags() FeatureFlags { return d.Flags }
156+
func (d BaseDeps) GetFlags(_ context.Context) FeatureFlags { return d.Flags }
157157

158158
// GetContentWindowSize implements ToolDependencies.
159159
func (d BaseDeps) GetContentWindowSize() int { return d.ContentWindowSize }
@@ -344,7 +344,11 @@ func (d *RequestDeps) GetRepoAccessCache(ctx context.Context) (*lockdown.RepoAcc
344344
func (d *RequestDeps) GetT() translations.TranslationHelperFunc { return d.T }
345345

346346
// GetFlags implements ToolDependencies.
347-
func (d *RequestDeps) GetFlags() FeatureFlags { return d.Flags }
347+
func (d *RequestDeps) GetFlags(ctx context.Context) FeatureFlags {
348+
return FeatureFlags{
349+
LockdownMode: ghcontext.IsLockdownMode(ctx),
350+
}
351+
}
348352

349353
// GetContentWindowSize implements ToolDependencies.
350354
func (d *RequestDeps) GetContentWindowSize() int { return d.ContentWindowSize }

pkg/github/issues.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func GetIssue(ctx context.Context, client *github.Client, deps ToolDependencies,
334334
if err != nil {
335335
return nil, fmt.Errorf("failed to get repo access cache: %w", err)
336336
}
337-
flags := deps.GetFlags()
337+
flags := deps.GetFlags(ctx)
338338

339339
issue, resp, err := client.Issues.Get(ctx, owner, repo, issueNumber)
340340
if err != nil {
@@ -389,7 +389,7 @@ func GetIssueComments(ctx context.Context, client *github.Client, deps ToolDepen
389389
if err != nil {
390390
return nil, fmt.Errorf("failed to get repo access cache: %w", err)
391391
}
392-
flags := deps.GetFlags()
392+
flags := deps.GetFlags(ctx)
393393

394394
opts := &github.IssueListCommentsOptions{
395395
ListOptions: github.ListOptions{
@@ -449,7 +449,7 @@ func GetSubIssues(ctx context.Context, client *github.Client, deps ToolDependenc
449449
if err != nil {
450450
return nil, fmt.Errorf("failed to get repo access cache: %w", err)
451451
}
452-
featureFlags := deps.GetFlags()
452+
featureFlags := deps.GetFlags(ctx)
453453

454454
opts := &github.IssueListOptions{
455455
ListOptions: github.ListOptions{

pkg/github/pullrequests.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func GetPullRequest(ctx context.Context, client *github.Client, deps ToolDepende
139139
if err != nil {
140140
return nil, fmt.Errorf("failed to get repo access cache: %w", err)
141141
}
142-
ff := deps.GetFlags()
142+
ff := deps.GetFlags(ctx)
143143

144144
pr, resp, err := client.PullRequests.Get(ctx, owner, repo, pullNumber)
145145
if err != nil {
@@ -350,7 +350,7 @@ func GetPullRequestReviewComments(ctx context.Context, gqlClient *githubv4.Clien
350350
if err != nil {
351351
return nil, fmt.Errorf("failed to get repo access cache: %w", err)
352352
}
353-
ff := deps.GetFlags()
353+
ff := deps.GetFlags(ctx)
354354

355355
// Convert pagination parameters to GraphQL format
356356
gqlParams, err := pagination.ToGraphQLParams()
@@ -437,7 +437,7 @@ func GetPullRequestReviews(ctx context.Context, client *github.Client, deps Tool
437437
if err != nil {
438438
return nil, fmt.Errorf("failed to get repo access cache: %w", err)
439439
}
440-
ff := deps.GetFlags()
440+
ff := deps.GetFlags(ctx)
441441

442442
reviews, resp, err := client.PullRequests.ListReviews(ctx, owner, repo, pullNumber, nil)
443443
if err != nil {

pkg/http/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func withToolset(next http.Handler) http.Handler {
105105
}
106106

107107
func (h *HTTPMcpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
108+
if relaxedParseBool(r.Header.Get(headers.MCPLockdownHeader)) {
109+
r = r.WithContext(ghcontext.WithLockdownMode(r.Context(), true))
110+
}
111+
108112
inventory := h.inventoryFactoryFunc(r)
109113

110114
ghServer, err := h.githubMcpServerFactory(r.Context(), r, h.deps, inventory, &github.MCPServerConfig{

pkg/http/headers/headers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const (
3232
MCPToolsetsHeader = "X-MCP-Toolsets"
3333
// MCPToolsHeader is a comma-separated list of MCP tools that the request is for.
3434
MCPToolsHeader = "X-MCP-Tools"
35+
// MCPLockdownHeader indicates whether lockdown mode is enabled.
36+
MCPLockdownHeader = "X-MCP-Lockdown"
3537
// MCPFeaturesHeader is a comma-separated list of feature flags to enable.
3638
MCPFeaturesHeader = "X-MCP-Features"
3739
)

0 commit comments

Comments
 (0)