Skip to main content
Glama
kinmeic

Stock MCP Server

by kinmeic

watch_add

Add stocks to your watchlist by specifying code, name, market, and reason for tracking. Monitor A-shares, Hong Kong, and US stocks for informed investment decisions.

Instructions

添加观察股票

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes股票代码
nameYes股票名称
reasonYes观察理由或目标
marketYes市场

Implementation Reference

  • The core implementation of addWatch function that adds a stock to the watch list. It loads existing data, checks for duplicates, creates a new WatchItem with timestamp, saves to watch.json file, and returns the new item.
    export function addWatch(
      code: string,
      name: string,
      reason: string,
      market: Market
    ): WatchItem {
      const watchList = loadWatchList();
    
      // 检查是否已存在
      const exists = watchList.some(item => item.code === code && item.market === market);
      if (exists) {
        throw new Error('Stock already in watch list');
      }
    
      const newItem: WatchItem = {
        code,
        name,
        reason,
        market,
        createdAt: new Date().toISOString(),
      };
    
      watchList.push(newItem);
      saveWatchList(watchList);
    
      return newItem;
    }
  • The MCP tool handler for watch_add that parses input arguments using AddWatchSchema, calls watch.addWatch() function with the parameters, and returns the result as formatted JSON.
    if (name === 'watch_add') {
      const params = AddWatchSchema.parse(args);
      const result = watch.addWatch(
        params.code,
        params.name,
        params.reason,
        params.market as Market
      );
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • src/index.ts:204-217 (registration)
    Tool registration for watch_add defining its name, description, input schema properties (code, name, reason, market), and required fields.
    {
      name: 'watch_add',
      description: '添加观察股票',
      inputSchema: {
        type: 'object',
        properties: {
          code: { type: 'string', description: '股票代码' },
          name: { type: 'string', description: '股票名称' },
          reason: { type: 'string', description: '观察理由或目标' },
          market: { type: 'string', enum: ['sh', 'sz', 'hk', 'us'], description: '市场' },
        },
        required: ['code', 'name', 'reason', 'market'],
      },
    },
  • Zod schema definition (AddWatchSchema) for input validation with required fields: code (string), name (string), reason (string), and market (enum: sh, sz, hk, us).
    const AddWatchSchema = z.object({
      code: z.string().describe('股票代码'),
      name: z.string().describe('股票名称'),
      reason: z.string().describe('观察理由或目标'),
      market: z.enum(['sh', 'sz', 'hk', 'us']).describe('市场'),
    });
  • Type definition for WatchItem interface defining the structure of watch list items with code, name, reason, market, and createdAt fields.
    export interface WatchItem {
      code: string;
      name: string;
      reason: string;
      market: Market;
      createdAt: string;
    }

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