Skip to content

Commit 2d98742

Browse files
committed
feat: add list issue types tool
1 parent 41d1269 commit 2d98742

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

pkg/github/issue_types.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package github
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
"net/http"
9+
10+
"github.com/github/github-mcp-server/pkg/translations"
11+
"github.com/mark3labs/mcp-go/mcp"
12+
"github.com/mark3labs/mcp-go/server"
13+
)
14+
15+
func ListIssueTypes(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
16+
return mcp.NewTool("list_issue_types",
17+
mcp.WithDescription(t("TOOL_LIST_ISSUE_TYPES_DESCRIPTION", "")),
18+
mcp.WithToolAnnotation(mcp.ToolAnnotation{
19+
Title: t("TOOL_LIST_ISSUE_TYPES_USER_TYPE", "List Issue Types"),
20+
ReadOnlyHint: ToBoolPtr(true),
21+
}),
22+
mcp.WithString("org_name",
23+
mcp.Required(),
24+
mcp.Description("The organization name to list issue types for"),
25+
),
26+
),
27+
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
28+
orgName, err := RequiredParam[string](request, "org_name")
29+
if err != nil {
30+
return mcp.NewToolResultError(err.Error()), nil
31+
}
32+
client, err := getClient(ctx)
33+
if err != nil {
34+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
35+
}
36+
issueTypes, resp, err := client.Organizations.ListIssueTypes(ctx, orgName)
37+
if err != nil {
38+
return nil, fmt.Errorf("failed to get issue types: %w", err)
39+
}
40+
defer func() { _ = resp.Body.Close() }()
41+
42+
if resp.StatusCode != http.StatusOK {
43+
body, err := io.ReadAll(resp.Body)
44+
if err != nil {
45+
return nil, fmt.Errorf("failed to read response body: %w", err)
46+
}
47+
return mcp.NewToolResultError(fmt.Sprintf("failed to list issue types: %s", string(body))), nil
48+
}
49+
50+
r, err := json.Marshal(issueTypes)
51+
if err != nil {
52+
return nil, fmt.Errorf("failed to marshal issue: %w", err)
53+
}
54+
55+
return mcp.NewToolResultText(string(r)), nil
56+
}
57+
}
58+
59+
func CreateIssueType() {}
60+
61+
func UpdateIssueType() {}
62+
63+
func DeleteIssueType() {}

pkg/github/tools.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ func DefaultToolsetGroup(readOnly bool, getClient GetClientFn, getGQLClient GetG
119119
toolsets.NewServerTool(GetMe(getClient, t)),
120120
)
121121

122+
issueTypes := toolsets.NewToolset("issue_types", "Issue types related tools, such as GitHub Copilot Issue Types").
123+
AddReadTools(
124+
toolsets.NewServerTool(ListIssueTypes(getClient, t)),
125+
)
126+
122127
// Add toolsets to the group
123128
tsg.AddToolset(contextTools)
124129
tsg.AddToolset(repos)
@@ -129,6 +134,7 @@ func DefaultToolsetGroup(readOnly bool, getClient GetClientFn, getGQLClient GetG
129134
tsg.AddToolset(secretProtection)
130135
tsg.AddToolset(notifications)
131136
tsg.AddToolset(experiments)
137+
tsg.AddToolset(issueTypes)
132138

133139
return tsg
134140
}

0 commit comments

Comments
 (0)