Skip to main content
Glama

geocode

Convert addresses into geographic coordinates for mapping and location-based applications.

Instructions

Convert an address to coordinates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesThe address to geocode

Implementation Reference

  • The handler function that performs geocoding using Google Maps API, handles errors, and formats the markdown output.
    export async function geocode(
      params: z.infer<typeof geocodeSchema>,
      extra?: any
    ) {
      const apiKey = process.env.GOOGLE_MAPS_API_KEY;
      if (!apiKey) {
        throw new Error("GOOGLE_MAPS_API_KEY is required");
      }
    
      try {
        const response = await googleMapsClient.geocode({
          params: {
            address: params.address,
            key: apiKey,
          },
        });
    
        const results = response.data.results;
        if (results.length === 0) {
          return {
            content: [
              {
                type: "text" as const,
                text: "No results found for the given address.",
              },
            ],
          };
        }
    
        const location = results[0];
        return {
          content: [
            {
              type: "text" as const,
              text: formatLocationToMarkdown(
                "Geocoded Location", 
                location.formatted_address, 
                location.geometry.location.lat, 
                location.geometry.location.lng,
                location.place_id
              ),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error geocoding address: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    }
  • Zod schema defining the input parameters for the geocode tool: an address string.
    export const geocodeSchema = z.object({
      address: z.string().describe("The address to geocode"),
    });
  • src/index.ts:60-67 (registration)
    Registration of the 'geocode' tool in the MCP server, providing name, description, input schema, and handler wrapper.
    server.tool(
      "geocode",
      "Convert an address to coordinates",
      geocodeSchema.shape,
      async (params) => {
        return await geocode(params);
      }
    );
  • Helper function to format geocoding results into markdown with title, address, coordinates, place ID, and Google Maps link.
    function formatLocationToMarkdown(title: string, address: string, lat: number, lng: number, placeId?: string): string {
      let markdown = `# ${title}\n\n`;
      markdown += `Address: ${address}  \n`;
      markdown += `Coordinates: ${lat}, ${lng}  \n`;
      if (placeId) markdown += `Place ID: \`${placeId}\`  \n`;
      markdown += `Google Maps: [View on Maps](https://maps.google.com/?q=${lat},${lng})`;
      return markdown;
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. The description only states the basic function without mentioning any behavioral traits such as rate limits, accuracy considerations, error handling, authentication requirements, or what happens with invalid addresses. For a tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves in practice.

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 extremely concise with a single, clear sentence that directly states the tool's purpose. There's no wasted language or unnecessary elaboration. It's front-loaded with the core functionality and doesn't include any redundant information.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete for effective tool use. While the purpose is clear, it doesn't address important contextual elements like what the output looks like (coordinates format), error conditions, performance characteristics, or integration considerations. For a tool that performs a non-trivial conversion with potential variability in results, more context would be helpful.

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?

The schema description coverage is 100% (the single parameter 'address' has a clear description in the schema), so the baseline is 3. The tool description doesn't add any parameter-specific information beyond what's already in the schema. It doesn't provide examples of address formats, discuss parameter constraints, or explain how the parameter affects the conversion process.

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

Purpose4/5

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

The description 'Convert an address to coordinates' clearly states the tool's function with a specific verb ('convert') and resource ('address to coordinates'). It distinguishes itself from sibling tools like 'reverse-geocode' by specifying the direction of conversion. However, it doesn't explicitly differentiate from other location-based tools like 'places-search' or 'get-directions' beyond the basic operation.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when this tool is appropriate compared to sibling tools like 'places-search' (which might return coordinates among other data) or 'reverse-geocode' (which does the opposite conversion). There's no context about prerequisites, limitations, or typical use cases.

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/CaptainCrouton89/maps-mcp'

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