Skip to main content
Glama
receptopalak

PostGIS MCP Server

by receptopalak

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
NameRequiredDescriptionDefault
distance_kmYesArama mesafesi (km)
latitudeYesMerkez nokta enlem
limitNoMaksimum sonuç sayısı (varsayılan: 10)
longitudeYesMerkez nokta boylam
table_nameYesAranacak tablo adı

Implementation Reference

  • 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),
                    },
                ],
            };
        }
  • 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"],
        },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/receptopalak/postgis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server