get_authorization_url
Generate an OAuth2 authorization URL to authenticate users with Withings Health API for accessing body measurements, activity data, and health metrics.
Instructions
Get OAuth2 authorization URL to authenticate with Withings
Input Schema
TableJSON 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
- src/withings_mcp_server/auth.py:41-51 (handler)Core implementation of the get_authorization_url tool. Constructs the OAuth2 authorization URL using client credentials and provided scope.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:164-177 (registration)Registers the get_authorization_url tool with MCP server including input schema for optional scope 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", }, }, }, ),
- MCP tool call handler that extracts scope from arguments, calls the auth method, and formats the response as TextContent.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.", ) ]