fix: make API bool parameters in search_repos and list_releases optional (#40) (#44)

Fix #40

Left the `mcp.DefaultBool(false)` for `is_draft` and `is_pre_release` in `list_releases`, because I guess they are default, but it's up to the client whether to set them or not.
11e04b5b8d/operation/repo/release.go (L67-L68)

Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/44
Reviewed-by: Bo-Yi Wu (吳柏毅) <appleboy.tw@gmail.com>
Co-authored-by: Hubert Wawrzyńczyk <hubert@fit-it.pl>
Co-committed-by: Hubert Wawrzyńczyk <hubert@fit-it.pl>
This commit is contained in:
Hubert Wawrzyńczyk
2025-05-27 12:20:47 +00:00
committed by Bo-Yi Wu (吳柏毅)
parent f25cc0de8c
commit a7061f9b64
2 changed files with 24 additions and 8 deletions

View File

@@ -221,8 +221,16 @@ func ListReleasesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool
if !ok { if !ok {
return nil, fmt.Errorf("repo is required") return nil, fmt.Errorf("repo is required")
} }
isDraft, _ := req.GetArguments()["is_draft"].(bool) var pIsDraft *bool
isPreRelease, _ := req.GetArguments()["is_pre_release"].(bool) isDraft, ok := req.GetArguments()["is_draft"].(bool)
if ok {
pIsDraft = ptr.To(isDraft)
}
var pIsPreRelease *bool
isPreRelease, ok := req.GetArguments()["is_pre_release"].(bool)
if ok {
pIsPreRelease = ptr.To(isPreRelease)
}
page, _ := req.GetArguments()["page"].(float64) page, _ := req.GetArguments()["page"].(float64)
pageSize, _ := req.GetArguments()["pageSize"].(float64) pageSize, _ := req.GetArguments()["pageSize"].(float64)
@@ -231,8 +239,8 @@ func ListReleasesFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallTool
Page: int(page), Page: int(page),
PageSize: int(pageSize), PageSize: int(pageSize),
}, },
IsDraft: ptr.To(isDraft), IsDraft: pIsDraft,
IsPreRelease: ptr.To(isPreRelease), IsPreRelease: pIsPreRelease,
}) })
if err != nil { if err != nil {
return nil, fmt.Errorf("list releases error: %v", err) return nil, fmt.Errorf("list releases error: %v", err)

View File

@@ -144,8 +144,16 @@ func SearchReposFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolR
keywordIsTopic, _ := req.GetArguments()["keywordIsTopic"].(bool) keywordIsTopic, _ := req.GetArguments()["keywordIsTopic"].(bool)
keywordInDescription, _ := req.GetArguments()["keywordInDescription"].(bool) keywordInDescription, _ := req.GetArguments()["keywordInDescription"].(bool)
ownerID, _ := req.GetArguments()["ownerID"].(float64) ownerID, _ := req.GetArguments()["ownerID"].(float64)
isPrivate, _ := req.GetArguments()["isPrivate"].(bool) var pIsPrivate *bool
isArchived, _ := req.GetArguments()["isArchived"].(bool) isPrivate, ok := req.GetArguments()["isPrivate"].(bool)
if ok {
pIsPrivate = ptr.To(isPrivate)
}
var pIsArchived *bool
isArchived, ok := req.GetArguments()["isArchived"].(bool)
if ok {
pIsArchived = ptr.To(isArchived)
}
sort, _ := req.GetArguments()["sort"].(string) sort, _ := req.GetArguments()["sort"].(string)
order, _ := req.GetArguments()["order"].(string) order, _ := req.GetArguments()["order"].(string)
page, ok := req.GetArguments()["page"].(float64) page, ok := req.GetArguments()["page"].(float64)
@@ -161,8 +169,8 @@ func SearchReposFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolR
KeywordIsTopic: keywordIsTopic, KeywordIsTopic: keywordIsTopic,
KeywordInDescription: keywordInDescription, KeywordInDescription: keywordInDescription,
OwnerID: int64(ownerID), OwnerID: int64(ownerID),
IsPrivate: ptr.To(isPrivate), IsPrivate: pIsPrivate,
IsArchived: ptr.To(isArchived), IsArchived: pIsArchived,
Sort: sort, Sort: sort,
Order: order, Order: order,
ListOptions: gitea_sdk.ListOptions{ ListOptions: gitea_sdk.ListOptions{