place-details
Retrieve comprehensive details about a specific location using its Google Place ID. Designed for integration with MCP Server Boilerplate to enhance AI assistant capabilities with place-specific data.
Instructions
Get detailed information about a specific place
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| place_id | Yes | The Google Place ID |
Implementation Reference
- src/maps.ts:456-509 (handler)The main handler function that fetches place details using Google Maps Place Details API, processes the response, and formats it into 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) }`, }, ], }; } }
- src/maps.ts:141-143 (schema)Zod schema for input validation: requires '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 on the MCP server with name, description, schema, and handler.server.tool( "place-details", "Get detailed information about a specific place", placeDetailsSchema.shape, async (params) => { return await placeDetails(params); } );
- src/maps.ts:68-103 (helper)Helper function to format place details data into a structured markdown string for the tool response.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; }