get_authorization_url
Get an OAuth2 authorization URL to authenticate users with Withings, granting access to health data such as body measurements, activity, and sleep analysis.
Instructions
Get OAuth2 authorization URL to authenticate with Withings
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scope | No | OAuth scopes (comma-separated): user.info, user.metrics, user.activity | user.info,user.metrics,user.activity |
Implementation Reference
- Handler for the get_authorization_url tool: extracts scope from arguments, calls auth.get_authorization_url(), and returns a TextContent response with the URL.
if name == "get_authorization_url": scope = arguments.get("scope", "user.info,user.metrics,user.activity") url = self.auth.get_authorization_url(scope) return [ TextContent( type="text", text=f"Please visit this URL to authorize:\n\n{url}\n\nAfter authorization, you'll receive a code. Use it to get access tokens.", ) ] - Tool registration and input schema definition for get_authorization_url, with an optional 'scope' string parameter.
Tool( name="get_authorization_url", description="Get OAuth2 authorization URL to authenticate with Withings", inputSchema={ "type": "object", "properties": { "scope": { "type": "string", "description": "OAuth scopes (comma-separated): user.info, user.metrics, user.activity", "default": "user.info,user.metrics,user.activity", }, }, }, ), - Helper function on WithingsAuth class that constructs the OAuth2 authorization URL using client_id, redirect_uri, scope, and a static state.
def get_authorization_url(self, scope: str = "user.info,user.metrics,user.activity") -> str: """Generate OAuth2 authorization URL.""" params = { "response_type": "code", "client_id": self.client_id, "redirect_uri": self.redirect_uri, "scope": scope, "state": "random_state_string" } query = "&".join(f"{k}={v}" for k, v in params.items()) return f"{self.AUTH_URL}?{query}" - src/withings_mcp_server/server.py:175-189 (registration)Tool registered in the list_tools() handler as part of the MCP tool listing.
Tool( name="get_authorization_url", description="Get OAuth2 authorization URL to authenticate with Withings", inputSchema={ "type": "object", "properties": { "scope": { "type": "string", "description": "OAuth scopes (comma-separated): user.info, user.metrics, user.activity", "default": "user.info,user.metrics,user.activity", }, }, }, ), ]