Skip to main content
Glama

Search Nearby Places

search_nearby

Find nearby places like restaurants or coffee shops by entering a location, search radius, and optional filters for current hours or minimum ratings.

Instructions

Search for places near a specific location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
centerYes
keywordNoSearch keyword (e.g., restaurant, coffee)
radiusNoSearch radius in meters
openNowNoOnly show places that are currently open
minRatingNoMinimum rating requirement (0-5)

Implementation Reference

  • MCP tool handler function for 'search_nearby' that executes the places search and returns structured content response or error.
    async (args) => {
        try {
            const result = await placesSearcher.searchNearby(args);
            return {
                content: [
                    { type: "text", text: JSON.stringify(result, null, 2) },
                ],
                isError: !result.success,
            };
        } catch (error) {
            const errorResponse = handleError(error);
            return {
                content: [
                    {
                        type: "text",
                        text:
                            errorResponse.error ||
                            "An unknown error occurred",
                    },
                ],
                isError: true,
            };
        }
    }
  • Input schema defining parameters for the search_nearby tool: center location, keyword, radius, openNow, minRating.
    export const SearchNearbySchema = {
      center: LocationInputSchema,
      keyword: z.string().optional().describe("Search keyword (e.g., restaurant, coffee)"),
      radius: z.number().optional().default(1000).describe("Search radius in meters"),
      openNow: z.boolean().optional().default(false).describe("Only show places that are currently open"),
      minRating: z.number().min(0).max(5).optional().describe("Minimum rating requirement (0-5)")
    };
  • Registration of the 'search_nearby' tool in the MCP server, specifying name, metadata, input schema, and handler.
    server.registerTool(
        "search_nearby",
        {
            title: "Search Nearby Places",
            description: "Search for places near a specific location",
            inputSchema: SearchNearbySchema,
        },
        async (args) => {
            try {
                const result = await placesSearcher.searchNearby(args);
                return {
                    content: [
                        { type: "text", text: JSON.stringify(result, null, 2) },
                    ],
                    isError: !result.success,
                };
            } catch (error) {
                const errorResponse = handleError(error);
                return {
                    content: [
                        {
                            type: "text",
                            text:
                                errorResponse.error ||
                                "An unknown error occurred",
                        },
                    ],
                    isError: true,
                };
            }
        }
    );
  • Supporting class method in PlacesSearcher that performs the actual nearby places search using Google Maps client, handles geocoding if needed, filters by rating, etc.
    async searchNearby(params: {
        center: LocationInput;
        keyword?: string;
        radius?: number;
        openNow?: boolean;
        minRating?: number;
    }): Promise<ServiceResponse<PlaceDetails[]>> {
        try {
            let location: Location;
    
            if (params.center.isCoordinates) {
                const [lat, lng] = params.center.value.split(",").map(Number);
                validateCoordinates(lat, lng);
                location = { lat, lng };
            } else {
                const geocodeResult = await this.geocode(params.center.value);
                if (!geocodeResult.success || !geocodeResult.data) {
                    throw new Error("Failed to geocode center location");
                }
                location = geocodeResult.data;
            }
    
            const response = await this.client.placesNearby({
                params: {
                    key: config.googleMapsApiKey,
                    location: location,
                    radius: params.radius || 1000,
                    keyword: params.keyword,
                    opennow: params.openNow,
                    language: config.defaultLanguage,
                },
            });
    
            let places = response.data.results.map((place) => {
                if (!place.geometry || !place.place_id || !place.name) {
                    throw new Error("Required place data is missing");
                }
                return {
                    placeId: place.place_id,
                    name: place.name,
                    location: place.geometry.location,
                    rating: place.rating,
                    userRatingsTotal: place.user_ratings_total,
                    types: place.types,
                    vicinity: place.vicinity,
                };
            });
    
            if (params.minRating) {
                places = places.filter(
                    (place) => (place.rating || 0) >= (params.minRating || 0)
                );
            }
    
            return {
                success: true,
                data: places,
            };
        } catch (error) {
            return handleError(error);
        }
    }
Behavior2/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 states the basic action but doesn't cover critical aspects like rate limits, authentication requirements, pagination, error handling, or what the output looks like (e.g., list format, fields included). This leaves significant gaps for an agent to understand how to use it effectively.

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, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 tool's complexity (5 parameters, nested objects, no output schema) and lack of annotations, the description is insufficient. It doesn't explain return values, error cases, or behavioral nuances, leaving the agent with incomplete context for proper usage.

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 80%, so the schema already documents most parameters well. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't clarify 'center' usage or 'keyword' examples beyond the schema's descriptions). This meets the baseline for high schema coverage.

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 clearly states the tool's purpose as 'Search for places near a specific location,' which includes a specific verb ('Search') and resource ('places near a specific location'). However, it doesn't explicitly differentiate from sibling tools like 'get_place_details' or 'get_geocode,' which prevents a perfect score.

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 lacks context such as whether this is for general discovery versus specific lookups, and doesn't mention sibling tools like 'get_place_details' for detailed information or 'get_geocode' for location resolution.

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/BACH-AI-Tools/MCP-Google-Maps'

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