Skip to main content
Glama
kinmeic

Stock MCP Server

by kinmeic

position_update

Update stock position records by modifying quantity or cost price for accurate portfolio tracking in the Stock MCP Server.

Instructions

更新持仓记录(数量或成本价)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes股票代码
marketYes市场
quantityNo持有数量
costPriceNo成本价

Implementation Reference

  • The updatePosition function that performs the actual position update logic - loads positions from file, finds the matching position by code and market, updates the quantity and/or costPrice, sets the updatedAt timestamp, saves back to file, and returns the updated position or null if not found.
    // 更新持仓 export function updatePosition( code: string, market: Market, updates: Partial<Pick<Position, 'quantity' | 'costPrice'>> ): Position | null { const positions = loadPositions(); const index = positions.findIndex(p => p.code === code && p.market === market); if (index === -1) { return null; } positions[index] = { ...positions[index], ...updates, updatedAt: new Date().toISOString(), }; savePositions(positions); return positions[index]; }
  • UpdatePositionSchema defines the input validation schema for position_update tool - requires code and market, with optional quantity and costPrice fields.
    const UpdatePositionSchema = z.object({ code: z.string().describe('股票代码'), market: z.enum(['sh', 'sz', 'hk', 'us']).describe('市场'), quantity: z.number().positive().optional().describe('持有数量'), costPrice: z.number().positive().optional().describe('成本价'), });
  • The MCP tool handler for position_update - validates input with UpdatePositionSchema, calls position.updatePosition with the parsed parameters, and returns the updated position or throws an error if not found.
    if (name === 'position_update') { const params = UpdatePositionSchema.parse(args); const result = position.updatePosition( params.code, params.market as Market, { quantity: params.quantity, costPrice: params.costPrice, } ); if (!result) { throw new Error('Position not found'); } return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • src/index.ts:158-171 (registration)
    Tool registration for position_update in the MCP server's ListToolsRequestSchema handler - defines the tool name, description, and input schema.
    { name: 'position_update', description: '更新持仓记录(数量或成本价)', inputSchema: { type: 'object', properties: { code: { type: 'string', description: '股票代码' }, market: { type: 'string', enum: ['sh', 'sz', 'hk', 'us'], description: '市场' }, quantity: { type: 'number', description: '持有数量' }, costPrice: { type: 'number', description: '成本价' }, }, required: ['code', 'market'], }, },
  • Position interface defining the structure of position data stored in positions.json - includes 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