find-nearby
Locate features within a specified distance from a given point using spatial queries. Enter coordinates, distance, and table name to retrieve results from a PostGIS database via the MCP protocol.
Instructions
Belirli bir noktanın çevresindeki özellikleri bul
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| distance_km | Yes | Arama mesafesi (km) | |
| latitude | Yes | Merkez nokta enlem | |
| limit | No | Maksimum sonuç sayısı (varsayılan: 10) | |
| longitude | Yes | Merkez nokta boylam | |
| table_name | Yes | Aranacak tablo adı |
Implementation Reference
- server.js:298-327 (handler)The main handler for the 'find-nearby' tool. It parses input using FindNearbySchema, sanitizes the table name, executes a PostGIS query using ST_DWithin to find nearby geometries within distance_km and ST_Distance to compute distances, orders by distance, limits results, and returns JSON of the rows.case "find-nearby": { const { latitude, longitude, distance_km, table_name, limit } = FindNearbySchema.parse(args); // Tablo adını sanitize et (basit güvenlik) const sanitizedTableName = table_name.replace(/[^a-zA-Z0-9_]/g, ''); const result = yield client.query(` SELECT *, ST_AsGeoJSON(geom) as geometry, ST_Distance( geom, ST_SetSRID(ST_MakePoint($1, $2), 4326)::geography ) / 1000 as distance_km FROM ${sanitizedTableName} WHERE ST_DWithin( geom, ST_SetSRID(ST_MakePoint($1, $2), 4326)::geography, $3 ) ORDER BY distance_km LIMIT $4; `, [longitude, latitude, distance_km * 1000, limit]); return { content: [ { type: "text", text: JSON.stringify(result.rows, null, 2), }, ], }; }
- server.js:33-39 (schema)Zod validation schema for the input parameters of the 'find-nearby' tool.const FindNearbySchema = zod_1.z.object({ latitude: zod_1.z.number(), longitude: zod_1.z.number(), distance_km: zod_1.z.number(), table_name: zod_1.z.string(), limit: zod_1.z.number().optional().default(10), });
- server.js:118-132 (registration)Tool registration entry in the ListTools handler, defining the name, description, and input schema for 'find-nearby'.{ name: "find-nearby", description: "Belirli bir noktanın çevresindeki özellikleri bul", inputSchema: { type: "object", properties: { latitude: { type: "number", description: "Merkez nokta enlem" }, longitude: { type: "number", description: "Merkez nokta boylam" }, distance_km: { type: "number", description: "Arama mesafesi (km)" }, table_name: { type: "string", description: "Aranacak tablo adı" }, limit: { type: "number", description: "Maksimum sonuç sayısı (varsayılan: 10)" }, }, required: ["latitude", "longitude", "distance_km", "table_name"], }, },