Skip to main content
Glama
ww11-max

CSMAR MCP Server

by ww11-max

get_stock_data

Retrieve stock trading data from CSMAR databases by stock code, date range, and frequency (daily, weekly, monthly). Access historical prices and volumes to support financial analysis.

Instructions

获取 CSMAR 股票交易数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stock_codeYes股票代码
start_dateYes开始日期 (YYYY-MM-DD)
end_dateYes结束日期 (YYYY-MM-DD)
frequencyNo数据频率

Implementation Reference

  • src/index.js:574-614 (registration)
    Registration of the 'get_stock_data' tool on the MCP server with input schema definition (stock_code, start_date, end_date, frequency) and the handler function that queries CSMAR stock data.
    // 9. 获取股票数据 (已实现)
    server.registerTool(
        'get_stock_data',
        {
            description: '获取 CSMAR 股票交易数据',
            inputSchema: {
                stock_code: z.string().describe('股票代码'),
                start_date: z.string().describe('开始日期 (YYYY-MM-DD)'),
                end_date: z.string().describe('结束日期 (YYYY-MM-DD)'),
                frequency: z.enum(['daily', 'weekly', 'monthly']).optional().describe('数据频率'),
            },
        },
        async ({ stock_code, start_date, end_date, frequency = 'daily' }) => {
            try {
                const loginResult = await ensureLogin();
                if (!loginResult.success) {
                    return { content: [{ type: 'text', text: JSON.stringify(loginResult, null, 2) }], isError: true };
                }
                
                // 映射频率参数
                const freqMap = { daily: 'D', weekly: 'W', monthly: 'M' };
                const freq = freqMap[frequency] || 'D';
                
                // 使用通用查询获取股票数据
                // 这里假设有一个股票日行情表,实际表名需要根据数据库确定
                const client = await initPythonClient();
                const result = await client.call('query', {
                    table_name: 'stock_daily',
                    columns: ['Stkcd', 'Trddt', 'Open', 'High', 'Low', 'Close', 'Vol', 'Amount'],
                    condition: `Stkcd='${stock_code}'`,
                    start_time: start_date,
                    end_time: end_date,
                    limit: 1000
                });
                
                return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
            } catch (error) {
                return { content: [{ type: 'text', text: `获取股票数据错误: ${error.message}` }], isError: true };
            }
        }
    );
  • The actual handler function for 'get_stock_data'. It calls ensureLogin(), maps frequency to 'D'/'W'/'M', calls the Python client to query table 'stock_daily' with columns (Stkcd, Trddt, Open, High, Low, Close, Vol, Amount), and returns the result.
    async ({ stock_code, start_date, end_date, frequency = 'daily' }) => {
        try {
            const loginResult = await ensureLogin();
            if (!loginResult.success) {
                return { content: [{ type: 'text', text: JSON.stringify(loginResult, null, 2) }], isError: true };
            }
            
            // 映射频率参数
            const freqMap = { daily: 'D', weekly: 'W', monthly: 'M' };
            const freq = freqMap[frequency] || 'D';
            
            // 使用通用查询获取股票数据
            // 这里假设有一个股票日行情表,实际表名需要根据数据库确定
            const client = await initPythonClient();
            const result = await client.call('query', {
                table_name: 'stock_daily',
                columns: ['Stkcd', 'Trddt', 'Open', 'High', 'Low', 'Close', 'Vol', 'Amount'],
                condition: `Stkcd='${stock_code}'`,
                start_time: start_date,
                end_time: end_date,
                limit: 1000
            });
            
            return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
        } catch (error) {
            return { content: [{ type: 'text', text: `获取股票数据错误: ${error.message}` }], isError: true };
        }
    }
  • Input schema for get_stock_data: stock_code (string), start_date (string YYYY-MM-DD), end_date (string YYYY-MM-DD), frequency (optional enum: daily/weekly/monthly).
    inputSchema: {
        stock_code: z.string().describe('股票代码'),
        start_date: z.string().describe('开始日期 (YYYY-MM-DD)'),
        end_date: z.string().describe('结束日期 (YYYY-MM-DD)'),
        frequency: z.enum(['daily', 'weekly', 'monthly']).optional().describe('数据频率'),
    },
Behavior2/5

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

No annotations are present, and the description does not disclose any behavioral traits such as return format, side effects, authentication requirements, or rate limits. For a tool with no output schema, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence, but it lacks any structural formatting. While minimal, it is not overly verbose, but the brevity sacrifices completeness.

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 has 4 parameters and no output schema, the description is too brief. It does not explain what the returned data represents, how errors are handled, or any constraints like date range limits.

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?

The input schema has 100% description coverage for all 4 parameters, each with Chinese descriptions. The tool description adds no additional meaning beyond what the schema provides, so baseline 3 is appropriate.

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 verb '获取' (get) and resource 'CSMAR 股票交易数据' (CSMAR stock trading data), distinguishing it from siblings like get_company_info and get_financial_data. However, it lacks specificity about what exactly constitutes 'stock trading data'.

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?

No guidance is provided on when to use this tool versus alternatives. Sibling tools such as get_financial_data or get_company_info exist, but the description does not help the agent decide which to choose.

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/ww11-max/CSMAR-MCP'

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