Skip to main content
Glama

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

Implementation Reference

  • 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'], }, },
  • 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);
  • Import of the external library providing the core KML to GeoJSON conversion function used in the handler.
    import { kml as kmlToGeoJSON } from '@tmcw/togeojson';

Other Tools

Related 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