Skip to main content
Glama
kinmeic

Stock MCP Server

by kinmeic

stock_get_batch

Retrieve real-time market data for multiple stocks simultaneously to monitor portfolio performance across A-shares, Hong Kong, and US markets.

Instructions

批量获取多只股票实时行情数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stocksYes股票列表

Implementation Reference

  • Handler for stock_get_batch tool: validates input using GetStocksSchema, maps the stocks array, calls fetchStocks, and returns JSON-formatted stock data
    if (name === 'stock_get_batch') {
      const params = GetStocksSchema.parse(args);
      const stocks = params.stocks.map(s => ({
        code: s.code,
        market: s.market as Market
      }));
      const data = await fetchStocks(stocks);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(data, null, 2),
          },
        ],
      };
    }
  • GetStocksSchema: Zod validation schema defining the input structure for batch stock fetching (array of stock objects with code and market)
    const GetStocksSchema = z.object({
      stocks: z.array(z.object({
        code: z.string(),
        market: z.enum(['sh', 'sz', 'hk', 'us']),
      })).min(1).describe('股票列表'),
    });
  • src/index.ts:121-141 (registration)
    Tool registration: Registers stock_get_batch in the MCP server's tool list with description and input schema definition
      name: 'stock_get_batch',
      description: '批量获取多只股票实时行情数据',
      inputSchema: {
        type: 'object',
        properties: {
          stocks: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                code: { type: 'string' },
                market: { type: 'string', enum: ['sh', 'sz', 'hk', 'us'] },
              },
              required: ['code', 'market'],
            },
            description: '股票列表',
          },
        },
        required: ['stocks'],
      },
    },
  • fetchStocks implementation: Iterates through stock codes, fetches each stock individually using fetchStock, and returns array of StockData (continues on error for individual stocks)
    export async function fetchStocks(codes: Array<{ code: string; market: Market }>): Promise<StockData[]> {
      const results: StockData[] = [];
    
      for (const { code, market } of codes) {
        try {
          const data = await fetchStock(code, market);
          results.push(data);
        } catch (error) {
          console.error(`Failed to fetch ${market}${code}:`, error);
        }
      }
    
      return results;
    }
  • Type definitions: Market type, StockPrefix, AStockData, HKStockData, USStockData, and unified StockData type used by fetchStocks
    // 股票市场类型
    export type Market = 'sh' | 'sz' | 'hk' | 'us';
    
    // 股票代码前缀
    export type StockPrefix = 'sh' | 'sz' | 'r_hk' | 's_us';
    
    // A股解析后的数据
    export interface AStockData {
      market: 'sh' | 'sz';
      name: string;
      code: string;
      currentPrice: number;
      yesterdayClose: number;
      open: number;
      volume: number;
      outside: number;
      inside: number;
      datetime: string;
      change: number;
      changePercent: number;
      high: number;
      low: number;
      amount: number;
      turnoverRate: number;    // 38 换手率
      peTtm: number;           // 39 市盈率TTM
      amplitude: number;      // 43 振幅
      totalMarketCap: number; // 44 总市值(亿)
      floatMarketCap: number;  // 45 流通市值(亿)
      volumeRatio: number;     // 49 量比
      avgPrice: number;        // 51 均价
      peDynamic: number;       // 52 市盈率(动)
      peStatic: number;        // 53 市盈率(静)
      floatingShares: number;  // 72 流通股
      totalShares: number;     // 73 总股本
      currency: string;       // 82 货币
      bidAsk?: {
        asks: Array<{ price: number; volume: number }>;
        bids: Array<{ price: number; volume: number }>;
      };
    }
    
    // 港股解析后的数据
    export interface HKStockData {
      market: 'hk';
      name: string;
      code: string;
      currentPrice: number;
      yesterdayClose: number;
      open: number;
      volume: number;
      datetime: string;
      change: number;
      changePercent: number;
      high: number;
      low: number;
      amount: number;
      pe: number;
      floatingShares: number;
      totalShares: number;
      currency: string;
    }
    
    // 美股解析后的数据
    export interface USStockData {
      market: 'us';
      name: string;
      code: string;
      currentPrice: number;
      change: number;
      changePercent: number;
      volume: number;
      amount: number;
      marketCap?: number;
      currency: string;
    }
    
    // 统一返回类型
    export type StockData = AStockData | HKStockData | USStockData;
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose rate limits, authentication needs, data freshness guarantees, error handling, or response format. '实时行情数据' implies real-time data but doesn't specify update frequency or latency.

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 Chinese phrase that directly conveys the core functionality without any wasted words. It's appropriately sized for a straightforward batch data retrieval tool.

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

Completeness2/5

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

For a data retrieval tool with no annotations and no output schema, the description is insufficient. It doesn't explain what data is returned (e.g., price, volume, change), format, error conditions, or limitations (e.g., maximum batch size). The context signals show minimal parameter complexity but the behavioral aspects are undocumented.

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?

Schema description coverage is 100% with the parameter 'stocks' documented as '股票列表'. The description adds no additional parameter semantics beyond what's in the schema. The baseline is 3 since the schema adequately covers the single parameter.

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 action (获取 - get/fetch) and resource (多只股票实时行情数据 - multiple stocks' real-time market data). It distinguishes from sibling 'stock_get' by specifying batch operation, though it doesn't explicitly mention how it differs from other stock-related tools that might not exist.

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 like 'stock_get' (single stock) or other position/watch tools. It doesn't mention prerequisites, limitations, or typical use cases for batch versus individual queries.

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

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