Skip to main content
Glama
receptopalak

PostGIS MCP Server

by receptopalak

spatial-join

Perform spatial joins between two tables using specified geometry columns and join types such as intersects, within, contains, or touches. Ideal for analyzing spatial relationships in PostGIS databases via the MCP server.

Instructions

İki tablo arasında mekansal join işlemi yap

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
geometry_column1NoTablo1 geometri kolonu (varsayılan: geom)
geometry_column2NoTablo2 geometri kolonu (varsayılan: geom)
join_typeYesJoin tipi
limitNoSonuç limiti (varsayılan: 100)
table1YesBirinci tablo adı
table2Yesİkinci tablo adı

Implementation Reference

  • Handler function for the 'spatial-join' tool. Parses input using SpatialJoinSchema, sanitizes table and column names, selects appropriate PostGIS spatial predicate based on join_type, executes a JOIN query between two tables, and returns results with GeoJSON geometries.
    case "spatial-join": {
      const {
        table1,
        table2,
        join_type,
        geometry_column1,
        geometry_column2,
        limit,
      } = SpatialJoinSchema.parse(args);
    
      const sanitizedTable1 = table1.replace(/[^a-zA-Z0-9_]/g, "");
      const sanitizedTable2 = table2.replace(/[^a-zA-Z0-9_]/g, "");
      const sanitizedGeomCol1 = geometry_column1 || "geom";
      const sanitizedGeomCol2 = geometry_column2 || "geom";
    
      const spatialPredicate = {
        intersects: "ST_Intersects",
        within: "ST_Within",
        contains: "ST_Contains",
        touches: "ST_Touches",
      }[join_type];
    
      const result = await client.query(
        `
        SELECT 
          t1.*,
          t2.*,
          ST_AsGeoJSON(t1.${sanitizedGeomCol1}) as t1_geometry,
          ST_AsGeoJSON(t2.${sanitizedGeomCol2}) as t2_geometry
        FROM ${sanitizedTable1} t1
        JOIN ${sanitizedTable2} t2 ON ${spatialPredicate}(t1.${sanitizedGeomCol1}, t2.${sanitizedGeomCol2})
        LIMIT $1;
      `,
        [limit]
      );
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                table1: sanitizedTable1,
                table2: sanitizedTable2,
                join_type: join_type,
                spatial_predicate: spatialPredicate,
                results_count: result.rows.length,
                results: result.rows,
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • Zod schema defining the input parameters for the spatial-join tool, including two tables, join type, optional geometry columns, and result limit.
    const SpatialJoinSchema = z.object({
      table1: z.string(),
      table2: z.string(),
      join_type: z.enum(["intersects", "within", "contains", "touches"]),
      geometry_column1: z.string().optional().default("geom"),
      geometry_column2: z.string().optional().default("geom"),
      limit: z.number().optional().default(100),
    });
  • server.ts:873-900 (registration)
    Registration of the 'spatial-join' tool in the ListToolsRequestSchema handler, providing name, description, and input schema matching SpatialJoinSchema.
      name: "spatial-join",
      description: "İki tablo arasında mekansal join işlemi yap",
      inputSchema: {
        type: "object",
        properties: {
          table1: { type: "string", description: "Birinci tablo adı" },
          table2: { type: "string", description: "İkinci tablo adı" },
          join_type: {
            type: "string",
            enum: ["intersects", "within", "contains", "touches"],
            description: "Join tipi",
          },
          geometry_column1: {
            type: "string",
            description: "Tablo1 geometri kolonu (varsayılan: geom)",
          },
          geometry_column2: {
            type: "string",
            description: "Tablo2 geometri kolonu (varsayılan: geom)",
          },
          limit: {
            type: "number",
            description: "Sonuç limiti (varsayılan: 100)",
          },
        },
        required: ["table1", "table2", "join_type"],
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions a 'spatial join operation' but doesn't disclose behavioral traits like whether it modifies data, requires specific permissions, has rate limits, returns geometry columns, or handles large datasets. For a tool with 6 parameters and no annotations, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence in Turkish ('İki tablo arasında mekansal join işlemi yap'), which is appropriately concise. However, it lacks front-loading of critical details (e.g., purpose in English, key constraints) and could be more structured for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and 6 parameters, the description is incomplete. It doesn't explain what the tool returns, how results are structured, or any behavioral context. For a spatial operation tool with complexity, this leaves significant gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional meaning about parameters beyond implying two tables are involved. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs a 'spatial join operation between two tables' (verb+resource), which is specific and understandable. However, it doesn't differentiate from sibling tools like 'geometry-intersection' or 'find-nearby' that might have overlapping spatial functionality, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With many spatial siblings (e.g., 'geometry-intersection', 'find-nearby'), there's no indication of when this spatial join is preferred or what specific problems it solves compared to other tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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