get_user_info
Retrieve Slack user information by searching with a display name or real name to identify team members and access their profile details.
Instructions
Get Slack user info by username or real name.
Args:
username: Slack display name or real name (not user ID).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes |
Implementation Reference
- main.py:57-94 (handler)The handler function for the 'get_user_info' MCP tool. It is decorated with @mcp.tool() for automatic registration and schema inference. Retrieves Slack user information by searching for username or real name.@mcp.tool() async def get_user_info(username: str) -> str: """ Get Slack user info by username or real name. Args: username: Slack display name or real name (not user ID). """ # Step 1: Get list of all users users_data = await make_slack_request("users.list") if not users_data or not users_data.get("ok"): return "❌ Failed to fetch user list." # Step 2: Search for the user user_id = None for user in users_data["members"]: if user.get("name") == username or user.get("real_name") == username: user_id = user["id"] break if not user_id: return f"❌ User '{username}' not found." # Step 3: Use user_id to get full user info params = {"user": user_id} data = await make_slack_request("users.info", params) if not data or not data.get("ok"): return "❌ Failed to fetch user info." user = data.get("user", {}) profile = user.get("profile", {}) return ( f"👤 Username: {user.get('name')}\n" f"🧾 Real Name: {user.get('real_name')}\n" f"📧 Email: {profile.get('email', 'N/A')}\n" f"🆔 ID: {user_id}" )
- main.py:19-33 (helper)Shared helper utility function used by get_user_info to make authenticated HTTP requests to the Slack API endpoints.async def make_slack_request(method: str, params: dict[str, Any] | None = None) -> dict[str, Any] | None: """Make a request to the Slack Web API with proper error handling.""" headers = { "Authorization": f"Bearer {SLACK_TOKEN}", "Content-Type": "application/x-www-form-urlencoded" } async with httpx.AsyncClient() as client: try: response = await client.post(f"{SLACK_API_BASE}/{method}", data=params, headers=headers, timeout=10.0) response.raise_for_status() return response.json() except Exception as e: print(f"Slack API error: {e}") return None
- main.py:57-57 (registration)The @mcp.tool() decorator registers the get_user_info function as an MCP tool.@mcp.tool()
- main.py:58-64 (schema)Function signature and docstring defining the tool's input schema (username: str) and output (str).async def get_user_info(username: str) -> str: """ Get Slack user info by username or real name. Args: username: Slack display name or real name (not user ID). """