Improve: MCP efficiency & fix radius filtering

- Remove bloat fields (shape, objectid, etc), add sequential IDs
- Add lang param (he/en) for Hebrew/English text values
- Reduce JSON whitespace (indent=None)
- Fix distance_meters: extract centroid from WKT shape geometry
- Add search_coordinates to all address-based tool responses
- Fix radius filtering: properly filter deals beyond radius_meters
- Change default radius from 30m to 50m
- Fix get_deal_statistics: return NO deals (stats only)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Nitzan Pomerantz
2025-12-08 09:34:42 +02:00
parent 4de1a4822b
commit b87cb268d5
4 changed files with 368 additions and 117 deletions
+38 -1
View File
@@ -6,7 +6,7 @@ This module provides shared helper functions with no external dependencies
"""
import re
from typing import Tuple
from typing import Optional, Tuple
def calculate_distance(point1: Tuple[float, float], point2: Tuple[float, float]) -> float:
@@ -28,6 +28,43 @@ def calculate_distance(point1: Tuple[float, float], point2: Tuple[float, float])
return (dx * dx + dy * dy) ** 0.5
def extract_shape_centroid(shape_wkt: Optional[str]) -> Optional[Tuple[float, float]]:
"""
Extract centroid coordinates from WKT geometry (MULTIPOLYGON/POLYGON).
Parses WKT string and calculates centroid as average of all coordinate points.
Args:
shape_wkt: WKT geometry string (e.g., "MULTIPOLYGON(...)")
Returns:
(longitude, latitude) tuple in ITM coordinates, or None if parsing fails
"""
if not shape_wkt or not isinstance(shape_wkt, str):
return None
try:
# Extract all coordinate pairs using regex
# Matches: "number.number number.number" or "number number"
coord_pattern = r"([\d.]+)\s+([\d.]+)"
matches = re.findall(coord_pattern, shape_wkt)
if not matches:
return None
# Calculate average (centroid)
lons = [float(m[0]) for m in matches]
lats = [float(m[1]) for m in matches]
centroid_lon = sum(lons) / len(lons)
centroid_lat = sum(lats) / len(lats)
return (centroid_lon, centroid_lat)
except (ValueError, ZeroDivisionError):
return None
def is_same_building(search_address: str, deal_address: str) -> bool:
"""
Check if a deal is from the same building as the search address.