Skip to main content
Glama
stefanstranger

mcp-server-vanmoof

get_vanmoof_cities

Retrieve city data from the VanMoof API to access available service locations for riders and their preferences.

Instructions

    Retrieves a list of city data from the vanMoof API.

    Returns:
        The rider vanMoof's city data if authentication is successful, otherwise None.        
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function implementing the get_vanmoof_cities tool. Authenticates using helper methods and makes a GET request to the VanMoof API to retrieve city data. Registered via @mcp.tool() decorator.
    @mcp.tool()
    # Function to get vanMoof Cities
    def get_vanmoof_cities() -> Dict[str, Any]:
        """
        Retrieves a list of city data from the vanMoof API.
    
        Returns:
            The rider vanMoof's city data if authentication is successful, otherwise None.        
        """
        # Get the Bearer token from the authenticate method
        token = VanMoofAPI.get_vanmoof_token(VANMOOF_USERNAME, VANMOOF_PASSWORD)
        application_token = VanMoofAPI.get_application_token(token)
        if not application_token:
            return {"error": "Authentication failed"}
    
        url = "https://tenjin.vanmoof.com/api/v1/cities"
        headers = {
            "authorization": f"Bearer {application_token}",
            "api-key": "fcb38d47-f14b-30cf-843b-26283f6a5819"
        }
        response = requests.get(url, headers=headers)
        return response.json()
  • Helper method in VanMoofAPI class to obtain the initial VanMoof access token using basic auth.
    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
  • Helper method in VanMoofAPI class to exchange the access token for an application token required for API calls.
    def get_application_token(token):
        """
        Authenticates with the VanMoof API and retrieves an application token.
    
        Args:
            token: The user's VanMoof access token.
    
        Returns:
            The application token string if authentication is successful, otherwise None.
        """
        api_key = 'fcb38d47-f14b-30cf-843b-26283f6a5819'
        uri_prefix = 'https://api.vanmoof-api.com/v8'
        auth_url = f'{uri_prefix}/getApplicationToken'
    
        headers = {
            'authorization': f'Bearer {token}',
            "accept": "*/*",
            "user-agent": "VanMoof-Rider/23.7 (sdk_gphone_x86_arm, Android 11)",
            'api-key': api_key
        }
    
        try:
            response = requests.get(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
            application_token = response.json()
            return application_token.get('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
  • Related tool/helper to get customer data, which is used in other tools but called within the cities handler indirectly.
    @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()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/stefanstranger/mcp-server-vanmoof'

If you have feedback or need assistance with the MCP directory API, please join our Discord server