Skip to main content
Glama
OilpriceAPI

OilPriceAPI

Official
by OilpriceAPI

opa_get_forecasts

Get short-term energy price forecasts for crude oil, natural gas, and other key commodities from the EIA STEO and additional sources.

Instructions

Get energy price forecasts from EIA Short-Term Energy Outlook (STEO) and other sources. Use when the user asks about price predictions, outlooks, or where oil/gas prices are heading. Returns forecast data for key commodities. Requires a paid plan with energy intelligence access.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual handler/logic for the 'opa_get_forecasts' tool. It calls makeApiRequest to '/v1/ei/forecasts/latest', checks for success, formats the response as JSON in a markdown block, and returns a text result.
    server.tool(
      "opa_get_forecasts",
      "Get energy price forecasts from EIA Short-Term Energy Outlook (STEO) and other sources. Use when the user asks about price predictions, outlooks, or where oil/gas prices are heading. Returns forecast data for key commodities. Requires a paid plan with energy intelligence access.",
      {},
      async () => {
        const response = await makeApiRequest<ApiResponse<Record<string, unknown>>>(
          "/v1/ei/forecasts/latest",
        );
    
        if (!response || response.status !== "success") {
          return errorResult(
            "Forecast data not available. This requires a paid plan with energy intelligence access.",
          );
        }
    
        let text = "# Energy Price Forecasts\n\n";
        text += "```json\n" + JSON.stringify(response.data, null, 2) + "\n```\n";
        text +=
          "\n_Source: EIA STEO | Data from [OilPriceAPI](https://oilpriceapi.com)_";
    
        return textResult(text);
      },
    );
  • src/index.ts:1266-1288 (registration)
    The tool is registered via server.tool() with the name 'opa_get_forecasts', a description, an empty schema object (no inputs), and the handler function.
    server.tool(
      "opa_get_forecasts",
      "Get energy price forecasts from EIA Short-Term Energy Outlook (STEO) and other sources. Use when the user asks about price predictions, outlooks, or where oil/gas prices are heading. Returns forecast data for key commodities. Requires a paid plan with energy intelligence access.",
      {},
      async () => {
        const response = await makeApiRequest<ApiResponse<Record<string, unknown>>>(
          "/v1/ei/forecasts/latest",
        );
    
        if (!response || response.status !== "success") {
          return errorResult(
            "Forecast data not available. This requires a paid plan with energy intelligence access.",
          );
        }
    
        let text = "# Energy Price Forecasts\n\n";
        text += "```json\n" + JSON.stringify(response.data, null, 2) + "\n```\n";
        text +=
          "\n_Source: EIA STEO | Data from [OilPriceAPI](https://oilpriceapi.com)_";
    
        return textResult(text);
      },
    );
  • The textResult helper function used by the handler to construct the successful response.
    function textResult(text: string) {
      return {
        content: [{ type: "text" as const, text }],
      };
    }
  • The errorResult helper function used by the handler when the API request fails.
    function errorResult(message: string) {
      return {
        content: [{ type: "text" as const, text: message }],
        isError: true,
      };
    }
  • The makeApiRequest helper function that performs the API call with retry logic and exponential backoff. Called by the handler to fetch forecast data from '/v1/ei/forecasts/latest'.
    export async function makeApiRequest<T>(
      endpoint: string,
      fetchFn: typeof fetch = fetch,
    ): Promise<T | null> {
      const headers: Record<string, string> = {
        "User-Agent": USER_AGENT,
        Accept: "application/json",
      };
    
      if (API_KEY) {
        headers["Authorization"] = `Bearer ${API_KEY}`;
      }
    
      const maxRetries = 3;
    
      for (let attempt = 0; attempt <= maxRetries; attempt++) {
        try {
          const response = await fetchFn(`${API_BASE}${endpoint}`, { headers });
    
          if (response.ok) {
            return (await response.json()) as T;
          }
    
          if (response.status === 401) {
            console.error(
              "Authentication failed. Set OILPRICEAPI_KEY environment variable. Get a free key at https://oilpriceapi.com/signup",
            );
            return null;
          }
    
          // Retry on 429 and 5xx
          if (
            (response.status === 429 || response.status >= 500) &&
            attempt < maxRetries
          ) {
            const retryAfter = response.headers.get("Retry-After");
            const delay = retryAfter
              ? Math.min(parseInt(retryAfter, 10), 60) * 1000
              : Math.pow(2, attempt) * 1000;
            await new Promise((resolve) => setTimeout(resolve, delay));
            continue;
          }
    
          console.error(
            `HTTP ${response.status}: ${response.statusText} for ${endpoint}`,
          );
          return null;
        } catch (error) {
          if (attempt === maxRetries) {
            console.error(
              `API request failed after ${maxRetries + 1} attempts: ${endpoint}`,
              error,
            );
            return null;
          }
          const delay = Math.pow(2, attempt) * 1000;
          await new Promise((resolve) => setTimeout(resolve, delay));
        }
      }
    
      return null;
    }
Behavior2/5

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

No annotations provided, and the description does not disclose any behavioral aspects such as idempotency, rate limits, data freshness, or error handling, which are important for a data-fetching tool.

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?

Three sentences that efficiently convey purpose, usage context, and requirements with no redundancy, and the key action is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequately covers the purpose and return type for a simple zero-parameter tool, but lacks specificity on commodities and output format since there is no output schema.

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?

The input schema has no parameters, so the description's lack of parameter details is acceptable; baseline for zero-parameter tools with 100% schema coverage is 4.

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 tool gets energy price forecasts from EIA STEO and other sources, and distinguishes itself from siblings like opa_get_price and opa_get_history by focusing on predictions and outlooks.

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

Usage Guidelines4/5

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

Explicitly says when to use (price predictions, outlooks) and mentions the prerequisite of a paid plan, but lacks explicit 'when not to use' guidance.

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/OilpriceAPI/mcp-server'

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