get_user_profile
Retrieve authenticated GitHub user profile data to access account information and verify identity for authorized API interactions.
Instructions
Fetch the authenticated user's GitHub profile.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_user_profile"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/github_oauth/server.py:110-135 (handler)The handler function for the 'get_user_profile' tool. It checks for an access token, makes a request to the GitHub /user endpoint, and returns a formatted string with the user's profile details including username, name, email, repos, followers, etc.
@mcp.tool() async def get_user_profile() -> str: """Fetch the authenticated user's GitHub profile.""" global access_token if not access_token: return "You are not authorized. Please authorize first." url = f"{GITHUB_API_BASE}/user" headers = { "Authorization": f"Bearer {access_token}", "User-Agent": USER_AGENT, } data = await make_request(url, headers) if not data: return "Unable to fetch user profile." return ( f"Username: {data.get('login', 'N/A')}\n" f"Name: {data.get('name', 'N/A')}\n" f"Email: {data.get('email', 'N/A')}\n" f"Public Repositories: {data.get('public_repos', 'N/A')}\n" f"Followers: {data.get('followers', 'N/A')}\n" f"Following: {data.get('following', 'N/A')}\n" f"Profile URL: {data.get('html_url', 'N/A')}" ) - src/github_oauth/server.py:26-36 (helper)Helper utility function used by get_user_profile (and others) to perform authenticated HTTP GET 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