Skip to main content
Glama

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
NameRequiredDescriptionDefault
kmlYesKML content to convert

Implementation Reference

  • 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)}` ); } }
  • 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'], }, },
  • 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';

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