From dac50b25d6dcc2064eb9ab042b5909bb0f9aecde Mon Sep 17 00:00:00 2001 From: Sam Morrow Date: Tue, 8 Apr 2025 00:38:10 +0200 Subject: [PATCH] chore: export remaining search + helpers --- pkg/github/code_scanning.go | 8 +++--- pkg/github/issues.go | 52 ++++++++++++++++++------------------- pkg/github/pullrequests.go | 48 +++++++++++++++++----------------- pkg/github/repositories.go | 20 +++++++------- pkg/github/search.go | 20 +++++++------- pkg/github/server.go | 50 +++++++++++++++++------------------ pkg/github/server_test.go | 32 +++++++++++------------ 7 files changed, 115 insertions(+), 115 deletions(-) diff --git a/pkg/github/code_scanning.go b/pkg/github/code_scanning.go index 1b9cd8760..dc48bdb3e 100644 --- a/pkg/github/code_scanning.go +++ b/pkg/github/code_scanning.go @@ -38,7 +38,7 @@ func GetCodeScanningAlert(client *github.Client, t translations.TranslationHelpe if err != nil { return mcp.NewToolResultError(err.Error()), nil } - alertNumber, err := requiredInt(request, "alertNumber") + alertNumber, err := RequiredInt(request, "alertNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -97,15 +97,15 @@ func ListCodeScanningAlerts(client *github.Client, t translations.TranslationHel if err != nil { return mcp.NewToolResultError(err.Error()), nil } - ref, err := optionalParam[string](request, "ref") + ref, err := OptionalParam[string](request, "ref") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - state, err := optionalParam[string](request, "state") + state, err := OptionalParam[string](request, "state") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - severity, err := optionalParam[string](request, "severity") + severity, err := OptionalParam[string](request, "severity") if err != nil { return mcp.NewToolResultError(err.Error()), nil } diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 5836deddb..c983fa269 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -40,7 +40,7 @@ func GetIssue(client *github.Client, t translations.TranslationHelperFunc) (tool if err != nil { return mcp.NewToolResultError(err.Error()), nil } - issueNumber, err := requiredInt(request, "issue_number") + issueNumber, err := RequiredInt(request, "issue_number") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -98,7 +98,7 @@ func AddIssueComment(client *github.Client, t translations.TranslationHelperFunc if err != nil { return mcp.NewToolResultError(err.Error()), nil } - issueNumber, err := requiredInt(request, "issue_number") + issueNumber, err := RequiredInt(request, "issue_number") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -162,22 +162,22 @@ func SearchIssues(client *github.Client, t translations.TranslationHelperFunc) ( mcp.Description("Sort order ('asc' or 'desc')"), mcp.Enum("asc", "desc"), ), - withPagination(), + WithPagination(), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { query, err := requiredParam[string](request, "q") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - sort, err := optionalParam[string](request, "sort") + sort, err := OptionalParam[string](request, "sort") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - order, err := optionalParam[string](request, "order") + order, err := OptionalParam[string](request, "order") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pagination, err := optionalPaginationParams(request) + pagination, err := OptionalPaginationParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -268,25 +268,25 @@ func CreateIssue(client *github.Client, t translations.TranslationHelperFunc) (t } // Optional parameters - body, err := optionalParam[string](request, "body") + body, err := OptionalParam[string](request, "body") if err != nil { return mcp.NewToolResultError(err.Error()), nil } // Get assignees - assignees, err := optionalStringArrayParam(request, "assignees") + assignees, err := OptionalStringArrayParam(request, "assignees") if err != nil { return mcp.NewToolResultError(err.Error()), nil } // Get labels - labels, err := optionalStringArrayParam(request, "labels") + labels, err := OptionalStringArrayParam(request, "labels") if err != nil { return mcp.NewToolResultError(err.Error()), nil } // Get optional milestone - milestone, err := optionalIntParam(request, "milestone") + milestone, err := OptionalIntParam(request, "milestone") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -363,7 +363,7 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to mcp.WithString("since", mcp.Description("Filter by date (ISO 8601 timestamp)"), ), - withPagination(), + WithPagination(), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { owner, err := requiredParam[string](request, "owner") @@ -378,28 +378,28 @@ func ListIssues(client *github.Client, t translations.TranslationHelperFunc) (to opts := &github.IssueListByRepoOptions{} // Set optional parameters if provided - opts.State, err = optionalParam[string](request, "state") + opts.State, err = OptionalParam[string](request, "state") if err != nil { return mcp.NewToolResultError(err.Error()), nil } // Get labels - opts.Labels, err = optionalStringArrayParam(request, "labels") + opts.Labels, err = OptionalStringArrayParam(request, "labels") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - opts.Sort, err = optionalParam[string](request, "sort") + opts.Sort, err = OptionalParam[string](request, "sort") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - opts.Direction, err = optionalParam[string](request, "direction") + opts.Direction, err = OptionalParam[string](request, "direction") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - since, err := optionalParam[string](request, "since") + since, err := OptionalParam[string](request, "since") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -497,7 +497,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t if err != nil { return mcp.NewToolResultError(err.Error()), nil } - issueNumber, err := requiredInt(request, "issue_number") + issueNumber, err := RequiredInt(request, "issue_number") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -506,7 +506,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t issueRequest := &github.IssueRequest{} // Set optional parameters if provided - title, err := optionalParam[string](request, "title") + title, err := OptionalParam[string](request, "title") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -514,7 +514,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t issueRequest.Title = github.Ptr(title) } - body, err := optionalParam[string](request, "body") + body, err := OptionalParam[string](request, "body") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -522,7 +522,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t issueRequest.Body = github.Ptr(body) } - state, err := optionalParam[string](request, "state") + state, err := OptionalParam[string](request, "state") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -531,7 +531,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t } // Get labels - labels, err := optionalStringArrayParam(request, "labels") + labels, err := OptionalStringArrayParam(request, "labels") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -540,7 +540,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t } // Get assignees - assignees, err := optionalStringArrayParam(request, "assignees") + assignees, err := OptionalStringArrayParam(request, "assignees") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -548,7 +548,7 @@ func UpdateIssue(client *github.Client, t translations.TranslationHelperFunc) (t issueRequest.Assignees = &assignees } - milestone, err := optionalIntParam(request, "milestone") + milestone, err := OptionalIntParam(request, "milestone") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -612,15 +612,15 @@ func GetIssueComments(client *github.Client, t translations.TranslationHelperFun if err != nil { return mcp.NewToolResultError(err.Error()), nil } - issueNumber, err := requiredInt(request, "issue_number") + issueNumber, err := RequiredInt(request, "issue_number") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - page, err := optionalIntParamWithDefault(request, "page", 1) + page, err := OptionalIntParamWithDefault(request, "page", 1) if err != nil { return mcp.NewToolResultError(err.Error()), nil } - perPage, err := optionalIntParamWithDefault(request, "per_page", 30) + perPage, err := OptionalIntParamWithDefault(request, "per_page", 30) if err != nil { return mcp.NewToolResultError(err.Error()), nil } diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index a5cd86b45..65b87154f 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -39,7 +39,7 @@ func GetPullRequest(client *github.Client, t translations.TranslationHelperFunc) if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -94,7 +94,7 @@ func ListPullRequests(client *github.Client, t translations.TranslationHelperFun mcp.WithString("direction", mcp.Description("Sort direction ('asc', 'desc')"), ), - withPagination(), + WithPagination(), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { owner, err := requiredParam[string](request, "owner") @@ -105,27 +105,27 @@ func ListPullRequests(client *github.Client, t translations.TranslationHelperFun if err != nil { return mcp.NewToolResultError(err.Error()), nil } - state, err := optionalParam[string](request, "state") + state, err := OptionalParam[string](request, "state") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - head, err := optionalParam[string](request, "head") + head, err := OptionalParam[string](request, "head") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - base, err := optionalParam[string](request, "base") + base, err := OptionalParam[string](request, "base") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - sort, err := optionalParam[string](request, "sort") + sort, err := OptionalParam[string](request, "sort") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - direction, err := optionalParam[string](request, "direction") + direction, err := OptionalParam[string](request, "direction") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pagination, err := optionalPaginationParams(request) + pagination, err := OptionalPaginationParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -200,19 +200,19 @@ func MergePullRequest(client *github.Client, t translations.TranslationHelperFun if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - commitTitle, err := optionalParam[string](request, "commit_title") + commitTitle, err := OptionalParam[string](request, "commit_title") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - commitMessage, err := optionalParam[string](request, "commit_message") + commitMessage, err := OptionalParam[string](request, "commit_message") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - mergeMethod, err := optionalParam[string](request, "merge_method") + mergeMethod, err := OptionalParam[string](request, "merge_method") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -271,7 +271,7 @@ func GetPullRequestFiles(client *github.Client, t translations.TranslationHelper if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -326,7 +326,7 @@ func GetPullRequestStatus(client *github.Client, t translations.TranslationHelpe if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -398,11 +398,11 @@ func UpdatePullRequestBranch(client *github.Client, t translations.TranslationHe if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - expectedHeadSHA, err := optionalParam[string](request, "expectedHeadSha") + expectedHeadSHA, err := OptionalParam[string](request, "expectedHeadSha") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -465,7 +465,7 @@ func GetPullRequestComments(client *github.Client, t translations.TranslationHel if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -525,7 +525,7 @@ func GetPullRequestReviews(client *github.Client, t translations.TranslationHelp if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -629,7 +629,7 @@ func CreatePullRequestReview(client *github.Client, t translations.TranslationHe if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pullNumber, err := requiredInt(request, "pullNumber") + pullNumber, err := RequiredInt(request, "pullNumber") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -644,7 +644,7 @@ func CreatePullRequestReview(client *github.Client, t translations.TranslationHe } // Add body if provided - body, err := optionalParam[string](request, "body") + body, err := OptionalParam[string](request, "body") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -653,7 +653,7 @@ func CreatePullRequestReview(client *github.Client, t translations.TranslationHe } // Add commit ID if provided - commitID, err := optionalParam[string](request, "commitId") + commitID, err := OptionalParam[string](request, "commitId") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -801,17 +801,17 @@ func CreatePullRequest(client *github.Client, t translations.TranslationHelperFu return mcp.NewToolResultError(err.Error()), nil } - body, err := optionalParam[string](request, "body") + body, err := OptionalParam[string](request, "body") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - draft, err := optionalParam[bool](request, "draft") + draft, err := OptionalParam[bool](request, "draft") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - maintainerCanModify, err := optionalParam[bool](request, "maintainer_can_modify") + maintainerCanModify, err := OptionalParam[bool](request, "maintainer_can_modify") if err != nil { return mcp.NewToolResultError(err.Error()), nil } diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index 7725438bd..2dafd4cee 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -28,7 +28,7 @@ func ListCommits(client *github.Client, t translations.TranslationHelperFunc) (t mcp.WithString("sha", mcp.Description("Branch name"), ), - withPagination(), + WithPagination(), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { owner, err := requiredParam[string](request, "owner") @@ -39,11 +39,11 @@ func ListCommits(client *github.Client, t translations.TranslationHelperFunc) (t if err != nil { return mcp.NewToolResultError(err.Error()), nil } - sha, err := optionalParam[string](request, "sha") + sha, err := OptionalParam[string](request, "sha") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pagination, err := optionalPaginationParams(request) + pagination, err := OptionalPaginationParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -148,7 +148,7 @@ func CreateOrUpdateFile(client *github.Client, t translations.TranslationHelperF } // If SHA is provided, set it (for updates) - sha, err := optionalParam[string](request, "sha") + sha, err := OptionalParam[string](request, "sha") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -203,15 +203,15 @@ func CreateRepository(client *github.Client, t translations.TranslationHelperFun if err != nil { return mcp.NewToolResultError(err.Error()), nil } - description, err := optionalParam[string](request, "description") + description, err := OptionalParam[string](request, "description") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - private, err := optionalParam[bool](request, "private") + private, err := OptionalParam[bool](request, "private") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - autoInit, err := optionalParam[bool](request, "autoInit") + autoInit, err := OptionalParam[bool](request, "autoInit") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -279,7 +279,7 @@ func GetFileContents(client *github.Client, t translations.TranslationHelperFunc if err != nil { return mcp.NewToolResultError(err.Error()), nil } - branch, err := optionalParam[string](request, "branch") + branch, err := OptionalParam[string](request, "branch") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -340,7 +340,7 @@ func ForkRepository(client *github.Client, t translations.TranslationHelperFunc) if err != nil { return mcp.NewToolResultError(err.Error()), nil } - org, err := optionalParam[string](request, "organization") + org, err := OptionalParam[string](request, "organization") if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -411,7 +411,7 @@ func CreateBranch(client *github.Client, t translations.TranslationHelperFunc) ( if err != nil { return mcp.NewToolResultError(err.Error()), nil } - fromBranch, err := optionalParam[string](request, "from_branch") + fromBranch, err := OptionalParam[string](request, "from_branch") if err != nil { return mcp.NewToolResultError(err.Error()), nil } diff --git a/pkg/github/search.go b/pkg/github/search.go index 46fed5997..cd2ab4346 100644 --- a/pkg/github/search.go +++ b/pkg/github/search.go @@ -20,14 +20,14 @@ func SearchRepositories(client *github.Client, t translations.TranslationHelperF mcp.Required(), mcp.Description("Search query"), ), - withPagination(), + WithPagination(), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { query, err := requiredParam[string](request, "query") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pagination, err := optionalPaginationParams(request) + pagination, err := OptionalPaginationParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -77,22 +77,22 @@ func SearchCode(client *github.Client, t translations.TranslationHelperFunc) (to mcp.Description("Sort order ('asc' or 'desc')"), mcp.Enum("asc", "desc"), ), - withPagination(), + WithPagination(), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { query, err := requiredParam[string](request, "q") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - sort, err := optionalParam[string](request, "sort") + sort, err := OptionalParam[string](request, "sort") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - order, err := optionalParam[string](request, "order") + order, err := OptionalParam[string](request, "order") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pagination, err := optionalPaginationParams(request) + pagination, err := OptionalPaginationParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil } @@ -145,22 +145,22 @@ func SearchUsers(client *github.Client, t translations.TranslationHelperFunc) (t mcp.Description("Sort order ('asc' or 'desc')"), mcp.Enum("asc", "desc"), ), - withPagination(), + WithPagination(), ), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { query, err := requiredParam[string](request, "q") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - sort, err := optionalParam[string](request, "sort") + sort, err := OptionalParam[string](request, "sort") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - order, err := optionalParam[string](request, "order") + order, err := OptionalParam[string](request, "order") if err != nil { return mcp.NewToolResultError(err.Error()), nil } - pagination, err := optionalPaginationParams(request) + pagination, err := OptionalPaginationParams(request) if err != nil { return mcp.NewToolResultError(err.Error()), nil } diff --git a/pkg/github/server.go b/pkg/github/server.go index d8a9b2307..5852d581d 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -72,7 +72,7 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati s.AddTool(SearchUsers(client, t)) // Add GitHub tools - Users - s.AddTool(getMe(client, t)) + s.AddTool(GetMe(client, t)) // Add GitHub tools - Code Scanning s.AddTool(GetCodeScanningAlert(client, t)) @@ -80,8 +80,8 @@ func NewServer(client *github.Client, version string, readOnly bool, t translati return s } -// getMe creates a tool to get details of the authenticated user. -func getMe(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { +// GetMe creates a tool to get details of the authenticated user. +func GetMe(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) { return mcp.NewTool("get_me", mcp.WithDescription(t("TOOL_GET_ME_DESCRIPTION", "Get details of the authenticated GitHub user. Use this when a request include \"me\", \"my\"...")), mcp.WithString("reason", @@ -144,12 +144,12 @@ func requiredParam[T comparable](r mcp.CallToolRequest, p string) (T, error) { return r.Params.Arguments[p].(T), nil } -// requiredInt is a helper function that can be used to fetch a requested parameter from the request. +// RequiredInt is a helper function that can be used to fetch a requested parameter from the request. // It does the following checks: // 1. Checks if the parameter is present in the request. // 2. Checks if the parameter is of the expected type. // 3. Checks if the parameter is not empty, i.e: non-zero value -func requiredInt(r mcp.CallToolRequest, p string) (int, error) { +func RequiredInt(r mcp.CallToolRequest, p string) (int, error) { v, err := requiredParam[float64](r, p) if err != nil { return 0, err @@ -157,11 +157,11 @@ func requiredInt(r mcp.CallToolRequest, p string) (int, error) { return int(v), nil } -// optionalParam is a helper function that can be used to fetch a requested parameter from the request. +// OptionalParam is a helper function that can be used to fetch a requested parameter from the request. // It does the following checks: // 1. Checks if the parameter is present in the request, if not, it returns its zero-value // 2. If it is present, it checks if the parameter is of the expected type and returns it -func optionalParam[T any](r mcp.CallToolRequest, p string) (T, error) { +func OptionalParam[T any](r mcp.CallToolRequest, p string) (T, error) { var zero T // Check if the parameter is present in the request @@ -177,22 +177,22 @@ func optionalParam[T any](r mcp.CallToolRequest, p string) (T, error) { return r.Params.Arguments[p].(T), nil } -// optionalIntParam is a helper function that can be used to fetch a requested parameter from the request. +// OptionalIntParam is a helper function that can be used to fetch a requested parameter from the request. // It does the following checks: // 1. Checks if the parameter is present in the request, if not, it returns its zero-value // 2. If it is present, it checks if the parameter is of the expected type and returns it -func optionalIntParam(r mcp.CallToolRequest, p string) (int, error) { - v, err := optionalParam[float64](r, p) +func OptionalIntParam(r mcp.CallToolRequest, p string) (int, error) { + v, err := OptionalParam[float64](r, p) if err != nil { return 0, err } return int(v), nil } -// optionalIntParamWithDefault is a helper function that can be used to fetch a requested parameter from the request +// OptionalIntParamWithDefault is a helper function that can be used to fetch a requested parameter from the request // similar to optionalIntParam, but it also takes a default value. -func optionalIntParamWithDefault(r mcp.CallToolRequest, p string, d int) (int, error) { - v, err := optionalIntParam(r, p) +func OptionalIntParamWithDefault(r mcp.CallToolRequest, p string, d int) (int, error) { + v, err := OptionalIntParam(r, p) if err != nil { return 0, err } @@ -202,11 +202,11 @@ func optionalIntParamWithDefault(r mcp.CallToolRequest, p string, d int) (int, e return v, nil } -// optionalStringArrayParam is a helper function that can be used to fetch a requested parameter from the request. +// OptionalStringArrayParam is a helper function that can be used to fetch a requested parameter from the request. // It does the following checks: // 1. Checks if the parameter is present in the request, if not, it returns its zero-value // 2. If it is present, iterates the elements and checks each is a string -func optionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error) { +func OptionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error) { // Check if the parameter is present in the request if _, ok := r.Params.Arguments[p]; !ok { return []string{}, nil @@ -230,9 +230,9 @@ func optionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error) } } -// withPagination returns a ToolOption that adds "page" and "perPage" parameters to the tool. +// WithPagination returns a ToolOption that adds "page" and "perPage" parameters to the tool. // The "page" parameter is optional, min 1. The "perPage" parameter is optional, min 1, max 100. -func withPagination() mcp.ToolOption { +func WithPagination() mcp.ToolOption { return func(tool *mcp.Tool) { mcp.WithNumber("page", mcp.Description("Page number for pagination (min 1)"), @@ -247,26 +247,26 @@ func withPagination() mcp.ToolOption { } } -type paginationParams struct { +type PaginationParams struct { page int perPage int } -// optionalPaginationParams returns the "page" and "perPage" parameters from the request, +// OptionalPaginationParams returns the "page" and "perPage" parameters from the request, // or their default values if not present, "page" default is 1, "perPage" default is 30. // In future, we may want to make the default values configurable, or even have this // function returned from `withPagination`, where the defaults are provided alongside // the min/max values. -func optionalPaginationParams(r mcp.CallToolRequest) (paginationParams, error) { - page, err := optionalIntParamWithDefault(r, "page", 1) +func OptionalPaginationParams(r mcp.CallToolRequest) (PaginationParams, error) { + page, err := OptionalIntParamWithDefault(r, "page", 1) if err != nil { - return paginationParams{}, err + return PaginationParams{}, err } - perPage, err := optionalIntParamWithDefault(r, "perPage", 30) + perPage, err := OptionalIntParamWithDefault(r, "perPage", 30) if err != nil { - return paginationParams{}, err + return PaginationParams{}, err } - return paginationParams{ + return PaginationParams{ page: page, perPage: perPage, }, nil diff --git a/pkg/github/server_test.go b/pkg/github/server_test.go index 149fb77ab..979046fc8 100644 --- a/pkg/github/server_test.go +++ b/pkg/github/server_test.go @@ -18,7 +18,7 @@ import ( func Test_GetMe(t *testing.T) { // Verify tool definition mockClient := github.NewClient(nil) - tool, _ := getMe(mockClient, translations.NullTranslationHelper) + tool, _ := GetMe(mockClient, translations.NullTranslationHelper) assert.Equal(t, "get_me", tool.Name) assert.NotEmpty(t, tool.Description) @@ -96,7 +96,7 @@ func Test_GetMe(t *testing.T) { t.Run(tc.name, func(t *testing.T) { // Setup client with mock client := github.NewClient(tc.mockedClient) - _, handler := getMe(client, translations.NullTranslationHelper) + _, handler := GetMe(client, translations.NullTranslationHelper) // Create call request request := createMCPRequest(tc.requestArgs) @@ -262,7 +262,7 @@ func Test_OptionalStringParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { request := createMCPRequest(tc.params) - result, err := optionalParam[string](request, tc.paramName) + result, err := OptionalParam[string](request, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -308,7 +308,7 @@ func Test_RequiredNumberParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { request := createMCPRequest(tc.params) - result, err := requiredInt(request, tc.paramName) + result, err := RequiredInt(request, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -361,7 +361,7 @@ func Test_OptionalNumberParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { request := createMCPRequest(tc.params) - result, err := optionalIntParam(request, tc.paramName) + result, err := OptionalIntParam(request, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -419,7 +419,7 @@ func Test_OptionalNumberParamWithDefault(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { request := createMCPRequest(tc.params) - result, err := optionalIntParamWithDefault(request, tc.paramName, tc.defaultVal) + result, err := OptionalIntParamWithDefault(request, tc.paramName, tc.defaultVal) if tc.expectError { assert.Error(t, err) @@ -472,7 +472,7 @@ func Test_OptionalBooleanParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { request := createMCPRequest(tc.params) - result, err := optionalParam[bool](request, tc.paramName) + result, err := OptionalParam[bool](request, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -540,7 +540,7 @@ func TestOptionalStringArrayParam(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { request := createMCPRequest(tc.params) - result, err := optionalStringArrayParam(request, tc.paramName) + result, err := OptionalStringArrayParam(request, tc.paramName) if tc.expectError { assert.Error(t, err) @@ -556,13 +556,13 @@ func TestOptionalPaginationParams(t *testing.T) { tests := []struct { name string params map[string]any - expected paginationParams + expected PaginationParams expectError bool }{ { name: "no pagination parameters, default values", params: map[string]any{}, - expected: paginationParams{ + expected: PaginationParams{ page: 1, perPage: 30, }, @@ -573,7 +573,7 @@ func TestOptionalPaginationParams(t *testing.T) { params: map[string]any{ "page": float64(2), }, - expected: paginationParams{ + expected: PaginationParams{ page: 2, perPage: 30, }, @@ -584,7 +584,7 @@ func TestOptionalPaginationParams(t *testing.T) { params: map[string]any{ "perPage": float64(50), }, - expected: paginationParams{ + expected: PaginationParams{ page: 1, perPage: 50, }, @@ -596,7 +596,7 @@ func TestOptionalPaginationParams(t *testing.T) { "page": float64(2), "perPage": float64(50), }, - expected: paginationParams{ + expected: PaginationParams{ page: 2, perPage: 50, }, @@ -607,7 +607,7 @@ func TestOptionalPaginationParams(t *testing.T) { params: map[string]any{ "page": "not-a-number", }, - expected: paginationParams{}, + expected: PaginationParams{}, expectError: true, }, { @@ -615,7 +615,7 @@ func TestOptionalPaginationParams(t *testing.T) { params: map[string]any{ "perPage": "not-a-number", }, - expected: paginationParams{}, + expected: PaginationParams{}, expectError: true, }, } @@ -623,7 +623,7 @@ func TestOptionalPaginationParams(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { request := createMCPRequest(tc.params) - result, err := optionalPaginationParams(request) + result, err := OptionalPaginationParams(request) if tc.expectError { assert.Error(t, err) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy