MatteoMass's picture
removed the tokens from env
9ad58d0
raw
history blame contribute delete
943 Bytes
"""
Branch listing tool.
"""
from typing import List, Dict
from mcp.server.fastmcp import Context
from pmcp.mcp_server.github_server.services.branches import BranchService
from pmcp.mcp_server.github_server.github import github_client
service = BranchService(github_client)
async def list_branches(ctx: Context, owner: str, repo: str) -> Dict[str, List[str]]:
"""
Gets the list of branches.
Args:
ctx: FastMCP request context (handles errors).
owner (str): Repository owner.
repo (str): Repository name.
Returns:
{"branches": ["main", "dev", …]}
"""
try:
branches = await service.list_branches(owner, repo)
names = [b["name"] for b in branches]
return {"branches": names}
except Exception as exc:
error_msg = f"Error while getting the list of branches for repository {repo}. Error: {str(exc)}"
await ctx.error(str(exc))
raise