Skip to main content
Glama

Search City

searchCity

Find cities matching your search query to locate specific urban areas for further analysis or data retrieval.

Instructions

Find cities matching a query string

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The handler function that implements the core logic of the 'searchCity' tool. It takes a query string, fetches matching cities from the Open-Meteo geocoding API (up to 5 results), formats them as a list, and returns the response in MCP format. Handles errors gracefully.
    async ({ query }) => {
      try {
        const geoUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(query)}&count=5&language=en&format=json`;
        const geoRes = await fetch(geoUrl);
        if (!geoRes.ok) throw new Error("Failed to fetch city search");
        const geoData = await geoRes.json() as any;
        if (!geoData.results || geoData.results.length === 0) return {
          content: [{ type: "text", text: "No matching cities found." }]
        };
        const matches = geoData.results.map((c: any) => `${c.name}, ${c.country} (${c.latitude},${c.longitude})`).join("\n");
        return {
          content: [{ type: "text", text: `Matching cities:\n${matches}` }]
        };
      } catch (err: any) {
        return {
          content: [{ type: "text", text: `Error: ${err.message}` }],
          isError: true
        };
      }
    }
  • The input schema and metadata for the 'searchCity' tool, defining the title, description, and input validation using Zod (query as string).
    {
      title: "Search City",
      description: "Find cities matching a query string",
      inputSchema: { query: z.string() }
  • src/server.ts:99-126 (registration)
    The registration of the 'searchCity' tool on the MCP server using server.registerTool, including the tool name, schema, and handler reference.
    server.registerTool(
      "searchCity",
      {
        title: "Search City",
        description: "Find cities matching a query string",
        inputSchema: { query: z.string() }
      },
      async ({ query }) => {
        try {
          const geoUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(query)}&count=5&language=en&format=json`;
          const geoRes = await fetch(geoUrl);
          if (!geoRes.ok) throw new Error("Failed to fetch city search");
          const geoData = await geoRes.json() as any;
          if (!geoData.results || geoData.results.length === 0) return {
            content: [{ type: "text", text: "No matching cities found." }]
          };
          const matches = geoData.results.map((c: any) => `${c.name}, ${c.country} (${c.latitude},${c.longitude})`).join("\n");
          return {
            content: [{ type: "text", text: `Matching cities:\n${matches}` }]
          };
        } catch (err: any) {
          return {
            content: [{ type: "text", text: `Error: ${err.message}` }],
            isError: true
          };
        }
      }
    );

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.8/5.0
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It states the action ('find cities') but doesn't describe what the tool returns (e.g., list of cities with details), whether it has rate limits, authentication needs, or error conditions. This leaves significant gaps for a tool with no annotation coverage.

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 gets straight to the point with no wasted words. It's appropriately front-loaded with the core action, 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?

For a search tool with no annotations, no output schema, and 0% schema description coverage, the description is insufficient. It doesn't explain what the tool returns (e.g., city names, coordinates, populations), how results are structured, or any behavioral aspects like pagination or error handling, leaving the agent with significant uncertainty.

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

Parameters2/5

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

Schema description coverage is 0%, so the schema provides no parameter documentation. The description mentions 'query string' which aligns with the 'query' parameter, but doesn't explain what constitutes a valid query (e.g., partial names, case sensitivity) or provide examples. With 1 parameter and low coverage, this adds minimal value beyond the bare schema.

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 verb ('find') and resource ('cities') with the action ('matching a query string'), making the purpose immediately understandable. However, it doesn't differentiate from potential sibling tools like 'currentWeather' or 'forecast' that might also involve city data, so it doesn't achieve full sibling differentiation.

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. With siblings like 'currentWeather' and 'forecast' that likely involve cities, there's no indication whether this is for general city lookup versus weather-specific queries, nor any prerequisites or exclusions mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.