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;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states 'update' implying mutation, but lacks details on permissions needed, whether updates are reversible, rate limits, error conditions (e.g., invalid code/market), or what happens on success (e.g., returns confirmation). This is a significant gap for a mutation tool with zero annotation coverage.

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 sentence in Chinese ('更新持仓记录(数量或成本价)') that directly states the purpose with no wasted words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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?

Given the tool's complexity (mutation with 4 parameters, no annotations, no output schema), the description is incomplete. It lacks behavioral details (e.g., side effects, error handling), usage context, and output information, leaving significant gaps for an AI agent to understand how to invoke it correctly beyond basic parameter definitions.

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%, so the schema already documents all parameters (code, market, quantity, costPrice). The description adds minimal value by implying quantity and costPrice are updatable fields, but doesn't provide additional context like units, constraints (e.g., positive numbers), or interactions between parameters beyond what the schema specifies.

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 (update) and resource (position record) with specific fields mentioned (quantity or cost price). It distinguishes from siblings like position_add (add new) and position_remove (delete), though it doesn't explicitly contrast with position_update's exact scope versus other updates in the system.

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. It doesn't mention prerequisites (e.g., existing position), exclusions (e.g., cannot update both quantity and cost price simultaneously if that's a constraint), or refer to sibling tools like position_add for new records or position_get for retrieval.

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