Skip to main content
Glama

get-weather

Retrieve current weather conditions for any city by specifying the location name. This tool provides essential weather information through the Weather MCP Server.

Instructions

Tool to get the weather for a given city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesThe city to get the weather for

Implementation Reference

  • main.ts:19-51 (handler)
    The handler function for the 'get-weather' tool. It invokes queryOllama to fetch weather data for the given city, handles errors gracefully, and returns the response in MCP content format.
    async ({ city }) => {
        console.log(`🌤️ MCP tool called for: ${city}`);
        const toolStartTime = Date.now();
        
        try {
            const response = await queryOllama(city);
            const toolEndTime = Date.now();
            
            console.log(`✅ MCP tool completed in ${toolEndTime - toolStartTime}ms`);
            
            return {
                content: [
                    {
                        type: "text",
                        text: response,
                    }
                ]
            };
        } catch (error) {
            const toolEndTime = Date.now();
            console.error(`❌ MCP tool failed after ${toolEndTime - toolStartTime}ms:`, error);
            
            // Return a helpful error message instead of throwing
            return {
                content: [
                    {
                        type: "text",
                        text: `Unable to get weather for ${city}. Ollama may be slow or unavailable. Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
                    }
                ]
            };
        }
    }
  • main.ts:16-18 (schema)
    Zod schema defining the input parameter 'city' for the get-weather tool.
    {
        city: z.string().describe("The city to get the weather for"),
    },
  • main.ts:13-52 (registration)
    Registration of the 'get-weather' tool using McpServer.tool(), including name, description, input schema, and handler reference.
    server.tool(
        "get-weather",
        "Tool to get the weather for a given city",
        {
            city: z.string().describe("The city to get the weather for"),
        },
        async ({ city }) => {
            console.log(`🌤️ MCP tool called for: ${city}`);
            const toolStartTime = Date.now();
            
            try {
                const response = await queryOllama(city);
                const toolEndTime = Date.now();
                
                console.log(`✅ MCP tool completed in ${toolEndTime - toolStartTime}ms`);
                
                return {
                    content: [
                        {
                            type: "text",
                            text: response,
                        }
                    ]
                };
            } catch (error) {
                const toolEndTime = Date.now();
                console.error(`❌ MCP tool failed after ${toolEndTime - toolStartTime}ms:`, error);
                
                // Return a helpful error message instead of throwing
                return {
                    content: [
                        {
                            type: "text",
                            text: `Unable to get weather for ${city}. Ollama may be slow or unavailable. Error: ${error instanceof Error ? error.message : 'Unknown error'}`,
                        }
                    ]
                };
            }
        }
    );
  • Core helper function that queries Ollama for weather information using HTTP API with fallback to CLI, implementing the actual LLM-based weather query logic.
    export async function queryOllama(city: string): Promise<string> {
      console.log(`🌤️ Querying weather for ${city}...`);
      const startTime = Date.now();
      
      try {
        const result = await queryOllamaHTTP(city);
        const endTime = Date.now();
        console.log(`✅ Query completed in ${endTime - startTime}ms`);
        return result;
      } catch (error) {
        console.error("❌ HTTP API failed, trying CLI...");
        try {
          const result = await queryOllamaCLI(city);
          const endTime = Date.now();
          console.log(`✅ CLI query completed in ${endTime - startTime}ms`);
          return result;
        } catch (cliError) {
          console.error("❌ Both HTTP and CLI failed");
          throw 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 only states the basic function without mentioning any behavioral traits like rate limits, error handling, authentication requirements, data freshness, or response format. For a tool with zero annotation coverage, this leaves critical gaps in understanding how it behaves.

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 extremely concise at just one sentence with zero wasted words. It's front-loaded with the core purpose and efficiently communicates the essential information. Every word earns its place in this minimal but complete statement of function.

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 (simple read operation) but complete lack of annotations and no output schema, the description is insufficient. It doesn't explain what weather data is returned, in what format, or any behavioral constraints. The description should provide more context about the operation's scope and results to compensate for the missing structured information.

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 100%, with the single parameter 'city' fully documented in the schema. The description adds no additional parameter semantics beyond what the schema already provides. According to the rules, when schema coverage is high (>80%), the baseline score is 3 even with no param info in the description.

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 with a specific verb ('get') and resource ('weather'), and specifies the target ('for a given city'). It's not tautological and communicates the core function effectively. However, with no sibling tools mentioned, there's no opportunity to distinguish from alternatives, preventing 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, prerequisites, or contextual constraints. It simply states what the tool does without any usage context. This is a significant gap in helping an agent make informed decisions.

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/codewith1984/weather-mcp-server-typescript'

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