Skip to main content
Glama
ronantakizawa

GIS Data Conversion MCP

geojson_to_csv

Convert GeoJSON geographic data to CSV format for analysis in spreadsheet applications. Include all feature properties or customize the output.

Instructions

Convert GeoJSON to CSV format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
geojsonYesGeoJSON object to convert
includeAllPropertiesNoInclude all feature properties in the CSV

Implementation Reference

  • The primary handler function for the 'geojson_to_csv' tool. Converts GeoJSON FeatureCollection to CSV by extracting latitude/longitude from geometries (using centroids for non-points) and all feature properties.
    async geojsonToCSV(args: any): Promise<ToolResponse> {
      const { geojson, includeAllProperties = true } = args;
    
      if (!geojson || !geojson.features) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid GeoJSON: missing features array'
        );
      }
    
      try {
        console.error('[Converting] GeoJSON to CSV');
        
        // Extract all unique property keys
        const properties = new Set<string>();
        geojson.features.forEach((feature: any) => {
          if (feature.properties) {
            Object.keys(feature.properties).forEach(key => properties.add(key));
          }
        });
        
        // Always include geometry columns
        const headers = ['latitude', 'longitude', ...Array.from(properties)];
        
        // Generate CSV rows
        let csvRows = [headers.join(',')];
        
        geojson.features.forEach((feature: any) => {
          // Extract coordinates (handling different geometry types)
          let lat: number | string = '';
          let lon: number | string = '';
          
          if (feature.geometry.type === 'Point') {
            [lon, lat] = feature.geometry.coordinates;
          } else if (feature.geometry.type === 'Polygon') {
            const centroid = this.getCentroid(feature.geometry.coordinates[0]);
            lon = centroid[0];
            lat = centroid[1];
          } else if (feature.geometry.type === 'LineString' || feature.geometry.type === 'MultiPoint') {
            // Use first coordinate for these types
            [lon, lat] = feature.geometry.coordinates[0];
          } else if (feature.geometry.type === 'MultiPolygon') {
            // Use the centroid of the first polygon
            const centroid = this.getCentroid(feature.geometry.coordinates[0][0]);
            lon = centroid[0];
            lat = centroid[1];
          } else if (feature.geometry.type === 'MultiLineString') {
            // Use the first point of the first linestring
            [lon, lat] = feature.geometry.coordinates[0][0];
          } else if (feature.geometry.type === 'GeometryCollection') {
            // Use the first geometry
            if (feature.geometry.geometries && feature.geometry.geometries.length > 0) {
              const firstGeom = feature.geometry.geometries[0];
              if (firstGeom.type === 'Point') {
                [lon, lat] = firstGeom.coordinates;
              } else if (firstGeom.type === 'Polygon') {
                const centroid = this.getCentroid(firstGeom.coordinates[0]);
                lon = centroid[0];
                lat = centroid[1];
              }
            }
          }
          
          // Convert coordinates to strings for CSV
          const latStr = String(lat);
          const lonStr = String(lon);
          
          // Build row with all properties
          const row = [latStr, lonStr];
          properties.forEach(prop => {
            const value = feature.properties && feature.properties[prop] !== undefined ? 
              feature.properties[prop] : '';
            // Make sure strings with commas are properly quoted
            row.push(typeof value === 'string' ? `"${value.replace(/"/g, '""')}"` : value);
          });
          
          csvRows.push(row.join(','));
        });
        
        return this.formatToolResponse(csvRows.join('\n'));
      } catch (error) {
        console.error('[Error] GeoJSON to CSV conversion failed:', error);
        throw new McpError(
          ErrorCode.InternalError,
          `GeoJSON to CSV conversion failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • src/index.ts:146-164 (registration)
    Registration of the 'geojson_to_csv' tool in the ListTools response, including name, description, and input schema definition.
    {
      name: 'geojson_to_csv',
      description: 'Convert GeoJSON to CSV format',
      inputSchema: {
        type: 'object',
        properties: {
          geojson: {
            type: 'object',
            description: 'GeoJSON object to convert',
          },
          includeAllProperties: {
            type: 'boolean',
            description: 'Include all feature properties in the CSV',
            default: true,
          },
        },
        required: ['geojson'],
      },
    },
  • src/index.ts:286-287 (registration)
    Switch case in CallToolRequest handler that dispatches 'geojson_to_csv' calls to the geojsonToCSV handler method.
    case 'geojson_to_csv':
      return await this.geojsonToCSV(request.params.arguments);
  • Helper function to compute the centroid of a polygon or ring of points, used in geojsonToCSV for non-Point geometries.
    private getCentroid(points: number[][]): number[] {
      const n = points.length;
      let sumX = 0;
      let sumY = 0;
      
      for (let i = 0; i < n; i++) {
        sumX += points[i][0];
        sumY += points[i][1];
      }
      
      return [sumX / n, sumY / n];
    }
  • General helper to format tool responses as required by MCP SDK, used by geojsonToCSV.
    private formatToolResponse(text: string): ToolResponse {
      return {
        content: [
          {
            type: 'text',
            text
          },
        ],
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the conversion action but lacks details on error handling, performance, output structure, or limitations (e.g., handling of complex geometries). For a data transformation tool with zero annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 the complexity of GeoJSON-to-CSV conversion (handling nested objects, geometry types, etc.), no annotations, and no output schema, the description is inadequate. It doesn't explain what the CSV output looks like (e.g., how geometries are represented), potential data loss, or usage constraints, leaving critical gaps for the 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 both parameters ('geojson' and 'includeAllProperties') with descriptions and defaults. The description adds no additional parameter semantics beyond what's in the schema, resulting in the baseline score of 3.

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's function with a specific verb ('Convert') and resource ('GeoJSON to CSV format'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'csv_to_geojson' or 'geojson_to_kml' beyond the output format, which prevents 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 siblings like 'csv_to_geojson' (reverse conversion) and 'geojson_to_kml' (different output format), there's no indication of context, prerequisites, or exclusions, leaving the agent to infer usage based on the name alone.

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

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/ronantakizawa/gis-dataconvertersion-mcp'

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