get_company_info
Retrieve basic company information including financial and stock data by providing a stock code.
Instructions
获取公司基本信息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stock_code | Yes | 股票代码 |
Implementation Reference
- src/index.js:664-690 (handler)The handler function that executes the 'get_company_info' tool logic. It ensures login, initializes the Python client, queries the 'company_basic' table for company info by stock code, and returns the result.
async ({ stock_code }) => { try { const loginResult = await ensureLogin(); if (!loginResult.success) { return { content: [{ type: 'text', text: JSON.stringify(loginResult, null, 2) }], isError: true }; } const client = await initPythonClient(); // 尝试从公司基本信息表获取 const result = await client.call('query', { table_name: 'company_basic', columns: ['Stkcd', 'ShortName', 'Industry', 'ListDate', 'Province', 'City'], condition: `Stkcd='${stock_code}'`, limit: 1 }); if (result.success && result.data && result.data.length > 0) { return { content: [{ type: 'text', text: JSON.stringify(result.data[0], null, 2) }] }; } return { content: [{ type: 'text', text: JSON.stringify({ stock_code, message: '未找到公司信息' }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `获取公司信息错误: ${error.message}` }], isError: true }; } } ); - src/index.js:658-663 (schema)The input schema definition for 'get_company_info'. It specifies a single required parameter 'stock_code' of type string described as '股票代码' (stock code).
{ description: '获取公司基本信息', inputSchema: { stock_code: z.string().describe('股票代码'), }, }, - src/index.js:655-690 (registration)The registration of the tool 'get_company_info' on the MCP server using server.registerTool(), with its schema and handler.
// 11. 获取公司信息 (已实现) server.registerTool( 'get_company_info', { description: '获取公司基本信息', inputSchema: { stock_code: z.string().describe('股票代码'), }, }, async ({ stock_code }) => { try { const loginResult = await ensureLogin(); if (!loginResult.success) { return { content: [{ type: 'text', text: JSON.stringify(loginResult, null, 2) }], isError: true }; } const client = await initPythonClient(); // 尝试从公司基本信息表获取 const result = await client.call('query', { table_name: 'company_basic', columns: ['Stkcd', 'ShortName', 'Industry', 'ListDate', 'Province', 'City'], condition: `Stkcd='${stock_code}'`, limit: 1 }); if (result.success && result.data && result.data.length > 0) { return { content: [{ type: 'text', text: JSON.stringify(result.data[0], null, 2) }] }; } return { content: [{ type: 'text', text: JSON.stringify({ stock_code, message: '未找到公司信息' }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `获取公司信息错误: ${error.message}` }], isError: true }; } } );