MCP clients (e.g. Claude Code) may serialize number parameters as JSON strings instead of JSON numbers. The Go type assertion .(float64) silently returns 0 for string values, causing "issue does not exist [index: 0]" errors. Add to.Float64() helper that handles float64, int, int64, and string types via strconv.ParseFloat. Replace all 62 bare .(float64) assertions across 9 operation files with to.Float64() calls. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"codeberg.org/goern/forgejo-mcp/v2/operation/params"
|
|
"codeberg.org/goern/forgejo-mcp/v2/pkg/forgejo"
|
|
"codeberg.org/goern/forgejo-mcp/v2/pkg/log"
|
|
"codeberg.org/goern/forgejo-mcp/v2/pkg/to"
|
|
|
|
forgejo_sdk "codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2"
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|
)
|
|
|
|
const (
|
|
ListRepoCommitsToolName = "list_repo_commits"
|
|
)
|
|
|
|
var (
|
|
ListRepoCommitsTool = mcp.NewTool(
|
|
ListRepoCommitsToolName,
|
|
mcp.WithDescription("List repo commits"),
|
|
mcp.WithString("owner", mcp.Required(), mcp.Description(params.Owner)),
|
|
mcp.WithString("repo", mcp.Required(), mcp.Description(params.Repo)),
|
|
mcp.WithString("path", mcp.Description("File/dir path")),
|
|
mcp.WithString("sha", mcp.Description("SHA/branch to start from")),
|
|
mcp.WithNumber("page", mcp.Required(), mcp.Description(params.Page), mcp.DefaultNumber(1), mcp.Min(1)),
|
|
mcp.WithNumber("limit", mcp.Required(), mcp.Description(params.Limit), mcp.DefaultNumber(100), mcp.Min(1)),
|
|
)
|
|
)
|
|
|
|
func ListRepoCommitsFn(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
log.Debugf("Called ListRepoCommitsFn")
|
|
owner, _ := req.GetArguments()["owner"].(string)
|
|
repo, _ := req.GetArguments()["repo"].(string)
|
|
path, ok := req.GetArguments()["path"].(string)
|
|
pathStr := ""
|
|
if ok && path != "" {
|
|
pathStr = path
|
|
}
|
|
sha, ok := req.GetArguments()["sha"].(string)
|
|
shaStr := ""
|
|
if ok && sha != "" {
|
|
shaStr = sha
|
|
}
|
|
page, _ := to.Float64(req.GetArguments()["page"])
|
|
if !ok {
|
|
page = 1
|
|
}
|
|
limit, _ := to.Float64(req.GetArguments()["limit"])
|
|
if !ok {
|
|
limit = 100
|
|
}
|
|
opt := forgejo_sdk.ListCommitOptions{
|
|
Path: pathStr,
|
|
SHA: shaStr,
|
|
ListOptions: forgejo_sdk.ListOptions{
|
|
Page: int(page),
|
|
PageSize: int(limit),
|
|
},
|
|
}
|
|
commits, _, err := forgejo.Client().ListRepoCommits(owner, repo, opt)
|
|
if err != nil {
|
|
return to.ErrorResult(fmt.Errorf("list repo commits error: %v", err))
|
|
}
|
|
return to.TextResult(commits)
|
|
}
|