get_profile
Retrieve user profile information using a handle or the authenticated user's data. Returns detailed profile data for Bluesky Social MCP users.
Instructions
Get a user profile.
Args:
ctx: MCP context
handle: Optional handle to get profile for. If None, gets the authenticated user
Returns:
Profile data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| handle | No |
Implementation Reference
- server.py:131-155 (handler)The primary handler function for the 'get_profile' tool. Decorated with @mcp.tool() which also registers it with the MCP server. Retrieves the profile of a specified handle or the authenticated user's profile using the Bluesky client.@mcp.tool() def get_profile(ctx: Context, handle: Optional[str] = None) -> Dict: """Get a user profile. Args: ctx: MCP context handle: Optional handle to get profile for. If None, gets the authenticated user Returns: Profile data """ try: bluesky_client = get_authenticated_client(ctx) # If no handle provided, get authenticated user's profile if not handle: handle = bluesky_client.me.handle profile_response = bluesky_client.get_profile(handle) profile = profile_response.dict() return {"status": "success", "profile": profile} except Exception as e: error_msg = f"Failed to get profile: {str(e)}" return {"status": "error", "message": error_msg}
- server.py:49-77 (helper)Helper function used by get_profile (and other tools) to obtain an authenticated Bluesky Client instance.def get_authenticated_client(ctx: Context) -> Client: """Get an authenticated client, creating it lazily if needed. Args: ctx: MCP context Returns: Authenticated Client instance Raises: ValueError: If credentials are not available """ app_context = ctx.request_context.lifespan_context # If we already have a client, return it if app_context.bluesky_client is not None: return app_context.bluesky_client # Try to create a new client by calling login again client = login() if client is None: raise ValueError( "Authentication required but credentials not available. " "Please set BLUESKY_IDENTIFIER and BLUESKY_APP_PASSWORD environment variables." ) # Store it in the context for future use app_context.bluesky_client = client return client
- server.py:22-46 (helper)Underlying helper function that performs the actual login to create the Bluesky Client, called by get_authenticated_client.def login() -> Optional[Client]: """Login to Bluesky API and return the client. Authenticates using environment variables: - BLUESKY_IDENTIFIER: The handle (username) - BLUESKY_APP_PASSWORD: The app password - BLUESKY_SERVICE_URL: The service URL (defaults to "https://bsky.social") Returns: Authenticated Client instance or None if credentials are not available """ handle = os.environ.get("BLUESKY_IDENTIFIER") password = os.environ.get("BLUESKY_APP_PASSWORD") service_url = os.environ.get("BLUESKY_SERVICE_URL", "https://bsky.social") if not handle or not password: return None # This is helpful for debugging. # print(f"LOGIN {handle=} {service_url=}", file=sys.stderr) # Create and authenticate client client = Client(service_url) client.login(handle, password) return client