kml_to_geojson
Transform KML data into GeoJSON format for use in GIS applications. This tool enables conversion of geographic data, facilitating compatibility and integration across platforms.
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 for the kml_to_geojson tool. It validates input, parses the KML string into XML using DOMParser, converts it to GeoJSON using the imported kmlToGeoJSON function from @tmcw/togeojson, formats the response, and handles errors.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:207-220 (registration)Registration of the kml_to_geojson tool in the ListToolsRequestSchema handler, 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:210-219 (schema)Input schema for the kml_to_geojson tool, specifying the required 'kml' string parameter.inputSchema: { type: 'object', properties: { kml: { type: 'string', description: 'KML content to convert', }, }, required: ['kml'], },
- src/index.ts:292-293 (registration)Dispatcher case in the CallToolRequestSchema handler that routes to the kmlToGeoJSON method.case 'kml_to_geojson': return await this.kmlToGeoJSON(request.params.arguments);
- src/index.ts:20-20 (helper)Import of the external library providing the core KML to GeoJSON conversion function used in the handler.import { kml as kmlToGeoJSON } from '@tmcw/togeojson';