Skip to main content
Glama

place-details

Retrieve comprehensive data for any location using its Google Place ID to access detailed information for analysis or integration.

Instructions

Get detailed information about a specific place

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
place_idYesThe Google Place ID

Implementation Reference

  • The main handler function for the 'place-details' tool. It fetches detailed information from the Google Maps Place Details API using the provided place_id and formats the response as markdown using formatPlaceDetailsToMarkdown.
    export async function placeDetails(
      params: z.infer<typeof placeDetailsSchema>,
      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.placeDetails({
          params: {
            place_id: params.place_id,
            key: apiKey,
          },
        });
    
        const place = response.data.result;
    
        const placeData = {
          name: place.name,
          formatted_address: place.formatted_address,
          phone_number: place.formatted_phone_number,
          website: place.website,
          rating: place.rating,
          user_ratings_total: place.user_ratings_total,
          price_level: place.price_level,
          opening_hours: place.opening_hours?.weekday_text,
          types: place.types,
          latitude: place.geometry?.location.lat,
          longitude: place.geometry?.location.lng,
        };
    
        return {
          content: [
            {
              type: "text" as const,
              text: formatPlaceDetailsToMarkdown(placeData),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error getting place details: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    }
  • Zod schema defining the input parameters for the 'place-details' tool, requiring a 'place_id' string.
    export const placeDetailsSchema = z.object({
      place_id: z.string().describe("The Google Place ID"),
    });
  • src/index.ts:110-117 (registration)
    Registers the 'place-details' tool with the MCP server, linking to the placeDetails handler and placeDetailsSchema.
    server.tool(
      "place-details",
      "Get detailed information about a specific place",
      placeDetailsSchema.shape,
      async (params) => {
        return await placeDetails(params);
      }
    );
  • Helper function used by the placeDetails handler to format the Google Maps place details data into a structured markdown string.
    function formatPlaceDetailsToMarkdown(place: any): string {
      let markdown = `# ${place.name}\n\n`;
      
      if (place.formatted_address) markdown += `Address: ${place.formatted_address}  \n`;
      if (place.phone_number) markdown += `Phone: ${place.phone_number}  \n`;
      if (place.website) markdown += `Website: [Visit](${place.website})  \n`;
      
      if (place.rating) {
        markdown += `Rating: ${place.rating}⭐`;
        if (place.user_ratings_total) markdown += ` (${place.user_ratings_total} reviews)`;
        markdown += `  \n`;
      }
      
      if (place.price_level !== undefined) {
        const priceSymbols = '$'.repeat(place.price_level + 1);
        markdown += `Price Level: ${priceSymbols}  \n`;
      }
      
      if (place.latitude && place.longitude) {
        markdown += `Location: ${place.latitude}, ${place.longitude}  \n`;
        markdown += `Maps: [View](https://maps.google.com/?q=${place.latitude},${place.longitude})  \n`;
      }
      
      if (place.opening_hours && place.opening_hours.length) {
        markdown += `\n## Hours\n`;
        place.opening_hours.forEach((hours: string) => {
          markdown += `- ${hours}\n`;
        });
      }
      
      if (place.types && place.types.length) {
        markdown += `\nCategories: ${place.types.join(', ')}`;
      }
      
      return markdown;
    }

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