Skip to main content
Glama
qqzhangyanhua

MCP Stock Assistant

get-market-index

Retrieve real-time overview of major Chinese market indices like the Shanghai and Shenzhen Composite to monitor current market performance.

Instructions

获取大盘指数概览信息,包括上证指数和深证成指等主要指数的实时数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/index.ts:113-140 (registration)
    MCP server.tool registration for 'get-market-index', with description, empty input schema, and inline handler that fetches and formats index data.
    server.tool(
      "get-market-index",
      "获取大盘指数概览信息,包括上证指数和深证成指等主要指数的实时数据",
      {},
      async () => {
        const indexData = await fetchMarketIndex();
    
        if (!indexData || indexData.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: "无法获取大盘指数数据,请稍后重试。",
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: formatIndexInfo(indexData),
            },
          ],
        };
      }
    );
  • Core helper function fetchMarketIndex that makes API request to INDEX_API for Shanghai (000001) and Shenzhen (399001) indices, parses response, and maps to IndexData array.
    export async function fetchMarketIndex(): Promise<IndexData[] | null> {
      try {
        const params = {
          fltt: "2",
          invt: "2",
          fields: "f1,f2,f3,f4,f12,f13,f14",
          secids: "1.000001,0.399001",
        };
    
        const response = await makeRequest(INDEX_API, params);
        const data = (await response.json()) as IndexResponse;
    
        if (data.rc !== 0 || !data.data || !data.data.diff) {
          throw new Error(data.msg || "获取指数数据失败");
        }
    
        const indexData: IndexData[] = data.data.diff.map((item) => ({
          code: item.f12,
          name: item.f14,
          price: item.f2,
          changePercent: item.f3,
          change: item.f4,
          volume: 0,
          amount: 0,
          time: new Date().toLocaleTimeString(),
        }));
    
        return indexData;
      } catch (error) {
        console.error("Error fetching market index:", error);
        return null;
      }
    }
  • Helper function to format IndexData array into a human-readable markdown table with emojis and statistics.
    export function formatIndexInfo(data: IndexData[]): string {
      let result = `
    📊 大盘指数信息
    
    `;
    
      result += "指数名称      当前点位    涨跌幅     涨跌点    成交量(手)   成交额(万)\n";
      result += "─".repeat(70) + "\n";
    
      for (const index of data) {
        const changeColor = index.changePercent >= 0 ? "📈" : "📉";
        const changeSign = index.change >= 0 ? "+" : "";
        result += `${index.name.padEnd(10)} ${formatPrice(index.price).padStart(8)} ${changeColor}${index.changePercent.toFixed(2)}%`.padEnd(20);
        result += ` ${changeSign}${formatPrice(index.change).padStart(7)} ${formatVolume(index.volume).padStart(10)} ${formatVolume(index.amount).padStart(10)}\n`;
      }
    
      result += `\n🕐 更新时间: ${data[0]?.time || new Date().toLocaleTimeString()}`;
    
      return result;
    }

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

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