Skip to main content
Glama

csv_to_geojson

Convert CSV files containing geographic coordinates into GeoJSON format for mapping and spatial analysis by specifying latitude and longitude fields.

Instructions

Convert CSV with geographic data to GeoJSON

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
csvYesCSV string to convert
latfieldYesField name for latitude
lonfieldYesField name for longitude
delimiterNoCSV delimiter (default is comma),

Implementation Reference

  • The handler function csvToGeoJSON that performs the CSV to GeoJSON conversion using the csv2geojson library. It takes CSV string, latitude and longitude field names, optional delimiter, validates inputs, calls the library's csv2geojson function, and returns formatted GeoJSON.
    async csvToGeoJSON(args: any): Promise<ToolResponse> { const { csv, latfield, lonfield, delimiter = ',' } = args; if (!csv || !latfield || !lonfield) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameters: csv, latfield, lonfield' ); } return new Promise<ToolResponse>((resolve, reject) => { try { console.error(`[Converting] CSV to GeoJSON using lat field ${latfield} and lon field ${lonfield}`); csv2geojson.csv2geojson(csv, { latfield, lonfield, delimiter }, (err: Error | null, data: any) => { if (err) { console.error('[Error] CSV to GeoJSON conversion failed:', err); reject(new McpError( ErrorCode.InternalError, `CSV to GeoJSON conversion failed: ${err.message}` )); return; } resolve(this.formatToolResponse(JSON.stringify(data, null, 2))); }); } catch (error) { console.error('[Error] CSV to GeoJSON conversion failed:', error); reject(new McpError( ErrorCode.InternalError, `CSV to GeoJSON conversion failed: ${error instanceof Error ? error.message : String(error)}` )); } }); }
  • Tool registration in listTools response including name, description, and inputSchema defining parameters: csv (string, required), latfield (string, required), lonfield (string, required), delimiter (string, optional default ',').
    name: 'csv_to_geojson', description: 'Convert CSV with geographic data to GeoJSON', inputSchema: { type: 'object', properties: { csv: { type: 'string', description: 'CSV string to convert', }, latfield: { type: 'string', description: 'Field name for latitude', }, lonfield: { type: 'string', description: 'Field name for longitude', }, delimiter: { type: 'string', description: 'CSV delimiter (default is comma)', default: ',', }, }, required: ['csv', 'latfield', 'lonfield'],
  • src/index.ts:284-285 (registration)
    Dispatcher switch case in CallToolRequest handler that routes 'csv_to_geojson' calls to the csvToGeoJSON method.
    case 'csv_to_geojson': return await this.csvToGeoJSON(request.params.arguments);

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