kml_to_geojson
Convert KML geographic data to GeoJSON format for use in web mapping applications and GIS software. This tool transforms KML content into the widely supported GeoJSON standard.
Instructions
Convert KML to GeoJSON format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kml | Yes | KML content to convert |
Implementation Reference
- src/index.ts:579-607 (handler)The handler function that validates input, parses the KML string into an XML document using DOMParser, converts it to GeoJSON using the imported kmlToGeoJSON function, and returns the formatted response.async kmlToGeoJSON(args: any): Promise<ToolResponse> { const { kml } = args; if (!kml) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameter: kml' ); } try { console.error('[Converting] KML to GeoJSON'); // Parse KML string to XML DOM const parser = new DOMParser(); const kmlDoc = parser.parseFromString(kml, 'text/xml'); // Convert KML to GeoJSON const geojson = kmlToGeoJSON(kmlDoc); return this.formatToolResponse(JSON.stringify(geojson, null, 2)); } catch (error) { console.error('[Error] KML to GeoJSON conversion failed:', error); throw new McpError( ErrorCode.InternalError, `KML to GeoJSON conversion failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:210-219 (schema)Input schema definition for the kml_to_geojson tool, requiring a 'kml' string parameter.inputSchema: { type: 'object', properties: { kml: { type: 'string', description: 'KML content to convert', }, }, required: ['kml'], },
- src/index.ts:292-293 (registration)Tool dispatcher registration that maps the 'kml_to_geojson' name to the kmlToGeoJSON handler method.case 'kml_to_geojson': return await this.kmlToGeoJSON(request.params.arguments);
- src/index.ts:207-220 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ name: 'kml_to_geojson', description: 'Convert KML to GeoJSON format', inputSchema: { type: 'object', properties: { kml: { type: 'string', description: 'KML content to convert', }, }, required: ['kml'], }, },
- src/index.ts:20-20 (helper)Import of the core kml conversion function from the togeojson library, aliased as kmlToGeoJSON and used in the handler.import { kml as kmlToGeoJSON } from '@tmcw/togeojson';