Skip to content

Commit b436b0b

Browse files
sridharavinashSamMorrowDrums
authored andcommitted
refactor: update notification functions to use GetClientFn . Fix conflicts
1 parent 1126d3c commit b436b0b

File tree

2 files changed

+139
-7
lines changed

2 files changed

+139
-7
lines changed

pkg/github/notifications.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
// getNotifications creates a tool to list notifications for the current user.
18-
func getNotifications(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
18+
func GetNotifications(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
1919
return mcp.NewTool("get_notifications",
2020
mcp.WithDescription(t("TOOL_GET_NOTIFICATIONS_DESCRIPTION", "Get notifications for the authenticated GitHub user")),
2121
mcp.WithBoolean("all",
@@ -38,6 +38,11 @@ func getNotifications(client *github.Client, t translations.TranslationHelperFun
3838
),
3939
),
4040
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
41+
client, err := getClient(ctx)
42+
if err != nil {
43+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
44+
}
45+
4146
// Extract optional parameters with defaults
4247
all, err := OptionalParamWithDefault[bool](request, "all", false)
4348
if err != nil {
@@ -122,7 +127,7 @@ func getNotifications(client *github.Client, t translations.TranslationHelperFun
122127
}
123128

124129
// markNotificationRead creates a tool to mark a notification as read.
125-
func markNotificationRead(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
130+
func MarkNotificationRead(getclient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
126131
return mcp.NewTool("mark_notification_read",
127132
mcp.WithDescription(t("TOOL_MARK_NOTIFICATION_READ_DESCRIPTION", "Mark a notification as read")),
128133
mcp.WithString("threadID",
@@ -131,6 +136,11 @@ func markNotificationRead(client *github.Client, t translations.TranslationHelpe
131136
),
132137
),
133138
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
139+
client, err := getclient(ctx)
140+
if err != nil {
141+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
142+
}
143+
134144
threadID, err := requiredParam[string](request, "threadID")
135145
if err != nil {
136146
return mcp.NewToolResultError(err.Error()), nil
@@ -154,16 +164,21 @@ func markNotificationRead(client *github.Client, t translations.TranslationHelpe
154164
}
155165
}
156166

157-
// markAllNotificationsRead creates a tool to mark all notifications as read.
158-
func markAllNotificationsRead(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
167+
// MarkAllNotificationsRead creates a tool to mark all notifications as read.
168+
func MarkAllNotificationsRead(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
159169
return mcp.NewTool("mark_all_notifications_read",
160170
mcp.WithDescription(t("TOOL_MARK_ALL_NOTIFICATIONS_READ_DESCRIPTION", "Mark all notifications as read")),
161171
mcp.WithString("lastReadAt",
162172
mcp.Description("Describes the last point that notifications were checked (optional). Default: Now"),
163173
),
164174
),
165175
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
166-
lastReadAt, err := OptionalParam[string](request, "lastReadAt")
176+
client, err := getClient(ctx)
177+
if err != nil {
178+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
179+
}
180+
181+
lastReadAt, err := OptionalParam(request, "lastReadAt")
167182
if err != nil {
168183
return mcp.NewToolResultError(err.Error()), nil
169184
}
@@ -197,8 +212,8 @@ func markAllNotificationsRead(client *github.Client, t translations.TranslationH
197212
}
198213
}
199214

200-
// getNotificationThread creates a tool to get a specific notification thread.
201-
func getNotificationThread(client *github.Client, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
215+
// GetNotificationThread creates a tool to get a specific notification thread.
216+
func GetNotificationThread(getClient GetClientFn, t translations.TranslationHelperFunc) (tool mcp.Tool, handler server.ToolHandlerFunc) {
202217
return mcp.NewTool("get_notification_thread",
203218
mcp.WithDescription(t("TOOL_GET_NOTIFICATION_THREAD_DESCRIPTION", "Get a specific notification thread")),
204219
mcp.WithString("threadID",
@@ -207,6 +222,11 @@ func getNotificationThread(client *github.Client, t translations.TranslationHelp
207222
),
208223
),
209224
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
225+
client, err := getClient(ctx)
226+
if err != nil {
227+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
228+
}
229+
210230
threadID, err := requiredParam[string](request, "threadID")
211231
if err != nil {
212232
return mcp.NewToolResultError(err.Error()), nil

pkg/github/server.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,77 @@ func NewServer(version string, opts ...server.ServerOption) *server.MCPServer {
2626
version,
2727
opts...,
2828
)
29+
<<<<<<< HEAD
30+
=======
31+
32+
// Add GitHub Resources
33+
s.AddResourceTemplate(GetRepositoryResourceContent(getClient, t))
34+
s.AddResourceTemplate(GetRepositoryResourceBranchContent(getClient, t))
35+
s.AddResourceTemplate(GetRepositoryResourceCommitContent(getClient, t))
36+
s.AddResourceTemplate(GetRepositoryResourceTagContent(getClient, t))
37+
s.AddResourceTemplate(GetRepositoryResourcePrContent(getClient, t))
38+
39+
// Add GitHub tools - Issues
40+
s.AddTool(GetIssue(getClient, t))
41+
s.AddTool(SearchIssues(getClient, t))
42+
s.AddTool(ListIssues(getClient, t))
43+
s.AddTool(GetIssueComments(getClient, t))
44+
if !readOnly {
45+
s.AddTool(CreateIssue(getClient, t))
46+
s.AddTool(AddIssueComment(getClient, t))
47+
s.AddTool(UpdateIssue(getClient, t))
48+
}
49+
50+
// Add GitHub tools - Pull Requests
51+
s.AddTool(GetPullRequest(getClient, t))
52+
s.AddTool(ListPullRequests(getClient, t))
53+
s.AddTool(GetPullRequestFiles(getClient, t))
54+
s.AddTool(GetPullRequestStatus(getClient, t))
55+
s.AddTool(GetPullRequestComments(getClient, t))
56+
s.AddTool(GetPullRequestReviews(getClient, t))
57+
if !readOnly {
58+
s.AddTool(MergePullRequest(getClient, t))
59+
s.AddTool(UpdatePullRequestBranch(getClient, t))
60+
s.AddTool(CreatePullRequestReview(getClient, t))
61+
s.AddTool(CreatePullRequest(getClient, t))
62+
s.AddTool(UpdatePullRequest(getClient, t))
63+
s.AddTool(AddPullRequestReviewComment(getClient, t))
64+
}
65+
66+
// Add GitHub tools - Repositories
67+
s.AddTool(SearchRepositories(getClient, t))
68+
s.AddTool(GetFileContents(getClient, t))
69+
s.AddTool(GetCommit(getClient, t))
70+
s.AddTool(ListCommits(getClient, t))
71+
s.AddTool(ListBranches(getClient, t))
72+
if !readOnly {
73+
s.AddTool(CreateOrUpdateFile(getClient, t))
74+
s.AddTool(CreateRepository(getClient, t))
75+
s.AddTool(ForkRepository(getClient, t))
76+
s.AddTool(CreateBranch(getClient, t))
77+
s.AddTool(PushFiles(getClient, t))
78+
}
79+
80+
// Add GitHub tools - Search
81+
s.AddTool(SearchCode(getClient, t))
82+
s.AddTool(SearchUsers(getClient, t))
83+
84+
// Add GitHub tools - Users
85+
s.AddTool(GetMe(getClient, t))
86+
87+
// Add GitHub tools - Code Scanning
88+
s.AddTool(GetCodeScanningAlert(getClient, t))
89+
s.AddTool(ListCodeScanningAlerts(getClient, t))
90+
91+
// Add GitHub tools - Notifications
92+
s.AddTool(GetNotifications(getClient, t))
93+
s.AddTool(GetNotificationThread(getClient, t))
94+
if !readOnly {
95+
s.AddTool(MarkNotificationRead(getClient, t))
96+
s.AddTool(MarkAllNotificationsRead(getClient, t))
97+
}
98+
99+
>>>>>>> dbdef79 (refactor: update notification functions to use GetClientFn . Fix conflicts)
29100
return s
30101
}
31102

@@ -163,6 +234,47 @@ func OptionalIntParamWithDefault(r mcp.CallToolRequest, p string, d int) (int, e
163234
return v, nil
164235
}
165236

237+
// OptionalBoolParamWithDefault is a helper function that can be used to fetch a requested parameter from the request
238+
// similar to optionalParam, but it also takes a default value.
239+
func OptionalBoolParamWithDefault(r mcp.CallToolRequest, p string, d bool) (bool, error) {
240+
v, err := OptionalParam[bool](r, p)
241+
if err != nil {
242+
return false, err
243+
}
244+
if v == false {
245+
return d, nil
246+
}
247+
return v, nil
248+
}
249+
250+
// OptionalStringParam is a helper function that can be used to fetch a requested parameter from the request.
251+
// It does the following checks:
252+
// 1. Checks if the parameter is present in the request, if not, it returns its zero-value
253+
// 2. If it is present, it checks if the parameter is of the expected type and returns it
254+
func OptionalStringParam(r mcp.CallToolRequest, p string) (string, error) {
255+
v, err := OptionalParam[string](r, p)
256+
if err != nil {
257+
return "", err
258+
}
259+
if v == "" {
260+
return "", nil
261+
}
262+
return v, nil
263+
}
264+
265+
// OptionalStringParamWithDefault is a helper function that can be used to fetch a requested parameter from the request
266+
// similar to optionalParam, but it also takes a default value.
267+
func OptionalStringParamWithDefault(r mcp.CallToolRequest, p string, d string) (string, error) {
268+
v, err := OptionalParam[string](r, p)
269+
if err != nil {
270+
return "", err
271+
}
272+
if v == "" {
273+
return d, nil
274+
}
275+
return v, nil
276+
}
277+
166278
// OptionalStringArrayParam is a helper function that can be used to fetch a requested parameter from the request.
167279
// It does the following checks:
168280
// 1. Checks if the parameter is present in the request, if not, it returns its zero-value

0 commit comments

Comments
 (0)