Skip to main content
Glama
Dagudelot

MCP Server with OpenAI Integration

by Dagudelot

get_weather

Retrieve current weather conditions and temperature for any city, with options for Celsius or Fahrenheit units.

Instructions

Get current weather information for a specific city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesThe city to get weather information for
unitNoTemperature unitcelsius

Implementation Reference

  • The core handler function that implements the logic for the 'get_weather' tool, generating simulated weather information for the given city and unit.
    async function getWeatherInfo(city: string, unit: "celsius" | "fahrenheit" = "celsius"): Promise<string> {
      // Simulate weather API call
      const temperature = Math.floor(Math.random() * 30) + 10; // Random temp between 10-40
      const conditions = ["sunny", "cloudy", "rainy", "partly cloudy"];
      const condition = conditions[Math.floor(Math.random() * conditions.length)];
      
      const tempDisplay = unit === "fahrenheit" ? `${Math.round(temperature * 9/5 + 32)}°F` : `${temperature}°C`;
      
      return `Weather in ${city}: ${tempDisplay}, ${condition}`;
    }
  • Zod schema used for input validation of the 'get_weather' tool parameters.
    const WeatherToolSchema = z.object({
      city: z.string().describe("The city to get weather information for"),
      unit: z.enum(["celsius", "fahrenheit"]).optional().default("celsius").describe("Temperature unit"),
    });
  • src/index.ts:66-70 (registration)
    Registration of the 'get_weather' tool in the MCP server's tool listing handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [weatherTool],
      };
    });
  • MCP server request handler for tool calls, dispatching to getWeatherInfo when 'get_weather' is called and returning the result.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      switch (name) {
        case "get_weather":
          const { city, unit } = WeatherToolSchema.parse(args);
          const weatherInfo = await getWeatherInfo(city, unit);
          return {
            content: [
              {
                type: "text",
                text: weatherInfo,
              },
            ],
          };
    
        default:
          throw new Error(`Unknown tool: ${name}`);
      }
    });
  • Definition of the 'get_weather' tool including its MCP input schema for tool discovery.
    const weatherTool: Tool = {
      name: "get_weather",
      description: "Get current weather information for a specific city",
      inputSchema: {
        type: "object",
        properties: {
          city: {
            type: "string",
            description: "The city to get weather information for"
          },
          unit: {
            type: "string",
            enum: ["celsius", "fahrenheit"],
            default: "celsius",
            description: "Temperature unit"
          }
        },
        required: ["city"]
      },
    };
Behavior2/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 of behavioral disclosure. It mentions 'Get current weather information,' which implies a read-only operation, but fails to describe error handling, rate limits, data sources, or response format. This leaves significant gaps in understanding the tool's behavior.

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 front-loads the core purpose without any wasted words. It is appropriately sized for a simple tool and earns its place by clearly stating the action and target.

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 lack of annotations and output schema, the description is incomplete. It doesn't explain what weather information is returned (e.g., temperature, conditions), error scenarios, or any behavioral traits. For a tool with no structured support, this leaves the agent under-informed.

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 input schema has 100% description coverage, clearly documenting both parameters. The description adds minimal value beyond the schema by implying the 'city' parameter is used for location, but it doesn't provide additional context like format examples or edge cases. Baseline 3 is appropriate given the schema does the heavy lifting.

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 ('current weather information'), and specifies the target ('for a specific city'). It distinguishes what the tool does effectively, though there are no sibling tools to differentiate from, 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, prerequisites, or exclusions. It simply states what the tool does without context for usage, leaving the agent with minimal direction.

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/Dagudelot/mcp-server-openai-sdk'

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