topojson_to_geojson
Convert TopoJSON files to GeoJSON format using this GIS Data Conversion MCP tool. Specify the TopoJSON object and optional object name for accurate transformation into standard GeoJSON.
Instructions
Convert TopoJSON to GeoJSON format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| objectName | No | Name of the TopoJSON object to convert (if not provided, first object is used) | |
| topojson | Yes | TopoJSON object to convert |
Implementation Reference
- src/index.ts:541-577 (handler)The main handler function that performs the TopoJSON to GeoJSON conversion using the topojsonClient.feature method. Handles input validation, object selection, conversion, and error handling.async topojsonToGeoJSON(args: any): Promise<ToolResponse> { const { topojson, objectName } = args; if (!topojson) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameter: topojson' ); } try { console.error('[Converting] TopoJSON to GeoJSON'); // Determine which object to convert let objName = objectName; // If no object name provided, use the first object in the topology if (!objName && topojson.objects) { objName = Object.keys(topojson.objects)[0]; } if (!objName || !topojson.objects || !topojson.objects[objName]) { throw new Error('No valid object found in TopoJSON'); } // Convert TopoJSON to GeoJSON const geojson = topojsonClient.feature(topojson, topojson.objects[objName]); return this.formatToolResponse(JSON.stringify(geojson, null, 2)); } catch (error) { console.error('[Error] TopoJSON to GeoJSON conversion failed:', error); throw new McpError( ErrorCode.InternalError, `TopoJSON to GeoJSON conversion failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:192-204 (schema)Input schema defining the expected parameters: topojson (required object) and optional objectName (string).inputSchema: { type: 'object', properties: { topojson: { type: 'object', description: 'TopoJSON object to convert', }, objectName: { type: 'string', description: 'Name of the TopoJSON object to convert (if not provided, first object is used)', }, }, required: ['topojson'],
- src/index.ts:189-206 (registration)Tool registration in the ListTools response, including name, description, and input schema.{ name: 'topojson_to_geojson', description: 'Convert TopoJSON to GeoJSON format', inputSchema: { type: 'object', properties: { topojson: { type: 'object', description: 'TopoJSON object to convert', }, objectName: { type: 'string', description: 'Name of the TopoJSON object to convert (if not provided, first object is used)', }, }, required: ['topojson'], }, },
- src/index.ts:290-291 (registration)Dispatcher case in CallToolRequest handler that routes to the topojsonToGeoJSON method.case 'topojson_to_geojson': return await this.topojsonToGeoJSON(request.params.arguments);