Skip to main content
Glama
europarcel
by europarcel

Search Localities

searchLocalities

Search for Romanian localities by name. Supports diacritics, punctuation, and reversed county-city queries for accurate address lookup.

Instructions

Search for localities by country and name. Supports diacritics, punctuation, and reversed county-city queries. Parameters: country_code (2 letters, required), search (min 2 chars, required), per_page (15|50|100|200)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
country_codeYesThe country code - must be 'RO' (Romania)
searchYesThe search term for locality names (minimum 2 characters)
per_pageNoNumber of results per page - must be 15, 50, 100, or 200 (default: 15)

Implementation Reference

  • Main handler function that registers the searchLocalities tool with the MCP server. Validates inputs (country_code, search, per_page), calls the API client, and formats the response with locality details.
    export function registerSearchLocalitiesTool(server: McpServer): void {
      // Create API client instance
    
      // Register searchLocalities tool
      server.registerTool(
        "searchLocalities",
        {
          title: "Search Localities",
          description:
            "Search for localities by country and name. Supports diacritics, punctuation, and reversed county-city queries. Parameters: country_code (2 letters, required), search (min 2 chars, required), per_page (15|50|100|200)",
          inputSchema: {
            country_code: z
              .enum(["RO"])
              .describe("The country code - must be 'RO' (Romania)"),
            search: z
              .string()
              .min(2)
              .describe(
                "The search term for locality names (minimum 2 characters)",
              ),
            per_page: z
              .union([z.literal(15), z.literal(50), z.literal(100), z.literal(200)])
              .optional()
              .describe(
                "Number of results per page - must be 15, 50, 100, or 200 (default: 15)",
              ),
          },
        },
        async (args: any) => {
          // Get API key from async context
          const apiKey = apiKeyStorage.getStore();
    
          if (!apiKey) {
            return {
              content: [
                {
                  type: "text",
                  text: "Error: X-API-KEY header is required",
                },
              ],
            };
          }
    
          // Create API client with customer's API key
          const client = new EuroparcelApiClient(apiKey);
    
          try {
            // Validate required parameters
            if (
              !args.country_code ||
              typeof args.country_code !== "string" ||
              args.country_code.length !== 2
            ) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: country_code is required and must be exactly 2 letters (e.g., 'RO', 'HU')",
                  },
                ],
              };
            }
    
            if (
              !args.search ||
              typeof args.search !== "string" ||
              args.search.length < 2
            ) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: search parameter is required and must be at least 2 characters",
                  },
                ],
              };
            }
    
            const perPage = args.per_page || 15;
            const allowedPerPage = [15, 50, 100, 200];
            if (!allowedPerPage.includes(perPage)) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: per_page must be one of: 15, 50, 100, 200",
                  },
                ],
              };
            }
    
            logger.info("Searching localities", {
              country_code: args.country_code.toUpperCase(),
              search: args.search,
              per_page: perPage,
            });
    
            const response = await client.searchLocalities(
              args.country_code.toUpperCase(),
              args.search,
              perPage as 15 | 50 | 100 | 200,
            );
    
            logger.info(`Found ${response.data.length} localities`);
    
            let formattedResponse = `Found ${response.meta.count} localities matching "${response.meta.search_term}" in ${response.meta.country_code}:\n\n`;
    
            if (response.data.length === 0) {
              formattedResponse += "No localities found.";
            } else {
              response.data.forEach((locality) => {
                formattedResponse += `📍 ${locality.name_and_county}\n`;
                formattedResponse += `   ID: ${locality.id}\n`;
                formattedResponse += `   County: ${locality.county} (${locality.county_code})\n\n`;
              });
    
              if (response.meta.count > response.meta.per_page) {
                formattedResponse += `\nShowing first ${response.meta.per_page} results. Use per_page parameter to see more.`;
              }
            }
    
            return {
              content: [
                {
                  type: "text",
                  text: formattedResponse,
                },
              ],
            };
          } catch (error: any) {
            logger.error("Failed to search localities", error);
    
            return {
              content: [
                {
                  type: "text",
                  text: `Error searching localities: ${error.message || "Unknown error"}`,
                },
              ],
            };
          }
        },
      );
    
      logger.info("searchLocalities tool registered successfully");
    }
  • Input schema for searchLocalities using Zod: country_code (enum RO), search (string min 2), per_page (optional union of 15|50|100|200).
    {
      title: "Search Localities",
      description:
        "Search for localities by country and name. Supports diacritics, punctuation, and reversed county-city queries. Parameters: country_code (2 letters, required), search (min 2 chars, required), per_page (15|50|100|200)",
      inputSchema: {
        country_code: z
          .enum(["RO"])
          .describe("The country code - must be 'RO' (Romania)"),
        search: z
          .string()
          .min(2)
          .describe(
            "The search term for locality names (minimum 2 characters)",
          ),
        per_page: z
          .union([z.literal(15), z.literal(50), z.literal(100), z.literal(200)])
          .optional()
          .describe(
            "Number of results per page - must be 15, 50, 100, or 200 (default: 15)",
          ),
      },
  • Registration entry point: registerSearchTools() calls registerSearchLocalitiesTool(server) to register the tool.
    export function registerSearchTools(server: McpServer): void {
      logger.info("Registering search tools...");
    
      // Register all search-related tools
      registerSearchLocalitiesTool(server);
      registerSearchStreetsTool(server);
      registerPostalCodeReverseTool(server);
    
      logger.info("All search tools registered successfully");
    }
  • API client method searchLocalities() that sends a GET request to /search/localities/{countryCode}/{search} with optional per_page param.
    async searchLocalities(
      countryCode: string,
      search: string,
      perPage?: 15 | 50 | 100 | 200,
    ): Promise<LocalitySearchResponse> {
      const response = await this.client.get<LocalitySearchResponse>(
        `/search/localities/${countryCode}/${search}`,
        {
          params: {
            per_page: perPage,
          },
        },
      );
      return response.data;
    }
  • TypeScript interface LocalitySearchResponse and LocalitySearchResult defining the response shape from the API.
    export interface LocalitySearchResponse {
      data: LocalitySearchResult[];
      meta: {
        count: number;
        per_page: number;
        country_code: string;
        search_term: string;
      };
    }
Behavior3/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. It discloses support for diacritics, punctuation, and reversed queries, but omits behavioral traits like rate limits, authentication needs, or result format. The description is decent but not thorough.

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?

Two sentences with no wasted words. The first sentence states purpose, the second covers parameters. Highly efficient and front-loaded.

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?

No output schema exists, so the description should explain what the response contains (e.g., list of localities, pagination info). It fails to do so, leaving significant gaps in completeness for a search tool with required parameters.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. The description adds value by summarizing constraints (e.g., '2 letters', 'min 2 chars', '15|50|100|200') and hinting at reversed query capability, going slightly beyond what the schema provides.

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 verb 'Search' and resource 'localities by country and name', distinguishing it from sibling tools like 'getLocalities' (likely a list all) and 'postalCodeReverse' (reverse lookup). It also mentions specific capabilities like diacritics and reversed queries.

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

Usage Guidelines3/5

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

The description implies usage for searching localities by name and country but does not explicitly state when to use this tool vs alternatives. No guidance on exclusions or prerequisites is provided, leaving the agent to infer context.

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/europarcel/mcp-docker'

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