Add nearest_nodes tool for coordinate-based node search
This commit is contained in:
Submodule backends/geo updated: 5f040426a2...5d5e0fa4b5
@@ -100,7 +100,25 @@ def build_tools(mcp: McpInvoker):
|
||||
},
|
||||
)
|
||||
|
||||
return [search_products, search_offers, match_offers_with_route, order_timeline, search_nodes]
|
||||
@tool
|
||||
def nearest_nodes(
|
||||
lat: float,
|
||||
lon: float,
|
||||
limit: int = 5,
|
||||
user_token: str | None = None,
|
||||
) -> Any:
|
||||
"""Find nearest logistics nodes to given coordinates. Use this when search_nodes by city name returns no results - provide approximate coordinates instead (e.g. Nairobi is roughly -1.29, 36.82)."""
|
||||
return mcp.call(
|
||||
"nearest_nodes",
|
||||
{
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
"limit": limit,
|
||||
"userToken": user_token,
|
||||
},
|
||||
)
|
||||
|
||||
return [search_products, search_offers, match_offers_with_route, order_timeline, search_nodes, nearest_nodes]
|
||||
|
||||
|
||||
def build_graph():
|
||||
|
||||
@@ -251,6 +251,56 @@ server.registerTool(
|
||||
}
|
||||
);
|
||||
|
||||
// Tool: nearest_nodes (GEO - find nodes by coordinates)
|
||||
server.registerTool(
|
||||
"nearest_nodes",
|
||||
{
|
||||
title: "Nearest Nodes",
|
||||
description: "Find nearest logistics nodes to given coordinates. Use this when searching by city name returns no results - provide approximate coordinates instead.",
|
||||
inputSchema: {
|
||||
lat: z.number().describe("Latitude of the location"),
|
||||
lon: z.number().describe("Longitude of the location"),
|
||||
limit: z.number().optional().default(5).describe("Max number of results"),
|
||||
userToken: z.string().optional().describe("Optional Bearer token"),
|
||||
},
|
||||
},
|
||||
async ({ lat, lon, limit = 5, userToken }) => {
|
||||
const geoUrl = process.env.GEO_GRAPHQL_URL;
|
||||
if (!geoUrl) {
|
||||
throw new Error("GEO_GRAPHQL_URL is not set.");
|
||||
}
|
||||
|
||||
const token = resolveToken({
|
||||
userToken,
|
||||
serviceTokenEnv: "GEO_M2M_TOKEN",
|
||||
required: false,
|
||||
});
|
||||
|
||||
const gqlQuery = `
|
||||
query NearestNodes($lat: Float!, $lon: Float!, $limit: Int) {
|
||||
nearestNodes(lat: $lat, lon: $lon, limit: $limit) {
|
||||
uuid
|
||||
name
|
||||
latitude
|
||||
longitude
|
||||
country
|
||||
countryCode
|
||||
transportTypes
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const data = await gqlRequest(
|
||||
geoUrl,
|
||||
gqlQuery,
|
||||
{ lat, lon, limit },
|
||||
token
|
||||
);
|
||||
|
||||
return { content: [{ type: "text", text: JSON.stringify(data.nearestNodes ?? [], null, 2) }] };
|
||||
}
|
||||
);
|
||||
|
||||
// Tool: order_timeline (orders service)
|
||||
server.registerTool(
|
||||
"order_timeline",
|
||||
|
||||
Reference in New Issue
Block a user