Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Repository security advisories#925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jurre merged 2 commits intomainfromjurre/repo-security-advisories
Aug 21, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
13 changes: 13 additions & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -942,6 +942,19 @@ The following sets of tools are available (all are on by default):
- `type`: Advisory type. (string, optional)
- `updated`: Filter by update date or date range (ISO 8601 date or range). (string, optional)

- **list_org_repository_security_advisories** - List org repository security advisories
- `direction`: Sort direction. (string, optional)
- `org`: The organization login. (string, required)
- `sort`: Sort field. (string, optional)
- `state`: Filter by advisory state. (string, optional)

- **list_repository_security_advisories** - List repository security advisories
- `direction`: Sort direction. (string, optional)
- `owner`: The owner of the repository. (string, required)
- `repo`: The name of the repository. (string, required)
- `sort`: Sort field. (string, optional)
- `state`: Filter by advisory state. (string, optional)

</details>

<details>
Expand Down
169 changes: 169 additions & 0 deletionspkg/github/security_advisories.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -182,6 +182,95 @@ func ListGlobalSecurityAdvisories(getClient GetClientFn, t translations.Translat
}
}

func ListRepositorySecurityAdvisories(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("list_repository_security_advisories",
mcp.WithDescription(t("TOOL_LIST_REPOSITORY_SECURITY_ADVISORIES_DESCRIPTION", "List repository security advisories for a GitHub repository.")),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_LIST_REPOSITORY_SECURITY_ADVISORIES_USER_TITLE", "List repository security advisories"),
ReadOnlyHint: ToBoolPtr(true),
}),
mcp.WithString("owner",
mcp.Required(),
mcp.Description("The owner of the repository."),
),
mcp.WithString("repo",
mcp.Required(),
mcp.Description("The name of the repository."),
),
mcp.WithString("direction",
mcp.Description("Sort direction."),
mcp.Enum("asc", "desc"),
),
mcp.WithString("sort",
mcp.Description("Sort field."),
mcp.Enum("created", "updated", "published"),
),
mcp.WithString("state",
mcp.Description("Filter by advisory state."),
mcp.Enum("triage", "draft", "published", "closed"),
),
), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
owner, err := RequiredParam[string](request, "owner")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
repo, err := RequiredParam[string](request, "repo")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

direction, err := OptionalParam[string](request, "direction")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
sortField, err := OptionalParam[string](request, "sort")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
state, err := OptionalParam[string](request, "state")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}

opts := &github.ListRepositorySecurityAdvisoriesOptions{}
if direction != "" {
opts.Direction = direction
}
if sortField != "" {
opts.Sort = sortField
}
if state != "" {
opts.State = state
}

advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisories(ctx, owner, repo, opts)
if err != nil {
return nil, fmt.Errorf("failed to list repository security advisories: %w", err)
}
defer func() { _ = resp.Body.Close() }()

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

r, err := json.Marshal(advisories)
if err != nil {
return nil, fmt.Errorf("failed to marshal advisories: %w", err)
}

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

func GetGlobalSecurityAdvisory(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("get_global_security_advisory",
mcp.WithDescription(t("TOOL_GET_GLOBAL_SECURITY_ADVISORY_DESCRIPTION", "Get a global security advisory")),
Expand DownExpand Up@@ -226,3 +315,83 @@ func GetGlobalSecurityAdvisory(getClient GetClientFn, t translations.Translation
return mcp.NewToolResultText(string(r)), nil
}
}

func ListOrgRepositorySecurityAdvisories(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("list_org_repository_security_advisories",
mcp.WithDescription(t("TOOL_LIST_ORG_REPOSITORY_SECURITY_ADVISORIES_DESCRIPTION", "List repository security advisories for a GitHub organization.")),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_LIST_ORG_REPOSITORY_SECURITY_ADVISORIES_USER_TITLE", "List org repository security advisories"),
ReadOnlyHint: ToBoolPtr(true),
}),
mcp.WithString("org",
mcp.Required(),
mcp.Description("The organization login."),
),
mcp.WithString("direction",
mcp.Description("Sort direction."),
mcp.Enum("asc", "desc"),
),
mcp.WithString("sort",
mcp.Description("Sort field."),
mcp.Enum("created", "updated", "published"),
),
mcp.WithString("state",
mcp.Description("Filter by advisory state."),
mcp.Enum("triage", "draft", "published", "closed"),
),
), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
org, err := RequiredParam[string](request, "org")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
direction, err := OptionalParam[string](request, "direction")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
sortField, err := OptionalParam[string](request, "sort")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
state, err := OptionalParam[string](request, "state")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}

client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}

opts := &github.ListRepositorySecurityAdvisoriesOptions{}
if direction != "" {
opts.Direction = direction
}
if sortField != "" {
opts.Sort = sortField
}
if state != "" {
opts.State = state
}

advisories, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisoriesForOrg(ctx, org, opts)
if err != nil {
return nil, fmt.Errorf("failed to list organization repository security advisories: %w", err)
}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
return mcp.NewToolResultError(fmt.Sprintf("failed to list organization repository advisories: %s", string(body))), nil
}

r, err := json.Marshal(advisories)
if err != nil {
return nil, fmt.Errorf("failed to marshal advisories: %w", err)
}

return mcp.NewToolResultText(string(r)), nil
}
}
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp