in pkg/github/issues.go [434:553]
func ListIssues(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
return mcp.NewTool("list_issues",
mcp.WithDescription(t("TOOL_LIST_ISSUES_DESCRIPTION", "List issues in a GitHub repository.")),
mcp.WithToolAnnotation(mcp.ToolAnnotation{
Title: t("TOOL_LIST_ISSUES_USER_TITLE", "List issues"),
ReadOnlyHint: true,
}),
mcp.WithString("owner",
mcp.Required(),
mcp.Description("Repository owner"),
),
mcp.WithString("repo",
mcp.Required(),
mcp.Description("Repository name"),
),
mcp.WithString("state",
mcp.Description("Filter by state"),
mcp.Enum("open", "closed", "all"),
),
mcp.WithArray("labels",
mcp.Description("Filter by labels"),
mcp.Items(
map[string]interface{}{
"type": "string",
},
),
),
mcp.WithString("sort",
mcp.Description("Sort order"),
mcp.Enum("created", "updated", "comments"),
),
mcp.WithString("direction",
mcp.Description("Sort direction"),
mcp.Enum("asc", "desc"),
),
mcp.WithString("since",
mcp.Description("Filter by date (ISO 8601 timestamp)"),
),
WithPagination(),
),
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
}
opts := &github.IssueListByRepoOptions{}
// Set optional parameters if provided
opts.State, err = OptionalParam[string](request, "state")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
// Get labels
opts.Labels, err = OptionalStringArrayParam(request, "labels")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
opts.Sort, err = OptionalParam[string](request, "sort")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
opts.Direction, err = OptionalParam[string](request, "direction")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
since, err := OptionalParam[string](request, "since")
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
if since != "" {
timestamp, err := parseISOTimestamp(since)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("failed to list issues: %s", err.Error())), nil
}
opts.Since = timestamp
}
if page, ok := request.Params.Arguments["page"].(float64); ok {
opts.Page = int(page)
}
if perPage, ok := request.Params.Arguments["perPage"].(float64); ok {
opts.PerPage = int(perPage)
}
client, err := getClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
}
issues, resp, err := client.Issues.ListByRepo(ctx, owner, repo, opts)
if err != nil {
return nil, fmt.Errorf("failed to list issues: %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 issues: %s", string(body))), nil
}
r, err := json.Marshal(issues)
if err != nil {
return nil, fmt.Errorf("failed to marshal issues: %w", err)
}
return mcp.NewToolResultText(string(r)), nil
}
}