Skip to content

Commit 2032557

Browse files
committed
Update params
1 parent d835623 commit 2032557

File tree

4 files changed

+61
-43
lines changed

4 files changed

+61
-43
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,9 @@ The following sets of tools are available (all are on by default):
762762
- `query`: Filter projects by a search query (matches title and description) (string, optional)
763763

764764
- **update_project_item** - Update project item
765+
- `field_id`: The unique identifier of the project field to be updated. (number, required)
766+
- `field_value`: The new value for the field: For text, number, and date fields, provide the new value directly. For single select and iteration fields, provide the ID of the option or iteration. To clear the field, set this to null. Example: {"id": 123456, "value": "Done"} (object, required)
765767
- `item_id`: The unique identifier of the project item. This is not the issue or pull request ID. (number, required)
766-
- `new_field`: Object consisting of the ID of the project field to update and the new value for the field. To clear the field, set "value" to null. Example: {"id": 123456, "value": "New Value"} (object, required)
767768
- `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)
768769
- `owner_type`: Owner type (string, required)
769770
- `project_number`: The project's number. (number, required)

pkg/github/__toolsnaps__/update_project_item.snap

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
"description": "Update a specific Project item for a user or org",
77
"inputSchema": {
88
"properties": {
9-
"item_id": {
10-
"description": "The unique identifier of the project item. This is not the issue or pull request ID.",
9+
"field_id": {
10+
"description": "The unique identifier of the project field to be updated.",
1111
"type": "number"
1212
},
13-
"new_field": {
14-
"description": "Object consisting of the ID of the project field to update and the new value for the field. To clear the field, set \"value\" to null. Example: {\"id\": 123456, \"value\": \"New Value\"}",
13+
"field_value": {
14+
"description": "The new value for the field: For text, number, and date fields, provide the new value directly. For single select and iteration fields, provide the ID of the option or iteration. To clear the field, set this to null. Example: {\"id\": 123456, \"value\": \"Done\"}",
1515
"properties": {},
1616
"type": "object"
1717
},
18+
"item_id": {
19+
"description": "The unique identifier of the project item. This is not the issue or pull request ID.",
20+
"type": "number"
21+
},
1822
"owner": {
1923
"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.",
2024
"type": "string"
@@ -37,7 +41,8 @@
3741
"owner",
3842
"project_number",
3943
"item_id",
40-
"new_field"
44+
"field_id",
45+
"field_value"
4146
],
4247
"type": "object"
4348
},

pkg/github/projects.go

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,13 @@ func UpdateProjectItem(getClient GetClientFn, t translations.TranslationHelperFu
691691
mcp.Required(),
692692
mcp.Description("The unique identifier of the project item. This is not the issue or pull request ID."),
693693
),
694-
mcp.WithObject("new_field",
694+
mcp.WithNumber("field_id",
695+
mcp.Required(),
696+
mcp.Description("The unique identifier of the project field to be updated."),
697+
),
698+
mcp.WithObject("field_value",
695699
mcp.Required(),
696-
mcp.Description("Object consisting of the ID of the project field to update and the new value for the field. To clear the field, set \"value\" to null. Example: {\"id\": 123456, \"value\": \"New Value\"}"),
700+
mcp.Description("The new value for the field: For text, number, and date fields, provide the new value directly. For single select and iteration fields, provide the ID of the option or iteration. To clear the field, set this to null. Example: {\"id\": 123456, \"value\": \"Done\"}"),
697701
),
698702
), func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
699703
owner, err := RequiredParam[string](req, "owner")
@@ -713,21 +717,28 @@ func UpdateProjectItem(getClient GetClientFn, t translations.TranslationHelperFu
713717
return mcp.NewToolResultError(err.Error()), nil
714718
}
715719

716-
rawNewField, exists := req.GetArguments()["new_field"]
720+
fieldID, err := RequiredInt(req, "field_id")
721+
if err != nil {
722+
return mcp.NewToolResultError(err.Error()), nil
723+
}
724+
725+
rawFieldValue, exists := req.GetArguments()["field_value"]
717726
if !exists {
718-
return mcp.NewToolResultError("missing required parameter: new_field"), nil
727+
return mcp.NewToolResultError("missing required parameter: field_value"), nil
719728
}
720729

721-
newField, ok := rawNewField.(map[string]any)
722-
if !ok || newField == nil {
723-
return mcp.NewToolResultError("new_field must be an object"), nil
730+
fieldValue, ok := rawFieldValue.(map[string]any)
731+
if !ok || fieldValue == nil {
732+
return mcp.NewToolResultError("field_value must be an object"), nil
724733
}
725734

726-
updatePayload, err := buildUpdateProjectItem(newField)
727-
if err != nil {
728-
return mcp.NewToolResultError(err.Error()), nil
735+
valueField, ok := fieldValue["value"]
736+
if !ok {
737+
return nil, fmt.Errorf("field_value is required")
729738
}
730739

740+
updatePayload := &updateProjectItem{ID: fieldID, Value: valueField}
741+
731742
client, err := getClient(ctx)
732743
if err != nil {
733744
return mcp.NewToolResultError(err.Error()), nil
@@ -913,29 +924,29 @@ type listProjectsOptions struct {
913924
Query string `url:"q,omitempty"`
914925
}
915926

916-
func buildUpdateProjectItem(input map[string]any) (*updateProjectItem, error) {
917-
if input == nil {
918-
return nil, fmt.Errorf("new_field must be an object")
919-
}
920-
921-
idField, ok := input["id"]
922-
if !ok {
923-
return nil, fmt.Errorf("new_field.id is required")
924-
}
925-
926-
idFieldAsFloat64, ok := idField.(float64) // JSON numbers are float64
927-
if !ok {
928-
return nil, fmt.Errorf("new_field.id must be a number")
929-
}
930-
931-
valueField, ok := input["value"]
932-
if !ok {
933-
return nil, fmt.Errorf("new_field.value is required")
934-
}
935-
payload := &updateProjectItem{ID: int(idFieldAsFloat64), Value: valueField}
936-
937-
return payload, nil
938-
}
927+
// func buildUpdateProjectItem(input map[string]any) (*updateProjectItem, error) {
928+
// if input == nil {
929+
// return nil, fmt.Errorf("new_field must be an object")
930+
// }
931+
932+
// idField, ok := input["id"]
933+
// if !ok {
934+
// return nil, fmt.Errorf("new_field.id is required")
935+
// }
936+
937+
// idFieldAsFloat64, ok := idField.(float64) // JSON numbers are float64
938+
// if !ok {
939+
// return nil, fmt.Errorf("new_field.id must be a number")
940+
// }
941+
942+
// valueField, ok := input["value"]
943+
// if !ok {
944+
// return nil, fmt.Errorf("new_field.value is required")
945+
// }
946+
// payload := &updateProjectItem{ID: int(idFieldAsFloat64), Value: valueField}
947+
948+
// return payload, nil
949+
// }
939950

940951
// addOptions adds the parameters in opts as URL query parameters to s. opts
941952
// must be a struct whose fields may contain "url" tags.

pkg/github/projects_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,9 @@ func Test_UpdateProjectItem(t *testing.T) {
11751175
assert.Contains(t, tool.InputSchema.Properties, "owner")
11761176
assert.Contains(t, tool.InputSchema.Properties, "project_number")
11771177
assert.Contains(t, tool.InputSchema.Properties, "item_id")
1178-
assert.Contains(t, tool.InputSchema.Properties, "new_field")
1179-
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner_type", "owner", "project_number", "item_id", "new_field"})
1178+
assert.Contains(t, tool.InputSchema.Properties, "field_id")
1179+
assert.Contains(t, tool.InputSchema.Properties, "field_value")
1180+
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner_type", "owner", "project_number", "item_id", "field_id", "field_value"})
11801181

11811182
orgUpdatedItem := map[string]any{
11821183
"id": 801,
@@ -1223,8 +1224,8 @@ func Test_UpdateProjectItem(t *testing.T) {
12231224
"owner_type": "org",
12241225
"project_number": float64(1001),
12251226
"item_id": float64(5555),
1226-
"new_field": map[string]any{
1227-
"id": float64(101),
1227+
"field_id": float64(101),
1228+
"field_value": map[string]any{
12281229
"value": "Done",
12291230
},
12301231
},

0 commit comments

Comments
 (0)