Skip to main content
Glama
OilpriceAPI

OilPriceAPI

Official
by OilpriceAPI

opa_get_rig_counts

Returns US oil and gas rig count data from Baker Hughes, including oil rigs, gas rigs, total count, and week-over-week change. Use to answer queries about drilling activity and rig counts.

Instructions

Get the latest US oil and gas rig count data (Baker Hughes). Use when the user asks about drilling activity, rig counts, or oil field operations. Returns oil rigs, gas rigs, total count, and week-over-week change. No parameters needed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/index.ts:1070-1099 (registration)
    Registration of the 'opa_get_rig_counts' tool using server.tool(), with description, empty schema, and async handler callback.
    server.tool(
      "opa_get_rig_counts",
      "Get the latest US oil and gas rig count data (Baker Hughes). Use when the user asks about drilling activity, rig counts, or oil field operations. Returns oil rigs, gas rigs, total count, and week-over-week change. No parameters needed.",
      {},
      async () => {
        const response = await makeApiRequest<ApiResponse<RigCountData>>(
          "/v1/rig-counts/latest",
        );
    
        if (!response || response.status !== "success") {
          return errorResult(
            "Rig count data not available. This may require a paid plan with energy intelligence access.",
          );
        }
    
        const data = response.data;
        let text = `# US Rig Count (Baker Hughes)\n\n`;
        text += `- **Oil Rigs**: ${data.oil}\n`;
        text += `- **Gas Rigs**: ${data.gas}\n`;
        text += `- **Total**: ${data.total}\n`;
        if (data.change_from_prior_week !== undefined) {
          const sign = data.change_from_prior_week >= 0 ? "+" : "";
          text += `- **Change from Prior Week**: ${sign}${data.change_from_prior_week}\n`;
        }
        text += `- **Date**: ${data.date}\n`;
        text += `\n_Data from [OilPriceAPI](https://oilpriceapi.com)_`;
    
        return textResult(text);
      },
    );
  • Handler function that calls makeApiRequest to /v1/rig-counts/latest, checks for success, and formats rig count data (oil, gas, total, change_from_prior_week, date) into a text result.
    async () => {
      const response = await makeApiRequest<ApiResponse<RigCountData>>(
        "/v1/rig-counts/latest",
      );
    
      if (!response || response.status !== "success") {
        return errorResult(
          "Rig count data not available. This may require a paid plan with energy intelligence access.",
        );
      }
    
      const data = response.data;
      let text = `# US Rig Count (Baker Hughes)\n\n`;
      text += `- **Oil Rigs**: ${data.oil}\n`;
      text += `- **Gas Rigs**: ${data.gas}\n`;
      text += `- **Total**: ${data.total}\n`;
      if (data.change_from_prior_week !== undefined) {
        const sign = data.change_from_prior_week >= 0 ? "+" : "";
        text += `- **Change from Prior Week**: ${sign}${data.change_from_prior_week}\n`;
      }
      text += `- **Date**: ${data.date}\n`;
      text += `\n_Data from [OilPriceAPI](https://oilpriceapi.com)_`;
    
      return textResult(text);
    },
  • RigCountData interface defining the shape of the API response: oil, gas, total, misc (optional), change_from_prior_week (optional), date, and source (optional).
    interface RigCountData {
      oil: number;
      gas: number;
      total: number;
      misc?: number;
      change_from_prior_week?: number;
      date: string;
      source?: string;
    }
  • makeApiRequest helper function that performs HTTP requests with retry and exponential backoff, used by the rig count handler to fetch data.
    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;
    }
  • textResult helper function that builds a successful TextContent result.
    function textResult(text: string) {
      return {
        content: [{ type: "text" as const, text }],
      };
    }
Behavior4/5

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

No annotations exist, so the description fully covers behavior. It specifies that no parameters are needed and lists the return fields: oil rigs, gas rigs, total count, week-over-week change. No side effects or destructive actions are relevant.

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?

Extremely concise: three sentences with no wasted words. Purpose is front-loaded, and each sentence adds value.

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 the tool's simplicity (0 parameters, no annotations, no output schema), the description provides sufficient context: what it does, when to use, what it returns. Minor improvement could include data refresh frequency, but not required.

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 tool has zero parameters, and the description explicitly states 'No parameters needed.' Schema coverage is 100% with an empty object. Baseline 4 applies as per instructions.

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 'Get the latest US oil and gas rig count data (Baker Hughes)' with a specific verb and resource. It distinguishes from siblings by mentioning the specific data source and drilling activity context.

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 'Use when the user asks about drilling activity, rig counts, or oil field operations.' Provides clear context for when to use. Does not mention exclusions or alternatives, but given sibling tools, the usage scenario is well-defined.

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