Skip to main content
Glama
blake365

Macrostrat MCP Server

by blake365

Latitude/Longitude to Tile

lat-lng-to-tile

Convert geographic coordinates (latitude/longitude) to map tile coordinates (x, y) for specified zoom levels using web mercator projection.

Instructions

Convert latitude/longitude coordinates to map tile coordinates (x, y) for a given zoom level. Uses the same web mercator projection as MapKit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latYesLatitude in decimal degrees (-90 to 90)
lngYesLongitude in decimal degrees (-180 to 180)
zoomYesZoom level (0-18)

Implementation Reference

  • The handler function that performs the core logic: converts latitude/longitude and zoom to tile coordinates (x, y, z) using Web Mercator projection formulas.
    async (request) => {
      const { lat, lng, zoom } = request;
      
      // Proper web mercator tile coordinate calculation (same as MapKit)
      const n = Math.pow(2, zoom);
      const x = Math.floor((lng + 180) / 360 * n);
      
      // Convert latitude to radians
      const lat_rad = lat * Math.PI / 180;
      // Web mercator y calculation
      const y = Math.floor((1 - Math.asinh(Math.tan(lat_rad)) / Math.PI) / 2 * n);
      
      const data = {
        x,
        y,
        z: zoom,
        lat,
        lng,
        zoom,
        note: "Use these x,y coordinates with the map-tiles tool"
      };
    
      return {
        content: [{
          type: "text" as const,
          text: JSON.stringify(data, null, 2)
        }]
      };
    }
  • Zod input schema defining parameters: lat, lng, zoom with validation and descriptions.
    {
      title: "Latitude/Longitude to Tile",
      description: "Convert latitude/longitude coordinates to map tile coordinates (x, y) for a given zoom level. Uses the same web mercator projection as MapKit.",
      inputSchema: {
        lat: z.number().min(-90).max(90).describe("Latitude in decimal degrees (-90 to 90)"),
        lng: z.number().min(-180).max(180).describe("Longitude in decimal degrees (-180 to 180)"),
        zoom: z.number().int().min(0).max(18).describe("Zoom level (0-18)"),
      }
    },
  • src/index.ts:1081-1121 (registration)
    Registration of the 'lat-lng-to-tile' tool with MCP server, including schema and handler.
    server.registerTool(
      "lat-lng-to-tile",
      {
        title: "Latitude/Longitude to Tile",
        description: "Convert latitude/longitude coordinates to map tile coordinates (x, y) for a given zoom level. Uses the same web mercator projection as MapKit.",
        inputSchema: {
          lat: z.number().min(-90).max(90).describe("Latitude in decimal degrees (-90 to 90)"),
          lng: z.number().min(-180).max(180).describe("Longitude in decimal degrees (-180 to 180)"),
          zoom: z.number().int().min(0).max(18).describe("Zoom level (0-18)"),
        }
      },
      async (request) => {
        const { lat, lng, zoom } = request;
        
        // Proper web mercator tile coordinate calculation (same as MapKit)
        const n = Math.pow(2, zoom);
        const x = Math.floor((lng + 180) / 360 * n);
        
        // Convert latitude to radians
        const lat_rad = lat * Math.PI / 180;
        // Web mercator y calculation
        const y = Math.floor((1 - Math.asinh(Math.tan(lat_rad)) / Math.PI) / 2 * n);
        
        const data = {
          x,
          y,
          z: zoom,
          lat,
          lng,
          zoom,
          note: "Use these x,y coordinates with the map-tiles tool"
        };
    
        return {
          content: [{
            type: "text" as const,
            text: JSON.stringify(data, null, 2)
          }]
        };
      }
    );
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the projection method ('web mercator projection as MapKit'), which adds useful technical context beyond basic functionality. However, it doesn't cover error handling, performance characteristics, or output format details, leaving gaps for a tool with no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently conveys the core transformation and key technical detail (projection type). Every word earns its place with zero redundancy or fluff, making it easy to parse front-loaded information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (coordinate conversion with three parameters) and lack of annotations/output schema, the description is minimally adequate. It covers the what and how (projection) but misses guidance on usage, error cases, and output structure, leaving the agent with incomplete operational context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all three parameters (lat, lng, zoom) with ranges and units. The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high coverage but not enhancing understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific verb 'convert' and the resources 'latitude/longitude coordinates to map tile coordinates (x, y)', distinguishing it from sibling tools like 'map-tiles' which likely serve different mapping functions. It provides a precise transformation purpose with technical specificity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'map-tiles' or other coordinate conversion methods. The description lacks context about typical use cases, prerequisites, or exclusions, leaving the agent to infer usage from the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/blake365/macrostrat-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server