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

Commit183d17a

Browse files
committed
Merge branch 'omgitsads/go-sdk' into copilot/migrate-dependabot-toolset
2 parents1dbc1d5 +ef60ef7 commit183d17a

File tree

5 files changed

+206
-101
lines changed

5 files changed

+206
-101
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"annotations": {
3+
"readOnlyHint":true,
4+
"title":"Get secret scanning alert"
5+
},
6+
"description":"Get details of a specific secret scanning alert in a GitHub repository.",
7+
"inputSchema": {
8+
"type":"object",
9+
"required": [
10+
"owner",
11+
"repo",
12+
"alertNumber"
13+
],
14+
"properties": {
15+
"alertNumber": {
16+
"type":"number",
17+
"description":"The number of the alert."
18+
},
19+
"owner": {
20+
"type":"string",
21+
"description":"The owner of the repository."
22+
},
23+
"repo": {
24+
"type":"string",
25+
"description":"The name of the repository."
26+
}
27+
}
28+
},
29+
"name":"get_secret_scanning_alert"
30+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"annotations": {
3+
"readOnlyHint":true,
4+
"title":"List secret scanning alerts"
5+
},
6+
"description":"List secret scanning alerts in a GitHub repository.",
7+
"inputSchema": {
8+
"type":"object",
9+
"required": [
10+
"owner",
11+
"repo"
12+
],
13+
"properties": {
14+
"owner": {
15+
"type":"string",
16+
"description":"The owner of the repository."
17+
},
18+
"repo": {
19+
"type":"string",
20+
"description":"The name of the repository."
21+
},
22+
"resolution": {
23+
"type":"string",
24+
"description":"Filter by resolution",
25+
"enum": [
26+
"false_positive",
27+
"wont_fix",
28+
"revoked",
29+
"pattern_edited",
30+
"pattern_deleted",
31+
"used_in_tests"
32+
]
33+
},
34+
"secret_type": {
35+
"type":"string",
36+
"description":"A comma-separated list of secret types to return. All default secret patterns are returned. To return generic patterns, pass the token name(s) in the parameter."
37+
},
38+
"state": {
39+
"type":"string",
40+
"description":"Filter by state",
41+
"enum": [
42+
"open",
43+
"resolved"
44+
]
45+
}
46+
}
47+
},
48+
"name":"list_secret_scanning_alerts"
49+
}

‎pkg/github/secret_scanning.go‎

Lines changed: 95 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build ignore
2-
31
package github
42

53
import (
@@ -11,49 +9,56 @@ import (
119

1210
ghErrors"github.com/github/github-mcp-server/pkg/errors"
1311
"github.com/github/github-mcp-server/pkg/translations"
12+
"github.com/github/github-mcp-server/pkg/utils"
1413
"github.com/google/go-github/v79/github"
15-
"github.com/mark3labs/mcp-go/mcp"
16-
"github.com/mark3labs/mcp-go/server"
14+
"github.com/google/jsonschema-go/jsonschema"
15+
"github.com/modelcontextprotocol/go-sdk/mcp"
1716
)
1817

19-
funcGetSecretScanningAlert(getClientGetClientFn,t translations.TranslationHelperFunc) (toolmcp.Tool,handler server.ToolHandlerFunc) {
20-
returnmcp.NewTool(
21-
"get_secret_scanning_alert",
22-
mcp.WithDescription(t("TOOL_GET_SECRET_SCANNING_ALERT_DESCRIPTION","Get details of a specific secret scanning alert in a GitHub repository.")),
23-
mcp.WithToolAnnotation(mcp.ToolAnnotation{
18+
funcGetSecretScanningAlert(getClientGetClientFn,t translations.TranslationHelperFunc) (mcp.Tool,mcp.ToolHandlerFor[map[string]any,any]) {
19+
return mcp.Tool{
20+
Name:"get_secret_scanning_alert",
21+
Description:t("TOOL_GET_SECRET_SCANNING_ALERT_DESCRIPTION","Get details of a specific secret scanning alert in a GitHub repository."),
22+
Annotations:&mcp.ToolAnnotations{
2423
Title:t("TOOL_GET_SECRET_SCANNING_ALERT_USER_TITLE","Get secret scanning alert"),
25-
ReadOnlyHint:ToBoolPtr(true),
26-
}),
27-
mcp.WithString("owner",
28-
mcp.Required(),
29-
mcp.Description("The owner of the repository."),
30-
),
31-
mcp.WithString("repo",
32-
mcp.Required(),
33-
mcp.Description("The name of the repository."),
34-
),
35-
mcp.WithNumber("alertNumber",
36-
mcp.Required(),
37-
mcp.Description("The number of the alert."),
38-
),
39-
),
40-
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
41-
owner,err:=RequiredParam[string](request,"owner")
24+
ReadOnlyHint:true,
25+
},
26+
InputSchema:&jsonschema.Schema{
27+
Type:"object",
28+
Properties:map[string]*jsonschema.Schema{
29+
"owner": {
30+
Type:"string",
31+
Description:"The owner of the repository.",
32+
},
33+
"repo": {
34+
Type:"string",
35+
Description:"The name of the repository.",
36+
},
37+
"alertNumber": {
38+
Type:"number",
39+
Description:"The number of the alert.",
40+
},
41+
},
42+
Required: []string{"owner","repo","alertNumber"},
43+
},
44+
},
45+
func(ctx context.Context,_*mcp.CallToolRequest,argsmap[string]any) (*mcp.CallToolResult,any,error) {
46+
owner,err:=RequiredParam[string](args,"owner")
4247
iferr!=nil {
43-
returnmcp.NewToolResultError(err.Error()),nil
48+
returnutils.NewToolResultError(err.Error()),nil,nil
4449
}
45-
repo,err:=RequiredParam[string](request,"repo")
50+
repo,err:=RequiredParam[string](args,"repo")
4651
iferr!=nil {
47-
returnmcp.NewToolResultError(err.Error()),nil
52+
returnutils.NewToolResultError(err.Error()),nil,nil
4853
}
49-
alertNumber,err:=RequiredInt(request,"alertNumber")
54+
alertNumber,err:=RequiredInt(args,"alertNumber")
5055
iferr!=nil {
51-
returnmcp.NewToolResultError(err.Error()),nil
56+
returnutils.NewToolResultError(err.Error()),nil,nil
5257
}
5358

5459
client,err:=getClient(ctx)
5560
iferr!=nil {
56-
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
61+
returnnil,nil,fmt.Errorf("failed to get GitHub client: %w",err)
5762
}
5863

5964
alert,resp,err:=client.SecretScanning.GetAlert(ctx,owner,repo,int64(alertNumber))
@@ -62,104 +67,113 @@ func GetSecretScanningAlert(getClient GetClientFn, t translations.TranslationHel
6267
fmt.Sprintf("failed to get alert with number '%d'",alertNumber),
6368
resp,
6469
err,
65-
),nil
70+
),nil,nil
6671
}
6772
deferfunc() {_=resp.Body.Close() }()
6873

6974
ifresp.StatusCode!=http.StatusOK {
7075
body,err:=io.ReadAll(resp.Body)
7176
iferr!=nil {
72-
returnnil,fmt.Errorf("failed to read response body: %w",err)
77+
returnnil,nil,fmt.Errorf("failed to read response body: %w",err)
7378
}
74-
returnmcp.NewToolResultError(fmt.Sprintf("failed to get alert: %s",string(body))),nil
79+
returnutils.NewToolResultError(fmt.Sprintf("failed to get alert: %s",string(body))),nil,nil
7580
}
7681

7782
r,err:=json.Marshal(alert)
7883
iferr!=nil {
79-
returnnil,fmt.Errorf("failed to marshal alert: %w",err)
84+
returnnil,nil,fmt.Errorf("failed to marshal alert: %w",err)
8085
}
8186

82-
returnmcp.NewToolResultText(string(r)),nil
87+
returnutils.NewToolResultText(string(r)),nil,nil
8388
}
8489
}
8590

86-
funcListSecretScanningAlerts(getClientGetClientFn,t translations.TranslationHelperFunc) (toolmcp.Tool,handler server.ToolHandlerFunc) {
87-
returnmcp.NewTool(
88-
"list_secret_scanning_alerts",
89-
mcp.WithDescription(t("TOOL_LIST_SECRET_SCANNING_ALERTS_DESCRIPTION","List secret scanning alerts in a GitHub repository.")),
90-
mcp.WithToolAnnotation(mcp.ToolAnnotation{
91+
funcListSecretScanningAlerts(getClientGetClientFn,t translations.TranslationHelperFunc) (mcp.Tool,mcp.ToolHandlerFor[map[string]any,any]) {
92+
return mcp.Tool{
93+
Name:"list_secret_scanning_alerts",
94+
Description:t("TOOL_LIST_SECRET_SCANNING_ALERTS_DESCRIPTION","List secret scanning alerts in a GitHub repository."),
95+
Annotations:&mcp.ToolAnnotations{
9196
Title:t("TOOL_LIST_SECRET_SCANNING_ALERTS_USER_TITLE","List secret scanning alerts"),
92-
ReadOnlyHint:ToBoolPtr(true),
93-
}),
94-
mcp.WithString("owner",
95-
mcp.Required(),
96-
mcp.Description("The owner of the repository."),
97-
),
98-
mcp.WithString("repo",
99-
mcp.Required(),
100-
mcp.Description("The name of the repository."),
101-
),
102-
mcp.WithString("state",
103-
mcp.Description("Filter by state"),
104-
mcp.Enum("open","resolved"),
105-
),
106-
mcp.WithString("secret_type",
107-
mcp.Description("A comma-separated list of secret types to return. All default secret patterns are returned. To return generic patterns, pass the token name(s) in the parameter."),
108-
),
109-
mcp.WithString("resolution",
110-
mcp.Description("Filter by resolution"),
111-
mcp.Enum("false_positive","wont_fix","revoked","pattern_edited","pattern_deleted","used_in_tests"),
112-
),
113-
),
114-
func(ctx context.Context,request mcp.CallToolRequest) (*mcp.CallToolResult,error) {
115-
owner,err:=RequiredParam[string](request,"owner")
97+
ReadOnlyHint:true,
98+
},
99+
InputSchema:&jsonschema.Schema{
100+
Type:"object",
101+
Properties:map[string]*jsonschema.Schema{
102+
"owner": {
103+
Type:"string",
104+
Description:"The owner of the repository.",
105+
},
106+
"repo": {
107+
Type:"string",
108+
Description:"The name of the repository.",
109+
},
110+
"state": {
111+
Type:"string",
112+
Description:"Filter by state",
113+
Enum: []any{"open","resolved"},
114+
},
115+
"secret_type": {
116+
Type:"string",
117+
Description:"A comma-separated list of secret types to return. All default secret patterns are returned. To return generic patterns, pass the token name(s) in the parameter.",
118+
},
119+
"resolution": {
120+
Type:"string",
121+
Description:"Filter by resolution",
122+
Enum: []any{"false_positive","wont_fix","revoked","pattern_edited","pattern_deleted","used_in_tests"},
123+
},
124+
},
125+
Required: []string{"owner","repo"},
126+
},
127+
},
128+
func(ctx context.Context,_*mcp.CallToolRequest,argsmap[string]any) (*mcp.CallToolResult,any,error) {
129+
owner,err:=RequiredParam[string](args,"owner")
116130
iferr!=nil {
117-
returnmcp.NewToolResultError(err.Error()),nil
131+
returnutils.NewToolResultError(err.Error()),nil,nil
118132
}
119-
repo,err:=RequiredParam[string](request,"repo")
133+
repo,err:=RequiredParam[string](args,"repo")
120134
iferr!=nil {
121-
returnmcp.NewToolResultError(err.Error()),nil
135+
returnutils.NewToolResultError(err.Error()),nil,nil
122136
}
123-
state,err:=OptionalParam[string](request,"state")
137+
state,err:=OptionalParam[string](args,"state")
124138
iferr!=nil {
125-
returnmcp.NewToolResultError(err.Error()),nil
139+
returnutils.NewToolResultError(err.Error()),nil,nil
126140
}
127-
secretType,err:=OptionalParam[string](request,"secret_type")
141+
secretType,err:=OptionalParam[string](args,"secret_type")
128142
iferr!=nil {
129-
returnmcp.NewToolResultError(err.Error()),nil
143+
returnutils.NewToolResultError(err.Error()),nil,nil
130144
}
131-
resolution,err:=OptionalParam[string](request,"resolution")
145+
resolution,err:=OptionalParam[string](args,"resolution")
132146
iferr!=nil {
133-
returnmcp.NewToolResultError(err.Error()),nil
147+
returnutils.NewToolResultError(err.Error()),nil,nil
134148
}
135149

136150
client,err:=getClient(ctx)
137151
iferr!=nil {
138-
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
152+
returnnil,nil,fmt.Errorf("failed to get GitHub client: %w",err)
139153
}
140154
alerts,resp,err:=client.SecretScanning.ListAlertsForRepo(ctx,owner,repo,&github.SecretScanningAlertListOptions{State:state,SecretType:secretType,Resolution:resolution})
141155
iferr!=nil {
142156
returnghErrors.NewGitHubAPIErrorResponse(ctx,
143157
fmt.Sprintf("failed to list alerts for repository '%s/%s'",owner,repo),
144158
resp,
145159
err,
146-
),nil
160+
),nil,nil
147161
}
148162
deferfunc() {_=resp.Body.Close() }()
149163

150164
ifresp.StatusCode!=http.StatusOK {
151165
body,err:=io.ReadAll(resp.Body)
152166
iferr!=nil {
153-
returnnil,fmt.Errorf("failed to read response body: %w",err)
167+
returnnil,nil,fmt.Errorf("failed to read response body: %w",err)
154168
}
155-
returnmcp.NewToolResultError(fmt.Sprintf("failed to list alerts: %s",string(body))),nil
169+
returnutils.NewToolResultError(fmt.Sprintf("failed to list alerts: %s",string(body))),nil,nil
156170
}
157171

158172
r,err:=json.Marshal(alerts)
159173
iferr!=nil {
160-
returnnil,fmt.Errorf("failed to marshal alerts: %w",err)
174+
returnnil,nil,fmt.Errorf("failed to marshal alerts: %w",err)
161175
}
162176

163-
returnmcp.NewToolResultText(string(r)),nil
177+
returnutils.NewToolResultText(string(r)),nil,nil
164178
}
165179
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp