|
| 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() {} |
0 commit comments