@@ -59,36 +59,37 @@ def __init__(self):
5959 - Registers the necessary MCP tools for further processing.
6060 - Logs the successful initialization of the MCP server.
6161 """
62-
63- # Initialize GitHub token
64- self .gi = GI ()
62+
63+ self .gi = GI () # Initialize GitHub token
6564 self .ip = IP ()
66-
65+
6766 # Initialize MCP Server
6867 self .mcp = FastMCP (
6968 name = "GitHub PR and Issue Analyser" ,
70- instruction = "You are a GitHub PR and Issue Analyser. You can fetch PR diffs, update PR descriptions, create and update issues, create tags and releases, and fetch IP information." ,
69+ instruction = """
70+ You are a GitHub PR and Issue Analyser. You can fetch PR diffs, update PR descriptions,
71+ create and update issues, create tags and releases, and fetch IP information.
72+ """ ,
7173 )
7274 logging .info ("MCP Server initialized" )
73-
75+
7476 # Register MCP tools
7577 self ._register_tools ()
76-
78+
7779 def _register_tools (self ):
7880 """Registers the MCP tools for GitHub PR and issue management."""
7981
8082 @self .mcp .tool ()
8183 async def get_github_pr_diff (repo_owner : str , repo_name : str , pr_number : int ) -> dict [str , Any ]:
8284 """
8385 Fetches the diff of a specific pull request from a GitHub repository.
84- Use only get_pr_diff to fetch the diff of a specific pull request from a GitHub repository.
8586 Args:
8687 repo_owner (str): The owner of the GitHub repository.
8788 repo_name (str): The name of the GitHub repository.
8889 pr_number (int): The pull request number to fetch the diff for.
8990 Returns:
9091 dict[str, Any]: A dictionary containing the pull request diff. Returns a 'No changes' string if no changes are found,
91- or an error message string if an exception occurs.
92+ or an error message string if an exception occurs.
9293 """
9394 logging .info (f"Fetching PR #{ pr_number } diff from { repo_owner } /{ repo_name } " )
9495 try :
@@ -108,14 +109,15 @@ async def get_github_pr_diff(repo_owner: str, repo_name: str, pr_number: int) ->
108109 async def get_github_pr_content (repo_owner : str , repo_name : str , pr_number : int ) -> dict [str , Any ]:
109110 """
110111 Fetches the content of a specific pull request from a GitHub repository.
111- Use only get_pr_content to fetch the content of a specific pull request from a GitHub repository.
112+ - Use only get_github_pr_diff to fetch the content of a specific pull request from a GitHub repository.
113+ - Use get_github_pr_content if there is no diff available.
112114 Args:
113115 repo_owner (str): The owner of the GitHub repository.
114116 repo_name (str): The name of the GitHub repository.
115117 pr_number (int): The pull request number to fetch the content for.
116118 Returns:
117119 dict[str, Any]: A dictionary containing the pull request content. Returns a 'No changes' string if no changes are found,
118- or an error message string if an exception occurs.
120+ or an error message string if an exception occurs.
119121 """
120122 logging .info (f"Fetching PR #{ pr_number } from { repo_owner } /{ repo_name } " )
121123 try :
@@ -130,12 +132,12 @@ async def get_github_pr_content(repo_owner: str, repo_name: str, pr_number: int)
130132 logging .error ({"status" : "error" , "message" : str (e )})
131133 traceback .print_exc (file = sys .stderr )
132134 return {"status" : "error" , "message" : str (e )}
133-
135+
134136 @self .mcp .tool ()
135137 async def update_github_pr_description (repo_owner : str , repo_name : str , pr_number : int , new_title : str , new_description : str ) -> dict [str , Any ]:
136138 """
137139 Updates the title and description of a specific pull request on GitHub.
138- Use only update_pr_description to update the title and description of a specific pull request on GitHub .
140+ - title should be one of chore, fix, bug, feat, docs etc .
139141 Args:
140142 repo_owner (str): The owner of the GitHub repository.
141143 repo_name (str): The name of the GitHub repository.
@@ -144,7 +146,7 @@ async def update_github_pr_description(repo_owner: str, repo_name: str, pr_numbe
144146 new_description (str): The new description for the pull request.
145147 Returns:
146148 dict[str, Any]: A dictionary containing the status and message of the update operation.
147- Returns a success message if the update is successful, or an error message if an exception occurs
149+ Returns a success message if the update is successful, or an error message if an exception occurs
148150 """
149151 logging .info (f"Updating PR #{ pr_number } description" )
150152 try :
@@ -170,7 +172,7 @@ async def add_github_pr_inline_comment(repo_owner: str, repo_name: str, pr_numbe
170172 comment_body (str): The content of the comment to be added.
171173 Returns:
172174 dict[str, Any]: A dictionary containing the status and message of the comment addition.
173- Returns a success message if the comment is added successfully, or an error message if an exception occurs.
175+ Returns a success message if the comment is added successfully, or an error message if an exception occurs.
174176 """
175177 logging .info (f"Adding inline review comment to PR #{ pr_number } " )
176178 try :
@@ -186,15 +188,15 @@ async def add_github_pr_inline_comment(repo_owner: str, repo_name: str, pr_numbe
186188 @self .mcp .tool ()
187189 async def add_github_pr_comment (repo_owner : str , repo_name : str , pr_number : int , comment : str ) -> dict [str , Any ]:
188190 """
189- Adds a comment to a specific pull request on GitHub.
191+ Adds a markdown comment to a specific pull request on GitHub.
190192 Args:
191193 repo_owner (str): The owner of the GitHub repository.
192194 repo_name (str): The name of the GitHub repository.
193195 pr_number (int): The pull request number to add the comment to.
194196 comment (str): The content of the comment to be added.
195197 Returns:
196198 dict[str, Any]: A dictionary containing the status and message of the comment addition.
197- Returns a success message if the comment is added successfully, or an error message if an exception occurs.
199+ Returns a success message if the comment is added successfully, or an error message if an exception occurs.
198200 """
199201 logging .info (f"Adding comment to PR #{ pr_number } " )
200202 try :
@@ -211,12 +213,14 @@ async def add_github_pr_comment(repo_owner: str, repo_name: str, pr_number: int,
211213 async def list_github_issues_prs (repo_owner : str , issue : str ) -> dict [str , Any ]:
212214 """
213215 Lists open issues or pull requests for a specified GitHub repository.
216+ - Present the issues or pull requests in a markdown table format.
217+ - Add index column to the table, and make the title link to the issue or pull request.
214218 Args:
215219 repo_owner (str): The owner of the GitHub repository.
216220 issue (str): The type of items to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'.
217221 Returns:
218222 dict[str, Any]: A dictionary containing the list of open issues or pull requests.
219- Returns an error message if an exception occurs during the listing process.
223+ Returns an error message if an exception occurs during the listing process.
220224 """
221225 logging .info ({"status" : "info" , "message" : f"Listing open { issue } for { repo_owner } " })
222226 try :
@@ -232,15 +236,16 @@ async def list_github_issues_prs(repo_owner: str, issue: str) -> dict[str, Any]:
232236 async def create_github_issue (repo_owner : str , repo_name : str , title : str , body : str , labels : list [str ]) -> dict [str , Any ]:
233237 """
234238 Creates a GitHub issue with the specified parameters.
239+ - title should be one of chore, fix, bug, feat, docs etc.
235240 Args:
236241 repo_owner (str): The owner of the GitHub repository.
237242 repo_name (str): The name of the GitHub repository.
238- title (str): The title of the issue, one of chore, fix, bug, feat, docs etc .
243+ title (str): The title of the issue.
239244 body (str): The body content of the issue.
240245 labels (list[str]): A list of labels to assign to the issue.
241246 Returns:
242247 dict[str, Any]: A dictionary containing the status and message of the issue creation.
243- Returns a success message if the issue is created successfully, or an error message if an exception occurs.
248+ Returns a success message if the issue is created successfully, or an error message if an exception occurs.
244249 """
245250 logging .info (f"Creating GitHub issue: { title } " )
246251 try :
@@ -257,6 +262,7 @@ async def create_github_issue(repo_owner: str, repo_name: str, title: str, body:
257262 async def update_github_issue (repo_owner : str , repo_name : str , issue_number : int , title : str , body : str , labels : list [str ], state : str ) -> dict [str , Any ]:
258263 """
259264 Updates a GitHub issue with the specified parameters.
265+ - title should be one of chore, fix, bug, feat, docs etc.
260266 Args:
261267 repo_owner (str): The owner of the GitHub repository.
262268 repo_name (str): The name of the GitHub repository.
@@ -267,7 +273,7 @@ async def update_github_issue(repo_owner: str, repo_name: str, issue_number: int
267273 state (str): The new state of the issue, either 'open' or 'closed'.
268274 Returns:
269275 dict[str, Any]: A dictionary containing the status and message of the issue update.
270- Returns a success message if the issue is updated successfully, or an error message if an exception occurs.
276+ Returns a success message if the issue is updated successfully, or an error message if an exception occurs.
271277 """
272278 logging .info (f"Updating GitHub issue #{ issue_number } : { title } " )
273279 try :
@@ -279,19 +285,22 @@ async def update_github_issue(repo_owner: str, repo_name: str, issue_number: int
279285 logging .error (error_msg )
280286 traceback .print_exc (file = sys .stderr )
281287 return {"status" : "error" , "message" : error_msg }
282-
288+
283289 @self .mcp .tool ()
284290 async def create_github_tag (repo_owner : str , repo_name : str , tag_name : str , message : str ) -> dict [str , Any ]:
285291 """
286292 Creates a GitHub tag for the specified repository.
293+ - Add a markdown comment to the tag.
294+ - The tag name should be descriptive and meaningful.
295+ - The message should contain detailed information about the tag, including changes, features, and fixes
287296 Args:
288297 repo_owner (str): The owner of the GitHub repository.
289298 repo_name (str): The name of the GitHub repository.
290299 tag_name (str): The name of the tag to be created.
291300 message (str): The message or description for the tag.
292301 Returns:
293302 dict[str, Any]: A dictionary containing the status and message of the tag creation.
294- Returns a success message if the tag is created successfully, or an error message if an exception occurs.
303+ Returns a success message if the tag is created successfully, or an error message if an exception occurs.
295304 """
296305 logging .info (f"Creating GitHub tag: { tag_name } " )
297306 try :
@@ -303,11 +312,14 @@ async def create_github_tag(repo_owner: str, repo_name: str, tag_name: str, mess
303312 logging .error (error_msg )
304313 traceback .print_exc (file = sys .stderr )
305314 return {"status" : "error" , "message" : error_msg }
306-
315+
307316 @self .mcp .tool ()
308317 async def create_github_release (repo_owner : str , repo_name : str , tag_name : str , release_name : str , body : str ) -> dict [str , Any ]:
309318 """
310319 Creates a GitHub release from a specified tag.
320+ - Add a markdown comment to the release.
321+ - The release name should be descriptive and meaningful.
322+ - The body should contain detailed information about the release, including changes, features, and fixes
311323 Args:
312324 repo_owner (str): The owner of the GitHub repository.
313325 repo_name (str): The name of the GitHub repository.
@@ -316,7 +328,7 @@ async def create_github_release(repo_owner: str, repo_name: str, tag_name: str,
316328 body (str): The body content of the release.
317329 Returns:
318330 dict[str, Any]: A dictionary containing the status and message of the release creation.
319- Returns a success message if the release is created successfully, or an error message if an exception occurs.
331+ Returns a success message if the release is created successfully, or an error message if an exception occurs.
320332 """
321333 logging .info (f"Creating GitHub release '{ release_name } ' from tag '{ tag_name } '" )
322334 try :
@@ -328,7 +340,7 @@ async def create_github_release(repo_owner: str, repo_name: str, tag_name: str,
328340 logging .error (error_msg )
329341 traceback .print_exc (file = sys .stderr )
330342 return {"status" : "error" , "message" : error_msg }
331-
343+
332344 @self .mcp .tool ()
333345 async def get_ipv4_ipv6_info () -> dict [str , Any ]:
334346 """
@@ -338,7 +350,7 @@ async def get_ipv4_ipv6_info() -> dict[str, Any]:
338350 If both are available, the IPv6 address is added to the IPv4 info dictionary under the "ipv6" key.
339351 Returns:
340352 dict[str, Any]: A dictionary containing IPv4 information, with the IPv6 address included if available.
341- Returns an empty dictionary if either IPv4 or IPv6 information is missing or if an error occurs.
353+ Returns an empty dictionary if either IPv4 or IPv6 information is missing or if an error occurs.
342354 Error Handling:
343355 Logs any exceptions encountered during the fetching process and returns an empty dictionary.
344356 """
0 commit comments