Skip to main content
Glama
lordbasilaiassistant-sudo

base-price-oracle-mcp

get_price_history

Retrieve historical price data for tokens on Base by querying DEX pool swap events. Specify token address, time intervals, and data points to analyze price trends.

Instructions

Get recent price data points by querying swap events from DEX pools

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
token_addressYesToken contract address on Base
periodsNoNumber of data points to return
intervalNoTime interval between points (e.g. 1h, 15m, 1d)1h

Implementation Reference

  • The tool `get_price_history` is defined and implemented here as an MCP tool, which queries DEX pools for recent swap events to generate price history.
    server.tool(
      "get_price_history",
      "Get recent price data points by querying swap events from DEX pools",
      {
        token_address: z.string().describe("Token contract address on Base"),
        periods: z.number().default(24).describe("Number of data points to return"),
        interval: z.string().default("1h").describe("Time interval between points (e.g. 1h, 15m, 1d)"),
      },
      async ({ token_address, periods, interval }) => {
        try {
          const quoteAddress = WETH;
          const [tokenDecimals, quoteDecimals, tokenSymbol] = await Promise.all([
            getTokenDecimals(token_address),
            getTokenDecimals(quoteAddress),
            getTokenSymbol(token_address),
          ]);
    
          const pools = await findAllPools(token_address, quoteAddress);
          if (pools.length === 0) {
            return { content: [{ type: "text" as const, text: `No DEX pools found for ${token_address} on Base.` }] };
          }
    
          // Use the pool with most liquidity (V2: highest reserves, V3: highest liquidity)
          const bestPool = pools[0];
          const blocksPerInterval = intervalToBlocks(interval);
          const totalBlocks = blocksPerInterval * periods;
    
          // Cap at ~50000 blocks to avoid RPC limits
          const lookback = Math.min(totalBlocks, 50000);
          const swaps = await getSwapHistory(bestPool, tokenDecimals, quoteDecimals, lookback);
    
          if (swaps.length === 0) {
            // Fall back to current price only
            const currentPrice = calculatePrice(bestPool, tokenDecimals, quoteDecimals);
            return {
              content: [{
                type: "text" as const,
                text: JSON.stringify({
                  token: token_address,
                  symbol: tokenSymbol,
                  message: "No recent swap events found. Current spot price from reserves:",
                  currentPrice: formatEth(currentPrice),
                  dex: bestPool.dex,
                }, null, 2),
              }],
            };
          }
    
          // Bucket swaps into intervals
          const now = swaps[swaps.length - 1].timestamp;
          const intervalSeconds = blocksPerInterval * 2; // 2s per block
          const buckets: PricePoint[][] = [];
    
          for (let i = 0; i < periods; i++) {
            const bucketEnd = now - i * intervalSeconds;
            const bucketStart = bucketEnd - intervalSeconds;
            const bucketSwaps = swaps.filter(
              (s) => s.timestamp > bucketStart && s.timestamp <= bucketEnd
            );
            buckets.unshift(bucketSwaps);
          }
    
          const dataPoints = buckets.map((bucket, i) => {
            const time = now - (periods - 1 - i) * intervalSeconds;
            if (bucket.length === 0) {
              return { timestamp: time, price: null, swapCount: 0 };
            }
            const avgPrice = bucket.reduce((s, p) => s + p.price, 0) / bucket.length;
            return {
              timestamp: time,
              price: formatEth(avgPrice),
              swapCount: bucket.length,
            };
          });
    
          return {
            content: [{
              type: "text" as const,
              text: JSON.stringify({
                token: token_address,
                symbol: tokenSymbol,
                dex: bestPool.dex,
                interval,
                periods: dataPoints.length,
                totalSwaps: swaps.length,
                data: dataPoints,
              }, null, 2),
            }],
          };
        } catch (err: unknown) {
          const msg = err instanceof Error ? err.message : String(err);
          return { content: [{ type: "text" as const, text: `Error: ${msg}` }] };
        }
      }
    );
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 querying swap events from DEX pools, which implies a read-only operation, but it doesn't clarify aspects like rate limits, authentication needs, data freshness, or potential errors. For a tool with no annotations, this leaves significant gaps in understanding its 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 directly states the tool's purpose without unnecessary words. It's front-loaded with the core action and resource, making it easy to understand at a glance. Every part of the sentence contributes to clarifying the tool's function.

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

Completeness3/5

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

Given the tool's complexity (fetching historical price data), lack of annotations, and no output schema, the description is moderately complete. It explains the data source (swap events from DEX pools) but doesn't cover return values, error handling, or performance considerations. For a tool with three parameters and no structured output, it should provide more context to be fully helpful.

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%, meaning all parameters are well-documented in the schema itself. The description doesn't add any extra meaning beyond the schema, such as explaining how 'periods' and 'interval' interact to define the time range or providing examples of valid 'interval' values. With high schema coverage, the baseline score of 3 is appropriate.

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 ('recent price data points'), and it explains the mechanism ('by querying swap events from DEX pools'). However, it doesn't explicitly differentiate this tool from sibling tools like 'get_token_price' or 'compare_prices', which likely serve related but distinct purposes in price analysis.

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. It doesn't mention scenarios where this tool is preferred over siblings like 'get_token_price' (which might fetch a single price) or 'compare_prices' (which might compare multiple tokens), nor does it specify prerequisites or exclusions for usage.

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/lordbasilaiassistant-sudo/base-price-oracle-mcp'

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