Skip to content

Commit 6d01897

Browse files
authored
Remove update_project_item tool (#1167)
* Remove update_project_item tool * Lint
1 parent 62f6876 commit 6d01897

File tree

5 files changed

+1
-376
lines changed

5 files changed

+1
-376
lines changed

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,6 @@ The following sets of tools are available (all are on by default):
707707
- `per_page`: Number of results per page (max 100, default: 30) (number, optional)
708708
- `query`: Filter projects by a search query (matches title and description) (string, optional)
709709

710-
- **update_project_item** - Update project item
711-
- `fields`: A list of field updates to apply. (array, required)
712-
- `item_id`: The numeric ID of the project item to update (not the issue or pull request ID). (number, required)
713-
- `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)
714-
- `owner_type`: Owner type (string, required)
715-
- `project_number`: The project's number. (number, required)
716-
717710
</details>
718711

719712
<details>

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/fsnotify/fsnotify v1.8.0 // indirect
3232
github.com/go-viper/mapstructure/v2 v2.4.0
3333
github.com/google/go-github/v71 v71.0.0 // indirect
34-
github.com/google/go-querystring v1.1.0 // indirect
34+
github.com/google/go-querystring v1.1.0
3535
github.com/google/uuid v1.6.0 // indirect
3636
github.com/gorilla/mux v1.8.0 // indirect
3737
github.com/inconshreveable/mousetrap v1.1.0 // indirect

pkg/github/projects.go

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -621,138 +621,6 @@ func DeleteProjectItem(getClient GetClientFn, t translations.TranslationHelperFu
621621
}
622622
}
623623

624-
func UpdateProjectItem(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
625-
return mcp.NewTool("update_project_item",
626-
mcp.WithDescription(t("TOOL_UPDATE_PROJECT_ITEM_DESCRIPTION", "Update a specific Project item for a user or org")),
627-
mcp.WithToolAnnotation(mcp.ToolAnnotation{Title: t("TOOL_UPDATE_PROJECT_ITEM_USER_TITLE", "Update project item"), ReadOnlyHint: ToBoolPtr(false)}),
628-
mcp.WithString("owner_type", mcp.Required(), mcp.Description("Owner type"), mcp.Enum("user", "org")),
629-
mcp.WithString("owner", mcp.Required(), mcp.Description("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.")),
630-
mcp.WithNumber("project_number", mcp.Required(), mcp.Description("The project's number.")),
631-
mcp.WithNumber("item_id", mcp.Required(), mcp.Description("The numeric ID of the project item to update (not the issue or pull request ID).")),
632-
mcp.WithArray("fields", mcp.Required(), mcp.Description("A list of field updates to apply.")),
633-
), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
634-
owner, err := RequiredParam[string](req, "owner")
635-
if err != nil {
636-
return mcp.NewToolResultError(err.Error()), nil
637-
}
638-
ownerType, err := RequiredParam[string](req, "owner_type")
639-
if err != nil {
640-
return mcp.NewToolResultError(err.Error()), nil
641-
}
642-
projectNumber, err := RequiredInt(req, "project_number")
643-
if err != nil {
644-
return mcp.NewToolResultError(err.Error()), nil
645-
}
646-
itemID, err := RequiredInt(req, "item_id")
647-
if err != nil {
648-
return mcp.NewToolResultError(err.Error()), nil
649-
}
650-
client, err := getClient(ctx)
651-
if err != nil {
652-
return mcp.NewToolResultError(err.Error()), nil
653-
}
654-
fieldsParam, ok := req.GetArguments()["fields"]
655-
if !ok {
656-
return mcp.NewToolResultError("missing required parameter: fields"), nil
657-
}
658-
659-
rawFields, ok := fieldsParam.([]any)
660-
if !ok {
661-
return mcp.NewToolResultError("parameter fields must be an array of objects"), nil
662-
}
663-
if len(rawFields) == 0 {
664-
return mcp.NewToolResultError("fields must contain at least one field update"), nil
665-
}
666-
667-
var projectsURL string
668-
if ownerType == "org" {
669-
projectsURL = fmt.Sprintf("orgs/%s/projectsV2/%d/items/%d", owner, projectNumber, itemID)
670-
} else {
671-
projectsURL = fmt.Sprintf("users/%s/projectsV2/%d/items/%d", owner, projectNumber, itemID)
672-
}
673-
674-
updateFields := make([]*newProjectV2Field, 0, len(rawFields))
675-
for idx, rawField := range rawFields {
676-
fieldMap, ok := rawField.(map[string]any)
677-
if !ok {
678-
return mcp.NewToolResultError(fmt.Sprintf("fields[%d] must be an object", idx)), nil
679-
}
680-
681-
rawID, ok := fieldMap["id"]
682-
if !ok {
683-
return mcp.NewToolResultError(fmt.Sprintf("fields[%d] is missing 'id'", idx)), nil
684-
}
685-
686-
var fieldID int64
687-
switch v := rawID.(type) {
688-
case float64:
689-
fieldID = int64(v)
690-
case int64:
691-
fieldID = v
692-
case json.Number:
693-
n, convErr := v.Int64()
694-
if convErr != nil {
695-
return mcp.NewToolResultError(fmt.Sprintf("fields[%d].id must be a numeric value", idx)), nil
696-
}
697-
fieldID = n
698-
default:
699-
return mcp.NewToolResultError(fmt.Sprintf("fields[%d].id must be a numeric value", idx)), nil
700-
}
701-
702-
value, ok := fieldMap["value"]
703-
if !ok {
704-
return mcp.NewToolResultError(fmt.Sprintf("fields[%d] is missing 'value'", idx)), nil
705-
}
706-
707-
updateFields = append(updateFields, &newProjectV2Field{
708-
ID: github.Ptr(fieldID),
709-
Value: value,
710-
})
711-
}
712-
713-
updateProjectItemOptions := &updateProjectItemOptions{Fields: updateFields}
714-
715-
httpRequest, err := client.NewRequest("PATCH", projectsURL, updateProjectItemOptions)
716-
if err != nil {
717-
return nil, fmt.Errorf("failed to create request: %w", err)
718-
}
719-
720-
updatedItem := projectV2Item{}
721-
resp, err := client.Do(ctx, httpRequest, &updatedItem)
722-
if err != nil {
723-
return ghErrors.NewGitHubAPIErrorResponse(ctx,
724-
"failed to update a project item",
725-
resp,
726-
err,
727-
), nil
728-
}
729-
defer func() { _ = resp.Body.Close() }()
730-
731-
if resp.StatusCode != http.StatusOK {
732-
body, err := io.ReadAll(resp.Body)
733-
if err != nil {
734-
return nil, fmt.Errorf("failed to read response body: %w", err)
735-
}
736-
return mcp.NewToolResultError(fmt.Sprintf("failed to update a project item: %s", string(body))), nil
737-
}
738-
r, err := json.Marshal(convertToMinimalProjectItem(&updatedItem))
739-
if err != nil {
740-
return nil, fmt.Errorf("failed to marshal response: %w", err)
741-
}
742-
743-
return mcp.NewToolResultText(string(r)), nil
744-
}
745-
}
746-
747-
type updateProjectItemOptions struct {
748-
Fields []*newProjectV2Field `json:"fields,omitempty"`
749-
}
750-
751-
type newProjectV2Field struct {
752-
ID *int64 `json:"id,omitempty"`
753-
Value any `json:"value,omitempty"`
754-
}
755-
756624
type newProjectItem struct {
757625
ID int64 `json:"id,omitempty"` // Issue or Pull Request ID to add to the project.
758626
Type string `json:"type,omitempty"`

0 commit comments

Comments
 (0)