Skip to main content
Glama
OilpriceAPI

OilPriceAPI

Official
by OilpriceAPI

opa_get_futures_curve

Retrieve the full futures forward curve for crude oil, including prices across all contract months and market structure analysis such as contango or backwardation.

Instructions

Get the full futures forward curve showing prices across all contract months. Use when the user asks about the forward curve, contango/backwardation, or term structure. Returns a table of contract months with prices and changes, plus market structure analysis.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractNoFutures contract: BZ = Brent crude, CL = WTI crude (default: BZ)BZ

Implementation Reference

  • Full tool definition, schema, and handler function for 'opa_get_futures_curve'. Uses server.tool() to register the tool. Accepts a 'contract' parameter (enum BZ/CL, default BZ). Handler calls the /v1/futures/curve API, formats a markdown table of contract months with prices and changes, and computes market structure (contango/backwardation).
    server.tool(
      "opa_get_futures_curve",
      "Get the full futures forward curve showing prices across all contract months. Use when the user asks about the forward curve, contango/backwardation, or term structure. Returns a table of contract months with prices and changes, plus market structure analysis.",
      {
        contract: z
          .enum(["BZ", "CL"])
          .default("BZ")
          .describe(
            "Futures contract: BZ = Brent crude, CL = WTI crude (default: BZ)",
          ),
      },
      async ({ contract }) => {
        const response = await makeApiRequest<ApiResponse<FuturesData>>(
          `/v1/futures/curve?contract=${contract}`,
        );
    
        if (
          !response ||
          response.status !== "success" ||
          !response.data.contracts?.length
        ) {
          return errorResult(
            `No futures curve data available for ${contract === "BZ" ? "Brent" : "WTI"} (${contract}). Futures data requires a paid plan.`,
          );
        }
    
        const contractName = contract === "BZ" ? "Brent Crude" : "WTI Crude";
        const contracts = response.data.contracts;
    
        let text = `# ${contractName} Futures Curve (${contract})\n\n`;
        text += `| Month | Price | Change |\n|-------|-------|--------|\n`;
    
        for (const c of contracts) {
          const changeStr =
            c.change !== undefined
              ? `${c.change >= 0 ? "+" : ""}$${c.change.toFixed(2)}`
              : "N/A";
          text += `| ${c.month} | $${c.price.toFixed(2)} | ${changeStr} |\n`;
        }
    
        const front = contracts[0].price;
        const back = contracts[contracts.length - 1].price;
        const structure = front > back ? "backwardation" : "contango";
        text += `\n**Market Structure**: ${structure} (front $${front.toFixed(2)} vs back $${back.toFixed(2)})`;
        text += `\n\n_Data from [OilPriceAPI](https://oilpriceapi.com)_`;
    
        return textResult(text);
      },
    );
  • Input schema for the tool: contract is a Zod enum of 'BZ' (Brent) or 'CL' (WTI), defaulting to 'BZ'.
    "Get the full futures forward curve showing prices across all contract months. Use when the user asks about the forward curve, contango/backwardation, or term structure. Returns a table of contract months with prices and changes, plus market structure analysis.",
    {
      contract: z
        .enum(["BZ", "CL"])
        .default("BZ")
        .describe(
          "Futures contract: BZ = Brent crude, CL = WTI crude (default: BZ)",
        ),
  • src/index.ts:970-971 (registration)
    Registration of the tool via server.tool('opa_get_futures_curve', ...) with description.
    server.tool(
      "opa_get_futures_curve",
  • FuturesData interface used for the API response type. Contains an array of contracts with month, price, change, and optional volume fields.
    interface FuturesData {
      contracts: Array<{
        contract: string;
        month: string;
        price: number;
        change?: number;
        volume?: number;
      }>;
    }
  • makeApiRequest helper function used by the tool handler to make HTTP requests to the OilPriceAPI with retry logic.
    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;
    }
Behavior4/5

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

Describes the output: 'Returns a table of contract months with prices and changes, plus market structure analysis.' This adequately discloses the return format and added analysis. No annotations exist, so description carries full burden, but it could mention data freshness or source.

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, front-loaded with the core purpose. Every sentence adds distinct information: what it does, when to use it, and what it returns. No wasted words.

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?

Given a simple parameter and no output schema, the description covers purpose, usage context, and output content. It lacks mention of limitations like data frequency or pagination, but these are not critical for this tool.

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% with clear enum values. The description adds value by explaining the output includes 'market structure analysis' and 'all contract months', which are not in the schema. This goes beyond the baseline of 3.

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?

Clearly states it retrieves the full futures forward curve with prices across all contract months. The verb 'Get' and resource 'full futures forward curve' are specific, and it distinguishes from siblings like opa_get_futures which likely returns a single price.

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 states when to use: 'when the user asks about the forward curve, contango/backwardation, or term structure.' This provides clear context, though it does not explicitly mention alternatives or when not to use.

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