Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
24b9cbb
refactor(security): migrate code_scanning, secret_scanning, dependabo…
SamMorrowDrums Dec 13, 2025
53f502c
refactor(discussions): migrate to NewTool pattern
SamMorrowDrums Dec 13, 2025
027c5a6
Refactor security_advisories tools to use NewTool pattern
SamMorrowDrums Dec 13, 2025
dbc73d5
refactor: convert projects, labels, and dynamic_tools to NewTool pattern
SamMorrowDrums Dec 13, 2025
1ba8bff
Add --features CLI flag for feature flag support
SamMorrowDrums Dec 13, 2025
59a32bb
Add validation tests for tools, resources, and prompts metadata
SamMorrowDrums Dec 13, 2025
fc8a843
Fix default toolsets behavior when not in dynamic mode
SamMorrowDrums Dec 13, 2025
48a674d
refactor: address PR review feedback for toolsets
SamMorrowDrums Dec 14, 2025
71b5f58
refactor: Apply HandlerFunc pattern to resources for stateless NewToo…
SamMorrowDrums Dec 14, 2025
edc99de
refactor: simplify ForMCPRequest switch cases
SamMorrowDrums Dec 14, 2025
f1b364d
refactor(generate_docs): use strings.Builder and AllTools() iteration
SamMorrowDrums Dec 14, 2025
d2bdbcf
feat(toolsets): add AvailableToolsets() with exclude filter
SamMorrowDrums Dec 14, 2025
83bbe87
refactor(generate_docs): hoist success logging to generateAllDocs
SamMorrowDrums Dec 14, 2025
b907604
refactor: consolidate toolset validation into ToolsetGroup
SamMorrowDrums Dec 14, 2025
02c9863
refactor: rename toolsets package to registry with builder pattern
SamMorrowDrums Dec 15, 2025
d73d98b
fix: remove unnecessary type arguments in helper_test.go
SamMorrowDrums Dec 15, 2025
a0fee3c
fix: restore correct behavior for --tools and --toolsets flags
SamMorrowDrums Dec 15, 2025
c57bae0
Move labels tools to issues toolset
SamMorrowDrums Dec 15, 2025
3a614e7
Restore labels toolset with get_label in both issues and labels
SamMorrowDrums Dec 15, 2025
a735a82
Fix instruction generation and capability advertisement
SamMorrowDrums Dec 15, 2025
34db085
Add tests for dynamic toolset management tools
SamMorrowDrums Dec 15, 2025
eb10ce0
Advertise all capabilities in dynamic toolsets mode
SamMorrowDrums Dec 15, 2025
956a9cd
Improve conformance test with dynamic tool calls and JSON normalization
SamMorrowDrums Dec 15, 2025
14d6a9e
Add conformance-report to .gitignore
SamMorrowDrums Dec 15, 2025
236ace1
Add conformance test CI workflow
SamMorrowDrums Dec 15, 2025
e335203
Add map indexes for O(1) lookups in Registry
SamMorrowDrums Dec 15, 2025
881d2bb
perf(registry): O(1) HasToolset lookup via pre-computed set
SamMorrowDrums Dec 15, 2025
fe4f78e
simplify: remove lazy toolsByName map - not needed for actual use cases
SamMorrowDrums Dec 15, 2025
1953945
Add generic tool filtering mechanisms to registry package
Copilot Dec 16, 2025
bc198ee
docs: improve filter evaluation order and FilteredTools documentation
SamMorrowDrums Dec 16, 2025
4bfc643
Refactor GenerateToolsetsHelp() to use strings.Builder pattern
Copilot Dec 15, 2025
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
189 changes: 99 additions & 90 deletions pkg/github/code_scanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
"net/http"

ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/toolsets"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/github/github-mcp-server/pkg/utils"
"github.com/google/go-github/v79/github"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
)

func GetCodeScanningAlert(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) {
return mcp.Tool{
func GetCodeScanningAlert(t translations.TranslationHelperFunc) toolsets.ServerTool {
return NewTool(
mcp.Tool{
Name: "get_code_scanning_alert",
Description: t("TOOL_GET_CODE_SCANNING_ALERT_DESCRIPTION", "Get details of a specific code scanning alert in a GitHub repository."),
Annotations: &mcp.ToolAnnotations{
Expand All @@ -42,54 +44,58 @@ func GetCodeScanningAlert(getClient GetClientFn, t translations.TranslationHelpe
Required: []string{"owner", "repo", "alertNumber"},
},
},
func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
owner, err := RequiredParam[string](args, "owner")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
repo, err := RequiredParam[string](args, "repo")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
alertNumber, err := RequiredInt(args, "alertNumber")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
func(deps ToolDependencies) mcp.ToolHandlerFor[map[string]any, any] {
return func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
owner, err := RequiredParam[string](args, "owner")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
repo, err := RequiredParam[string](args, "repo")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
alertNumber, err := RequiredInt(args, "alertNumber")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}

client, err := getClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
}
client, err := deps.GetClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
}

alert, resp, err := client.CodeScanning.GetAlert(ctx, owner, repo, int64(alertNumber))
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get alert",
resp,
err,
), nil, nil
}
defer func() { _ = resp.Body.Close() }()
alert, resp, err := client.CodeScanning.GetAlert(ctx, owner, repo, int64(alertNumber))
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get alert",
resp,
err,
), nil, nil
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil
}
return utils.NewToolResultError(fmt.Sprintf("failed to get alert: %s", string(body))), nil, nil
}

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
r, err := json.Marshal(alert)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil
return utils.NewToolResultErrorFromErr("failed to marshal alert", err), nil, nil
}
return utils.NewToolResultError(fmt.Sprintf("failed to get alert: %s", string(body))), nil, nil
}

r, err := json.Marshal(alert)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to marshal alert", err), nil, nil
return utils.NewToolResultText(string(r)), nil, nil
}

return utils.NewToolResultText(string(r)), nil, nil
}
},
)
}

func ListCodeScanningAlerts(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) {
return mcp.Tool{
func ListCodeScanningAlerts(t translations.TranslationHelperFunc) toolsets.ServerTool {
return NewTool(
mcp.Tool{
Name: "list_code_scanning_alerts",
Description: t("TOOL_LIST_CODE_SCANNING_ALERTS_DESCRIPTION", "List code scanning alerts in a GitHub repository."),
Annotations: &mcp.ToolAnnotations{
Expand Down Expand Up @@ -130,59 +136,62 @@ func ListCodeScanningAlerts(getClient GetClientFn, t translations.TranslationHel
Required: []string{"owner", "repo"},
},
},
func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
owner, err := RequiredParam[string](args, "owner")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
repo, err := RequiredParam[string](args, "repo")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
ref, err := OptionalParam[string](args, "ref")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
state, err := OptionalParam[string](args, "state")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
severity, err := OptionalParam[string](args, "severity")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
toolName, err := OptionalParam[string](args, "tool_name")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
func(deps ToolDependencies) mcp.ToolHandlerFor[map[string]any, any] {
return func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
owner, err := RequiredParam[string](args, "owner")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
repo, err := RequiredParam[string](args, "repo")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
ref, err := OptionalParam[string](args, "ref")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
state, err := OptionalParam[string](args, "state")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
severity, err := OptionalParam[string](args, "severity")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
toolName, err := OptionalParam[string](args, "tool_name")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}

client, err := getClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
}
alerts, resp, err := client.CodeScanning.ListAlertsForRepo(ctx, owner, repo, &github.AlertListOptions{Ref: ref, State: state, Severity: severity, ToolName: toolName})
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to list alerts",
resp,
err,
), nil, nil
}
defer func() { _ = resp.Body.Close() }()
client, err := deps.GetClient(ctx)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
}
alerts, resp, err := client.CodeScanning.ListAlertsForRepo(ctx, owner, repo, &github.AlertListOptions{Ref: ref, State: state, Severity: severity, ToolName: toolName})
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to list alerts",
resp,
err,
), nil, nil
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil
}
return utils.NewToolResultError(fmt.Sprintf("failed to list alerts: %s", string(body))), nil, nil
}

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
r, err := json.Marshal(alerts)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil
return utils.NewToolResultErrorFromErr("failed to marshal alerts", err), nil, nil
}
return utils.NewToolResultError(fmt.Sprintf("failed to list alerts: %s", string(body))), nil, nil
}

r, err := json.Marshal(alerts)
if err != nil {
return utils.NewToolResultErrorFromErr("failed to marshal alerts", err), nil, nil
return utils.NewToolResultText(string(r)), nil, nil
}

return utils.NewToolResultText(string(r)), nil, nil
}
},
)
}
36 changes: 20 additions & 16 deletions pkg/github/code_scanning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ import (

func Test_GetCodeScanningAlert(t *testing.T) {
// Verify tool definition once
mockClient := github.NewClient(nil)
tool, _ := GetCodeScanningAlert(stubGetClientFn(mockClient), translations.NullTranslationHelper)
require.NoError(t, toolsnaps.Test(tool.Name, tool))
toolDef := GetCodeScanningAlert(translations.NullTranslationHelper)
require.NoError(t, toolsnaps.Test(toolDef.Tool.Name, toolDef.Tool))

assert.Equal(t, "get_code_scanning_alert", tool.Name)
assert.NotEmpty(t, tool.Description)
assert.Equal(t, "get_code_scanning_alert", toolDef.Tool.Name)
assert.NotEmpty(t, toolDef.Tool.Description)

// InputSchema is of type any, need to cast to *jsonschema.Schema
schema, ok := tool.InputSchema.(*jsonschema.Schema)
schema, ok := toolDef.Tool.InputSchema.(*jsonschema.Schema)
require.True(t, ok, "InputSchema should be *jsonschema.Schema")
assert.Contains(t, schema.Properties, "owner")
assert.Contains(t, schema.Properties, "repo")
Expand Down Expand Up @@ -89,13 +88,16 @@ func Test_GetCodeScanningAlert(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
// Setup client with mock
client := github.NewClient(tc.mockedClient)
_, handler := GetCodeScanningAlert(stubGetClientFn(client), translations.NullTranslationHelper)
deps := ToolDependencies{
GetClient: stubGetClientFn(client),
}
handler := toolDef.Handler(deps)

// Create call request
request := createMCPRequest(tc.requestArgs)

// Call handler with new signature
result, _, err := handler(context.Background(), &request, tc.requestArgs)
result, err := handler(context.Background(), &request)

// Verify results
if tc.expectError {
Expand Down Expand Up @@ -127,15 +129,14 @@ func Test_GetCodeScanningAlert(t *testing.T) {

func Test_ListCodeScanningAlerts(t *testing.T) {
// Verify tool definition once
mockClient := github.NewClient(nil)
tool, _ := ListCodeScanningAlerts(stubGetClientFn(mockClient), translations.NullTranslationHelper)
require.NoError(t, toolsnaps.Test(tool.Name, tool))
toolDef := ListCodeScanningAlerts(translations.NullTranslationHelper)
require.NoError(t, toolsnaps.Test(toolDef.Tool.Name, toolDef.Tool))

assert.Equal(t, "list_code_scanning_alerts", tool.Name)
assert.NotEmpty(t, tool.Description)
assert.Equal(t, "list_code_scanning_alerts", toolDef.Tool.Name)
assert.NotEmpty(t, toolDef.Tool.Description)

// InputSchema is of type any, need to cast to *jsonschema.Schema
schema, ok := tool.InputSchema.(*jsonschema.Schema)
schema, ok := toolDef.Tool.InputSchema.(*jsonschema.Schema)
require.True(t, ok, "InputSchema should be *jsonschema.Schema")
assert.Contains(t, schema.Properties, "owner")
assert.Contains(t, schema.Properties, "repo")
Expand Down Expand Up @@ -219,13 +220,16 @@ func Test_ListCodeScanningAlerts(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
// Setup client with mock
client := github.NewClient(tc.mockedClient)
_, handler := ListCodeScanningAlerts(stubGetClientFn(client), translations.NullTranslationHelper)
deps := ToolDependencies{
GetClient: stubGetClientFn(client),
}
handler := toolDef.Handler(deps)

// Create call request
request := createMCPRequest(tc.requestArgs)

// Call handler with new signature
result, _, err := handler(context.Background(), &request, tc.requestArgs)
result, err := handler(context.Background(), &request)

// Verify results
if tc.expectError {
Expand Down
Loading