Skip to main content
Glama
qubaomingg

@qubaomingg/stock-mcp

get-stock-alerts

Set up automated alerts for stock price movements based on percentage thresholds. Monitor specific stocks and receive notifications when prices change beyond your defined limits.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesStock symbol (e.g., IBM, AAPL)
thresholdNoPercentage threshold for price movement alerts (default: 5)

Implementation Reference

  • MCP tool handler for 'get-stock-alerts': calls getStockAlerts helper and handles response or error formatting.
      async ({ symbol, threshold = 5 }) => {
        try {
          const alerts = await getStockAlerts(symbol, threshold);
          return {
            content: [{ type: 'text', text: alerts }],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error generating stock alerts: ${
                  error instanceof Error ? error.message : String(error)
                }`,
              },
            ],
            isError: true,
          };
        }
      },
    );
  • Zod input schema defining parameters: symbol (required string) and threshold (optional number, default 5).
    {
      symbol: z.string().describe('Stock symbol (e.g., IBM, AAPL)'),
      threshold: z
        .number()
        .optional()
        .describe('Percentage threshold for price movement alerts (default: 5)'),
    },
  • src/index.ts:87-116 (registration)
    Full registration of the 'get-stock-alerts' tool including name, schema, and handler on the MCP server.
    server.tool(
      'get-stock-alerts',
      {
        symbol: z.string().describe('Stock symbol (e.g., IBM, AAPL)'),
        threshold: z
          .number()
          .optional()
          .describe('Percentage threshold for price movement alerts (default: 5)'),
      },
      async ({ symbol, threshold = 5 }) => {
        try {
          const alerts = await getStockAlerts(symbol, threshold);
          return {
            content: [{ type: 'text', text: alerts }],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error generating stock alerts: ${
                  error instanceof Error ? error.message : String(error)
                }`,
              },
            ],
            isError: true,
          };
        }
      },
    );
  • Helper function implementing the core logic: fetches daily data via Alpha Vantage API, computes percentage changes over last 10 days, generates alert text for movements exceeding threshold.
    export async function getStockAlerts(symbol: string | string[], threshold: number = 5): Promise<string> {
      try {
        // Ensure symbol is a string, not an array
        const symbolStr = Array.isArray(symbol) ? symbol[0] : symbol;
    
        // Get daily stock data for analysis
        const url = `${BASE_URL}?function=TIME_SERIES_DAILY&symbol=${symbolStr}&outputsize=compact&apikey=${API_KEY}`;
        const response = await axios.get(url);
    
        if (response.data['Error Message']) {
          throw new Error(response.data['Error Message']);
        }
    
        const timeSeries = response.data['Time Series (Daily)'];
    
        if (!timeSeries) {
          throw new Error('No time series data found in the response');
        }
    
        // Get dates sorted from newest to oldest
        const dates = Object.keys(timeSeries).sort().reverse();
    
        if (dates.length < 2) {
          return `Not enough historical data available for ${symbolStr} to generate alerts.`;
        }
    
        let alerts = `Stock Alerts for ${symbolStr.toUpperCase()} (${threshold}% threshold):\n\n`;
        let alertCount = 0;
    
        // Analyze the last 10 days (or less if not available)
        const daysToAnalyze = Math.min(10, dates.length - 1);
    
        for (let i = 0; i < daysToAnalyze; i++) {
          const currentDate = dates[i];
          const previousDate = dates[i + 1];
    
          const currentClose = parseFloat(timeSeries[currentDate]['4. close']);
          const previousClose = parseFloat(timeSeries[previousDate]['4. close']);
    
          // Calculate percentage change
          const percentChange =
            ((currentClose - previousClose) / previousClose) * 100;
          const absPercentChange = Math.abs(percentChange);
    
          // Check if change exceeds threshold
          if (absPercentChange >= threshold) {
            const direction = percentChange >= 0 ? 'increased' : 'decreased';
            alerts += `${currentDate}: Price ${direction} by ${absPercentChange.toFixed(
              2,
            )}% from ${previousClose} to ${currentClose}\n`;
            alertCount++;
          }
        }
    
        if (alertCount === 0) {
          alerts += `No significant price movements (>=${threshold}%) detected in the last ${daysToAnalyze} trading days.\n`;
        }
    
        return alerts;
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`API request failed: ${error.message}`);
        }
        throw error;
      }
    }
Behavior1/5

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

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

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

Completeness1/5

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

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/qubaomingg/stock-analysis-mcp'

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