get_user_repositories
Fetch repositories for authenticated GitHub users to manage and access their code projects through OAuth-secured connections.
Instructions
Fetch the repositories of the authenticated user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/github_oauth/server.py:83-107 (handler)The handler function for the 'get_user_repositories' tool. It is decorated with @mcp.tool() for registration and implements the logic to retrieve and format the user's GitHub repositories using the GitHub API and the stored access token.@mcp.tool() async def get_user_repositories() -> str: """Fetch the repositories of the authenticated user.""" global access_token if not access_token: return "You are not authorized. Please authorize first." url = f"{GITHUB_API_BASE}/user/repos" headers = { "Authorization": f"Bearer {access_token}", "User-Agent": USER_AGENT, "Accept": "application/vnd.github.v3+json", } data = await make_request(url, headers) if not data: return "Unable to fetch repositories." if isinstance(data, list): repos = [] for repo in data: repos.append(f"Name: {repo['name']}, URL: {repo['html_url']}, Language: {repo.get('language', 'Unknown')}") return "\n---\n".join(repos) return "No repositories found."
- src/github_oauth/server.py:26-36 (helper)Helper utility function used by get_user_repositories to perform authenticated HTTP requests to the GitHub API.async def make_request(url: str, headers: dict[str, str], params: dict[str, str] = None) -> Optional[dict[str, Any]]: """Make an HTTP GET request with error handling.""" async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, params=params, timeout=30.0) response.raise_for_status() return response.json() except Exception as e: print(f"Request failed: {e}") return None