Skip to main content
Glama
kinmeic

Stock MCP Server

by kinmeic

position_add

Add a new stock position to your portfolio by specifying code, quantity, cost price, currency, and market for tracking investments.

Instructions

添加持仓记录

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes股票代码
nameYes股票名称
quantityYes持有数量
costPriceYes成本价
currencyYes货币单位,如 CNY、HKD、USD
marketYes市场

Implementation Reference

  • The core implementation of addPosition function that creates a new position record, loads existing positions from JSON file, creates a new Position object with timestamp, appends to the array, saves back to file, and returns the new position.
    export function addPosition( code: string, name: string, quantity: number, costPrice: number, currency: string, market: Market ): Position { const positions = loadPositions(); const now = new Date().toISOString(); const newPosition: Position = { code, name, quantity, costPrice, currency, market, createdAt: now, updatedAt: now, }; positions.push(newPosition); savePositions(positions); return newPosition; }
  • src/index.ts:304-322 (registration)
    The request handler for position_add tool in CallToolRequestSchema that validates arguments using AddPositionSchema, calls position.addPosition with parsed parameters, and returns the result as JSON.
    if (name === 'position_add') { const params = AddPositionSchema.parse(args); const result = position.addPosition( params.code, params.name, params.quantity, params.costPrice, params.currency, params.market as Market ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • Zod validation schema AddPositionSchema that defines the expected input structure for position_add with fields: code, name, quantity, costPrice, currency, and market.
    const AddPositionSchema = z.object({ code: z.string().describe('股票代码'), name: z.string().describe('股票名称'), quantity: z.number().positive().describe('持有数量'), costPrice: z.number().positive().describe('成本价'), currency: z.string().describe('货币单位,如 CNY、HKD、USD'), market: z.enum(['sh', 'sz', 'hk', 'us']).describe('市场'), });
  • src/index.ts:142-157 (registration)
    Tool registration for position_add in ListToolsRequestSchema that exposes the tool to MCP clients with name, description, and input schema definition.
    { name: 'position_add', description: '添加持仓记录', inputSchema: { type: 'object', properties: { code: { type: 'string', description: '股票代码' }, name: { type: 'string', description: '股票名称' }, quantity: { type: 'number', description: '持有数量' }, costPrice: { type: 'number', description: '成本价' }, currency: { type: 'string', description: '货币单位,如 CNY、HKD、USD' }, market: { type: 'string', enum: ['sh', 'sz', 'hk', 'us'], description: '市场' }, }, required: ['code', 'name', 'quantity', 'costPrice', 'currency', 'market'], }, },
  • The Position interface type definition that defines the structure of position objects including code, name, quantity, costPrice, currency, market, createdAt, and updatedAt fields.
    export interface Position { code: string; name: string; quantity: number; costPrice: number; currency: string; market: Market; createdAt: string; updatedAt: 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