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
10 changes: 9 additions & 1 deletion pkg/github/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"

ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/ifc"
"github.com/github/github-mcp-server/pkg/inventory"
"github.com/github/github-mcp-server/pkg/scopes"
"github.com/github/github-mcp-server/pkg/translations"
Expand Down Expand Up @@ -161,7 +162,14 @@ func SearchRepositories(t translations.TranslationHelperFunc) inventory.ServerTo
}
}

return utils.NewToolResultText(string(r)), nil, nil
callResult := utils.NewToolResultText(string(r))
if deps.GetFlags(ctx).InsidersMode {
if callResult.Meta == nil {
callResult.Meta = mcp.Meta{}
}
callResult.Meta["ifc"] = ifc.LabelSearchRepositories()
}
return callResult, nil, nil
},
)
}
Expand Down
61 changes: 61 additions & 0 deletions pkg/github/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,67 @@ func Test_SearchRepositories_FullOutput(t *testing.T) {
assert.Equal(t, *mockSearchResult.Repositories[0].Name, *returnedResult.Repositories[0].Name)
}

func Test_SearchRepositories_IFC_InsidersMode(t *testing.T) {
t.Parallel()

serverTool := SearchRepositories(translations.NullTranslationHelper)

mockSearchResult := &github.RepositoriesSearchResult{
Total: github.Ptr(1),
IncompleteResults: github.Ptr(false),
Repositories: []*github.Repository{{
ID: github.Ptr(int64(1)),
Name: github.Ptr("repo"),
FullName: github.Ptr("octocat/repo"),
}},
}

mockedClient := MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
GetSearchRepositories: mockResponse(t, http.StatusOK, mockSearchResult),
})
reqParams := map[string]any{"query": "octocat"}

t.Run("insiders mode disabled omits ifc label", func(t *testing.T) {
deps := BaseDeps{
Client: github.NewClient(mockedClient),
Flags: FeatureFlags{InsidersMode: false},
}
handler := serverTool.Handler(deps)

request := createMCPRequest(reqParams)
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
require.NoError(t, err)
require.False(t, result.IsError)

assert.Nil(t, result.Meta)
})

t.Run("insiders mode enabled emits public untrusted label", func(t *testing.T) {
deps := BaseDeps{
Client: github.NewClient(mockedClient),
Flags: FeatureFlags{InsidersMode: true},
}
handler := serverTool.Handler(deps)

request := createMCPRequest(reqParams)
result, err := handler(ContextWithDeps(context.Background(), deps), &request)
require.NoError(t, err)
require.False(t, result.IsError)

require.NotNil(t, result.Meta)
ifcLabel, ok := result.Meta["ifc"]
require.True(t, ok, "result meta should contain ifc key")

ifcJSON, err := json.Marshal(ifcLabel)
require.NoError(t, err)
var ifcMap map[string]any
require.NoError(t, json.Unmarshal(ifcJSON, &ifcMap))

assert.Equal(t, "untrusted", ifcMap["integrity"])
assert.Equal(t, []any{"public"}, ifcMap["confidentiality"])
})
}

func Test_SearchCode(t *testing.T) {
// Verify tool definition once
serverTool := SearchCode(translations.NullTranslationHelper)
Expand Down
9 changes: 9 additions & 0 deletions pkg/ifc/ifc.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ func LabelGetFileContents(isPrivate bool, readers []string) SecurityLabel {
return PublicUntrusted()
}

// LabelSearchRepositories returns the IFC label for a search_repositories
// result. Repository search is treated as a discovery surface: matched
// repositories are by definition already accessible to the caller through
// other means, so the joined readers are universal. Integrity is untrusted
// because repository names, descriptions, and topics are user-authored.
func LabelSearchRepositories() SecurityLabel {
return PublicUntrusted()
}

// LabelSearchIssues returns the IFC label for a search_issues result, joining
// per-repository labels across all matched repositories.
//
Expand Down
Loading