create-spatial-index
Generate spatial indexes for PostGIS database tables to optimize spatial queries. Specify the table name and geometry column to enhance spatial data performance.
Instructions
Mekansal indeks oluştur
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geometry_column | No | Geometri kolonu (varsayılan: geom) | |
| table_name | Yes | Tablo adı |
Implementation Reference
- server.ts:1728-1793 (handler)Handler function for 'create-spatial-index' tool: parses input using SpatialIndexSchema, sanitizes table and column names, creates a GIST spatial index if not exists using SQL CREATE INDEX, queries for index info, returns success or error details.
case "create-spatial-index": { const { table_name, geometry_column } = SpatialIndexSchema.parse(args); const sanitizedTableName = table_name.replace(/[^a-zA-Z0-9_]/g, ""); const sanitizedGeomColumn = geometry_column || "geom"; const indexName = `idx_${sanitizedTableName}_${sanitizedGeomColumn}_gist`; try { await client.query(` CREATE INDEX IF NOT EXISTS ${indexName} ON ${sanitizedTableName} USING GIST (${sanitizedGeomColumn}); `); const indexInfo = await client.query( ` SELECT indexname, indexdef, tablename FROM pg_indexes WHERE indexname = $1; `, [indexName] ); return { content: [ { type: "text", text: JSON.stringify( { table_name: sanitizedTableName, geometry_column: sanitizedGeomColumn, index_name: indexName, index_created: true, index_info: indexInfo.rows[0] || null, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { table_name: sanitizedTableName, geometry_column: sanitizedGeomColumn, index_name: indexName, index_created: false, error: error instanceof Error ? error.message : "Unknown error", }, null, 2 ), }, ], }; } } - server.ts:115-118 (schema)Zod input schema validation for create-spatial-index tool parameters: table_name (required string), geometry_column (optional string, default 'geom').
const SpatialIndexSchema = z.object({ table_name: z.string(), geometry_column: z.string().optional().default("geom"), }); - server.ts:904-918 (registration)Tool registration in ListToolsRequestHandler: defines name 'create-spatial-index', description, and inputSchema matching SpatialIndexSchema.
name: "create-spatial-index", description: "Mekansal indeks oluştur", inputSchema: { type: "object", properties: { table_name: { type: "string", description: "Tablo adı" }, geometry_column: { type: "string", description: "Geometri kolonu (varsayılan: geom)", }, }, required: ["table_name"], }, },