Skip to content

Commit 50f1250

Browse files
committed
update types
1 parent 584d2e0 commit 50f1250

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ Options are:
840840
- **list_project_items** - List project items
841841
- `after`: Forward pagination cursor from previous pageInfo.nextCursor. (string, optional)
842842
- `before`: Backward pagination cursor from previous pageInfo.prevCursor (rare). (string, optional)
843-
- `fields`: Field IDs to include (e.g. ["102589", "985201"]). CRITICAL: Always provide to get field values. Without this, only titles returned. Get IDs from list_project_fields first. (string[], optional)
843+
- `fields`: Field IDs to include (e.g. ["102589", "985201"]). CRITICAL: Always provide to get field values. Without this, only titles returned. (string[], optional)
844844
- `owner`: If owner_type == user it is the handle for the GitHub user account. If owner_type == org it is the name of the organization. The name is not case sensitive. (string, required)
845845
- `owner_type`: Owner type (string, required)
846846
- `per_page`: Results per page (max 50) (number, optional)

pkg/github/__toolsnaps__/list_project_items.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "string"
1616
},
1717
"fields": {
18-
"description": "Field IDs to include (e.g. [\"102589\", \"985201\"]). CRITICAL: Always provide to get field values. Without this, only titles returned. Get IDs from list_project_fields first.",
18+
"description": "Field IDs to include (e.g. [\"102589\", \"985201\"]). CRITICAL: Always provide to get field values. Without this, only titles returned.",
1919
"items": {
2020
"type": "string"
2121
},

pkg/github/projects.go

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,30 @@ func ListProjectFields(getClient GetClientFn, t translations.TranslationHelperFu
256256
return mcp.NewToolResultError(err.Error()), nil
257257
}
258258

259-
var resp *github.Response
260-
var projectFields []*github.ProjectV2Field
261-
262259
opts := &github.ListProjectsOptions{
263260
ListProjectsPaginationOptions: pagination,
264261
}
265262

263+
var url string
266264
if ownerType == "org" {
267-
projectFields, resp, err = client.Projects.ListOrganizationProjectFields(ctx, owner, projectNumber, opts)
265+
url = fmt.Sprintf("orgs/%s/projectsV2/%d/fields", owner, projectNumber)
268266
} else {
269-
projectFields, resp, err = client.Projects.ListUserProjectFields(ctx, owner, projectNumber, opts)
267+
url = fmt.Sprintf("users/%s/projectsV2/%d/fields", owner, projectNumber)
270268
}
271269

270+
url, err = addOptions(url, opts)
271+
if err != nil {
272+
return mcp.NewToolResultError(err.Error()), nil
273+
}
274+
275+
httpRequest, err := client.NewRequest("GET", url, nil)
276+
if err != nil {
277+
return nil, fmt.Errorf("failed to create request: %w", err)
278+
}
279+
280+
var projectFields []projectV2Field
281+
resp, err := client.Do(ctx, httpRequest, &projectFields)
282+
272283
if err != nil {
273284
return ghErrors.NewGitHubAPIErrorResponse(ctx,
274285
"failed to list project fields",
@@ -401,7 +412,7 @@ func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFun
401412
mcp.Description("Backward pagination cursor from previous pageInfo.prevCursor (rare)."),
402413
),
403414
mcp.WithArray("fields",
404-
mcp.Description("Field IDs to include (e.g. [\"102589\", \"985201\"]). CRITICAL: Always provide to get field values. Without this, only titles returned. Get IDs from list_project_fields first."),
415+
mcp.Description("Field IDs to include (e.g. [\"102589\", \"985201\"]). CRITICAL: Always provide to get field values. Without this, only titles returned."),
405416
mcp.WithStringItems(),
406417
),
407418
), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
@@ -441,7 +452,7 @@ func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFun
441452
}
442453

443454
var resp *github.Response
444-
var projectItems []*github.ProjectV2Item
455+
var projectItems []projectV2Item
445456
var queryPtr *string
446457

447458
if queryStr != "" {
@@ -456,12 +467,25 @@ func ListProjectItems(getClient GetClientFn, t translations.TranslationHelperFun
456467
},
457468
}
458469

470+
var url string
459471
if ownerType == "org" {
460-
projectItems, resp, err = client.Projects.ListOrganizationProjectItems(ctx, owner, projectNumber, opts)
472+
url = fmt.Sprintf("orgs/%s/projectsV2/%d/items", owner, projectNumber)
461473
} else {
462-
projectItems, resp, err = client.Projects.ListUserProjectItems(ctx, owner, projectNumber, opts)
474+
url = fmt.Sprintf("users/%s/projectsV2/%d/items", owner, projectNumber)
475+
}
476+
477+
url, err = addOptions(url, opts)
478+
if err != nil {
479+
return mcp.NewToolResultError(err.Error()), nil
463480
}
464481

482+
httpRequest, err := client.NewRequest("GET", url, nil)
483+
if err != nil {
484+
return nil, fmt.Errorf("failed to create request: %w", err)
485+
}
486+
487+
resp, err = client.Do(ctx, httpRequest, &projectItems)
488+
465489
if err != nil {
466490
return ghErrors.NewGitHubAPIErrorResponse(ctx,
467491
ProjectListFailedError,
@@ -920,6 +944,18 @@ type pageInfo struct {
920944
PrevCursor string `json:"prevCursor,omitempty"`
921945
}
922946

947+
type projectV2Field struct {
948+
ID *int64 `json:"id,omitempty"`
949+
NodeID *string `json:"node_id,omitempty"`
950+
Name *string `json:"name,omitempty"`
951+
DataType *string `json:"data_type,omitempty"`
952+
ProjectURL *string `json:"project_url,omitempty"`
953+
Options []any `json:"options,omitempty"`
954+
Configuration any `json:"configuration,omitempty"`
955+
CreatedAt *github.Timestamp `json:"created_at,omitempty"`
956+
UpdatedAt *github.Timestamp `json:"updated_at,omitempty"`
957+
}
958+
923959
func toNewProjectType(projType string) string {
924960
switch strings.ToLower(projType) {
925961
case "issue":
@@ -983,11 +1019,20 @@ func extractPaginationOptions(request mcp.CallToolRequest) (github.ListProjectsP
9831019
return github.ListProjectsPaginationOptions{}, err
9841020
}
9851021

986-
return github.ListProjectsPaginationOptions{
1022+
opts := github.ListProjectsPaginationOptions{
9871023
PerPage: &perPage,
988-
After: &after,
989-
Before: &before,
990-
}, nil
1024+
}
1025+
1026+
// Only set After/Before if they have non-empty values
1027+
if after != "" {
1028+
opts.After = &after
1029+
}
1030+
1031+
if before != "" {
1032+
opts.Before = &before
1033+
}
1034+
1035+
return opts, nil
9911036
}
9921037

9931038
// addOptions adds the parameters in opts as URL query parameters to s. opts

0 commit comments

Comments
 (0)