fetch_my_locations
Retrieve location data from Obenan API using an access token, with optional filtering by group ID for targeted results.
Instructions
Fetch locations from Obenan API using the access token
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| access_token | No | Access token for Obenan API. Optional if OBENAN_LOGIN_ACCESS_TOKEN environment variable is set. | |
| group_id | No | Group ID to filter locations by. Optional. |
Implementation Reference
- src/obenan_mcp_server/server.py:97-166 (handler)The handle_fetch_locations function implements the logic to fetch and format locations from the Obenan API for the 'fetch_my_locations' tool.
async def handle_fetch_locations( arguments: dict[str, Any] | None ) -> list[types.TextContent]: # Get token from environment variable or from arguments import os access_token = os.environ.get("OBENAN_LOGIN_ACCESS_TOKEN") # Add debug info about the token (just showing first/last few characters for security) token_debug = "" if access_token: if len(access_token) > 10: token_debug = f"{access_token[:5]}...{access_token[-5:]}" else: token_debug = "[too short to truncate safely]" else: token_debug = "[None - Token not found]" try: # Direct API call with simplified URL url = "https://stagingapi.obenan.com/api/v1/location/search?isLocationPage=false&isListingPage=true" headers = {"Authorization": f"Bearer {access_token}"} response = requests.get(url, headers=headers) if response.status_code == 200: data = response.json() # Simple output format focusing just on location names formatted_response = f"✅ Location Names: (Token: {token_debug})\n\n" # Check for data.results path if data and isinstance(data, dict) and "data" in data: if isinstance(data["data"], dict) and "results" in data["data"]: locations = data["data"]["results"] if locations and isinstance(locations, list): for i, loc in enumerate(locations): name = loc.get("name", "Unknown") formatted_response += f"{i+1}. {name}\n" else: formatted_response += "No locations found in results.\n" else: formatted_response += "Results field not found in data structure.\n" else: formatted_response += "No data field found in response.\n" # Add response debug info formatted_response += f"\n===DEBUG INFO===\n" formatted_response += f"Response Keys: {list(data.keys()) if isinstance(data, dict) else 'Not a dict'}\n" if isinstance(data, dict) and "data" in data: data_keys = list(data["data"].keys()) if isinstance(data["data"], dict) else "Not a dict" formatted_response += f"Data Keys: {data_keys}\n" if isinstance(data["data"], dict) and "results" in data["data"]: location_count = len(data["data"]["results"]) if isinstance(data["data"]["results"], list) else 0 formatted_response += f"Location Count: {location_count}\n" return [types.TextContent(type="text", text=formatted_response)] else: error_msg = f"❌ Failed to fetch locations: HTTP {response.status_code}\n{response.text[:500]}" return [types.TextContent(type="text", text=error_msg)] except Exception as e: error_trace = traceback.format_exc() return [types.TextContent( type="text", text=f"🚨 Error fetching locations: {str(e)}\n\n{error_trace[:500]}" )] - src/obenan_mcp_server/server.py:27-38 (registration)The 'fetch_my_locations' tool is defined and registered within the list_tools() function.
types.Tool( name="fetch_my_locations", description="Fetch locations from Obenan API using the access token", inputSchema={ "type": "object", "properties": { "access_token": {"type": "string", "description": "Access token for Obenan API. Optional if OBENAN_LOGIN_ACCESS_TOKEN environment variable is set."}, "group_id": {"type": "string", "description": "Group ID to filter locations by. Optional."} }, "required": [] }, ),