Skip to main content
Glama
Xxx00xxX33

FinanceMCP

by Xxx00xxX33

company_performance_hk

Retrieve comprehensive financial performance data for Hong Kong-listed companies, including income statements, balance sheets, and cash flow statements with customizable date ranges and specific financial metrics.

Instructions

获取港股上市公司综合表现数据,包括利润表、资产负债表、现金流量表等财务报表数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ts_codeYes港股代码,如'00700.HK'表示腾讯控股,'00939.HK'表示建设银行
data_typeYes数据类型:income(利润表)、balance(资产负债表)、cashflow(现金流量表)
start_dateYes起始日期,格式为YYYYMMDD,如'20230101'
end_dateYes结束日期,格式为YYYYMMDD,如'20231231'
periodNo特定报告期,格式为YYYYMMDD,如'20231231'表示2023年年报。指定此参数时将忽略start_date和end_date
ind_nameNo指定财务科目名称,如'营业额'、'毛利'、'除税后溢利'等,不指定则返回全部科目

Implementation Reference

  • Core handler function that executes the tool logic: selects API endpoint based on data_type, fetches data from Tushare API, formats results using specialized formatters, handles errors.
    async run(args: { 
      ts_code: string; 
      data_type: string; 
      start_date: string;
      end_date: string;
      period?: string;
      ind_name?: string;
    }) {
      try {
        console.log('港股公司综合表现查询参数:', args);
        
        const TUSHARE_API_KEY = TUSHARE_CONFIG.API_TOKEN;
        const TUSHARE_API_URL = TUSHARE_CONFIG.API_URL;
        
        if (!TUSHARE_API_KEY) {
          throw new Error('请配置TUSHARE_TOKEN环境变量');
        }
    
        // 根据data_type选择对应的接口
        let apiInterface = '';
        let formatFunction: any = null;
        
        switch (args.data_type) {
          case 'income':
            apiInterface = 'hk_income';
            formatFunction = formatHkIncomeData;
            break;
          case 'balance':
            apiInterface = 'hk_balancesheet';
            formatFunction = formatHkBalanceData;
            break;
          case 'cashflow':
            apiInterface = 'hk_cashflow';
            formatFunction = formatHkCashflowData;
            break;
          default:
            throw new Error(`不支持的数据类型: ${args.data_type}`);
        }
    
        const result = await fetchHkFinancialData(
          apiInterface,
          args.ts_code,
          args.period,
          args.start_date,
          args.end_date,
          args.ind_name,
          TUSHARE_API_KEY,
          TUSHARE_API_URL
        );
    
        if (!result.data || result.data.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `# ${args.ts_code} 港股${getDataTypeName(args.data_type)}数据\n\n❌ 未找到相关数据,请检查股票代码或日期范围`
              }
            ]
          };
        }
    
        // 使用对应的格式化函数
        if (formatFunction) {
          const formattedResult = formatFunction(result.data, args.ts_code, args.data_type);
          return formattedResult;
        } else {
          // 如果没有实现格式化器,返回原始数据
          return {
            content: [
              {
                type: "text",
                text: `# ${args.ts_code} 港股${getDataTypeName(args.data_type)}数据\n\n⚠️ 格式化器待实现,以下为原始数据:\n\n${JSON.stringify(result.data, null, 2)}`
              }
            ]
          };
        }
    
      } catch (error) {
        console.error('港股公司业绩查询错误:', error);
        return {
          content: [
            {
              type: "text",
              text: `❌ 港股公司业绩查询失败: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Tool schema defining input parameters including required fields ts_code, data_type, start_date, end_date, and optional period, ind_name.
    name: "company_performance_hk",
    description: "获取港股上市公司综合表现数据,包括利润表、资产负债表、现金流量表等财务报表数据",
    parameters: {
      type: "object",
      properties: {
        ts_code: {
          type: "string",
          description: "港股代码,如'00700.HK'表示腾讯控股,'00939.HK'表示建设银行"
        },
        data_type: {
          type: "string",
          description: "数据类型:income(利润表)、balance(资产负债表)、cashflow(现金流量表)",
          enum: ["income", "balance", "cashflow"]
        },
        start_date: {
          type: "string",
          description: "起始日期,格式为YYYYMMDD,如'20230101'"
        },
        end_date: {
          type: "string",
          description: "结束日期,格式为YYYYMMDD,如'20231231'"
        },
        period: {
          type: "string",
          description: "特定报告期,格式为YYYYMMDD,如'20231231'表示2023年年报。指定此参数时将忽略start_date和end_date"
        },
        ind_name: {
          type: "string",
          description: "指定财务科目名称,如'营业额'、'毛利'、'除税后溢利'等,不指定则返回全部科目"
        }
      },
      required: ["ts_code", "data_type", "start_date", "end_date"]
    },
  • src/index.ts:234-238 (registration)
    Tool registration in the MCP stdio server's tools list, exposing name, description, and inputSchema.
    {
      name: companyPerformance_hk.name,
      description: companyPerformance_hk.description,
      inputSchema: companyPerformance_hk.parameters
    },
  • Tool registration in the MCP HTTP server's tools list, exposing name, description, and inputSchema.
    { name: companyPerformance_hk.name, description: companyPerformance_hk.description, inputSchema: companyPerformance_hk.parameters },
  • Helper function to fetch financial data from Tushare API, constructs request, handles response parsing and conversion from array to object format.
    async function fetchHkFinancialData(
      apiInterface: string,
      ts_code: string,
      period?: string,
      start_date?: string,
      end_date?: string,
      ind_name?: string,
      apiKey?: string,
      apiUrl?: string
    ): Promise<any> {
      const requestData: any = {
        api_name: apiInterface,
        token: apiKey,
        params: {
          ts_code: ts_code
        }
      };
    
      // 根据是否指定period来设置参数
      if (period) {
        requestData.params.period = period;
      } else if (start_date && end_date) {
        requestData.params.start_date = start_date;
        requestData.params.end_date = end_date;
      }
    
      // 如果指定了具体的财务科目
      if (ind_name) {
        requestData.params.ind_name = ind_name;
      }
    
      const response = await fetch(apiUrl!, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(requestData),
        signal: AbortSignal.timeout(TUSHARE_CONFIG.TIMEOUT)
      });
    
      if (!response.ok) {
        throw new Error(`Tushare API请求失败: ${response.status} ${response.statusText}`);
      }
    
      const data = await response.json();
      
      if (data.code !== 0) {
        throw new Error(`Tushare API错误: ${data.msg || '未知错误'}`);
      }
    
      // 将返回的数组格式转换为对象数组
      const items: any[] = [];
      if (data.data && data.data.items && data.data.items.length > 0) {
        const fields = data.data.fields;
        for (const item of data.data.items) {
          const obj: any = {};
          fields.forEach((field: string, index: number) => {
            obj[field] = item[index];
          });
          items.push(obj);
        }
      }
    
      return { data: items };
    } 
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it indicates this is a data retrieval tool (implied read-only), it doesn't address important behavioral aspects like authentication requirements, rate limits, data freshness, error conditions, or response format. For a financial data tool with no annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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

Conciseness4/5

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

The description is a single, efficient Chinese sentence that states the core purpose. It's appropriately sized for a data retrieval tool and front-loads the essential information. While it could potentially be more structured, there's no wasted verbiage or redundancy.

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?

For a financial data tool with 6 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what data format is returned, whether results are paginated, what happens when no data is found, or how to interpret the financial metrics. The combination of moderate complexity and lack of structured metadata means the description should provide more operational context.

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 description mentions financial statement types (income, balance, cashflow) which aligns with the 'data_type' parameter, but doesn't add meaningful semantic context beyond what's already in the schema descriptions. With 100% schema description coverage, the baseline is 3. The description doesn't explain parameter interactions (like how 'period' overrides date ranges) or provide examples of valid 'ind_name' values beyond the two examples given.

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 tool's purpose: '获取港股上市公司综合表现数据,包括利润表、资产负债表、现金流量表等财务报表数据' (Get comprehensive performance data for Hong Kong-listed companies, including financial statement data such as income statements, balance sheets, and cash flow statements). It specifies the verb ('获取' - get/retrieve) and resource (Hong Kong-listed company financial data), but doesn't explicitly differentiate from sibling tools like 'company_performance' and 'company_performance_us' beyond the 'hk' designation in the name.

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 sibling tools like 'company_performance' (likely for mainland China companies) or 'company_performance_us' (for US companies), nor does it specify use cases, prerequisites, or exclusions. The only contextual clue is the 'hk' in the tool name, but this isn't explained in the description.

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/Xxx00xxX33/FinanceMCP'

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