township-mcp-server / p_tool_nearby.py
puseletso55's picture
Create p_tool_nearby.py
d64d3bb verified
raw
history blame contribute delete
642 Bytes
import json
from langchain.tools import Tool
import requests
def call_mcp(method, params):
req = {
"jsonrpc": "2.0",
"id": 1,
"method": method,
"params": params
}
r = requests.post(
"https://puseletso55-township-mcp-server.hf.space/run/predict",
json={"data": [json.dumps(req)]}
)
return json.loads(r.json()["data"][0])
nearby_tool = Tool.from_function(
name="getNearbyBusinesses",
description="Finds businesses within 10km of a location. Use this to find spaza shops or services nearby.",
func=lambda loc: call_mcp("getNearbyBusinesses", {"location": loc})
)