get_customer_data
Retrieve authenticated customer data including bike details, rider preferences, and weekly rides from the VanMoof API for integration with AI agents.
Instructions
Retrieves customer data from the vanMoof API.
Returns:
The rider vanMoof's customer data if authentication is successful, otherwise None.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:115-135 (handler)The core handler implementation for the 'get_customer_data' MCP tool. Decorated with @mcp.tool() for automatic registration. Authenticates using helper method and fetches customer data from the VanMoof API.@mcp.tool() # Function to get customer data def get_customer_data() -> Dict[str, Any]: """ Retrieves customer data from the vanMoof API. Returns: The rider vanMoof's customer data if authentication is successful, otherwise None. """ # Get the Bearer token from the authenticate method token = VanMoofAPI.get_vanmoof_token(VANMOOF_USERNAME, VANMOOF_PASSWORD) if not token: return {"error": "Authentication failed"} url = "https://my.vanmoof.com/api/v8/getCustomerData" headers = { "authorization": f"Bearer {token}", "api-key": "fcb38d47-f14b-30cf-843b-26283f6a5819" } response = requests.get(url, headers=headers) return response.json()
- server.py:40-77 (helper)Supporting helper method 'get_vanmoof_token' in VanMoofAPI class, called by the tool handler to authenticate and obtain the Bearer token required for the API request.def get_vanmoof_token(username, password): """ Authenticates with the VanMoof API and retrieves an access token. Args: username: The user's VanMoof email address. password: The user's VanMoof password. Returns: The access token string if authentication is successful, otherwise None. """ api_key = 'fcb38d47-f14b-30cf-843b-26283f6a5819' uri_prefix = 'https://my.vanmoof.com/api/v8' auth_url = f'{uri_prefix}/authenticate' # Prepare Basic Authentication credentials auth_string = f"{username}:{password}" encoded_auth_string = base64.b64encode(auth_string.encode('ascii')).decode('ascii') headers = { 'Authorization': f'Basic {encoded_auth_string}', 'Api-Key': api_key } try: response = requests.post(auth_url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) # Parse the JSON response and extract the token token = response.json().get('token') return token except requests.exceptions.RequestException as e: print(f"An error occurred during the API request: {e}") return None except Exception as e: print(f"An unexpected error occurred: {e}") return None
- server.py:115-115 (registration)The @mcp.tool() decorator registers the get_customer_data function as an MCP tool.@mcp.tool()