Skip to main content
Glama
guangxiangdebizi

FinanceMCP

company_performance_us

Retrieve comprehensive U.S. company performance data, including income statements, balance sheets, cash flow, and financial metrics, for informed investment decisions. Analyze specific periods or date ranges with ease.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
data_typeYes数据类型:income(利润表)、balance(资产负债表)、cashflow(现金流量表)、indicator(财务指标)
end_dateYes结束日期,格式为YYYYMMDD,如'20231231'
periodNo特定报告期,格式为YYYYMMDD,如'20231231'表示2023年年报。指定此参数时将忽略start_date和end_date
start_dateYes起始日期,格式为YYYYMMDD,如'20230101'
ts_codeYes美股代码,如'NVDA'表示英伟达,'AAPL'表示苹果,'TSLA'表示特斯拉

Implementation Reference

  • The main execution handler for the 'company_performance_us' tool. Fetches US stock financial data (income, balance, cashflow, indicators) from Tushare API based on input parameters, applies appropriate formatters, and returns formatted markdown content or error.
    async run(args: { 
      ts_code: string; 
      data_type: string; 
      start_date: string;
      end_date: string;
      period?: 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 = 'us_income';
            formatFunction = formatUsIncomeData;
            break;
          case 'balance':
            apiInterface = 'us_balancesheet';
            formatFunction = formatUsBalanceData;
            break;
          case 'cashflow':
            apiInterface = 'us_cashflow';
            formatFunction = formatUsCashflowData;
            break;
          case 'indicator':
            apiInterface = 'us_fina_indicator';
            formatFunction = formatUsIndicatorData;
            break;
          default:
            throw new Error(`不支持的数据类型: ${args.data_type}`);
        }
    
        const result = await fetchUsFinancialData(
          apiInterface,
          args.ts_code,
          args.period,
          args.start_date,
          args.end_date,
          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
        };
      }
    }
  • Input schema defining parameters for the tool: ts_code (required stock code), data_type (enum: income/balance/cashflow/indicator), date ranges, and optional period.
    parameters: {
      type: "object",
      properties: {
        ts_code: {
          type: "string",
          description: "美股代码,如'NVDA'表示英伟达,'AAPL'表示苹果,'TSLA'表示特斯拉"
        },
        data_type: {
          type: "string",
          description: "数据类型:income(利润表)、balance(资产负债表)、cashflow(现金流量表)、indicator(财务指标)",
          enum: ["income", "balance", "cashflow", "indicator"]
        },
        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"
        }
      },
      required: ["ts_code", "data_type", "start_date", "end_date"]
    },
  • src/index.ts:338-345 (registration)
    Registration and dispatch in the stdio MCP server's CallToolRequestSchema handler, extracting args and calling the tool's run method.
    case "company_performance_us": {
      const ts_code = String(request.params.arguments?.ts_code);
      const data_type = String(request.params.arguments?.data_type);
      const start_date = String(request.params.arguments?.start_date);
      const end_date = String(request.params.arguments?.end_date);
      const period = request.params.arguments?.period ? String(request.params.arguments.period) : undefined;
      return await companyPerformance_us.run({ ts_code, data_type, start_date, end_date, period });
    }
  • Registration and dispatch in the HTTP MCP server's tools/call handler, extracting args and calling the tool's run method.
    case 'company_performance_us':
      return await companyPerformance_us.run({
        ts_code: String(args?.ts_code),
        data_type: String(args?.data_type),
        start_date: String(args?.start_date),
        end_date: String(args?.end_date),
        period: args?.period ? String(args.period) : undefined,
      });
  • Helper function to make POST request to Tushare API for US financial data, handles params construction, response parsing, and converts array format to object array.
    async function fetchUsFinancialData(
      apiInterface: string,
      ts_code: string,
      period?: string,
      start_date?: string,
      end_date?: 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;
      }
    
      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 full burden. It implies a read-only operation by stating '获取' (get/retrieve), but doesn't disclose behavioral traits like authentication needs, rate limits, data freshness, error handling, or output format. For a tool with 5 parameters and no annotations, this is a significant gap in transparency.

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 sentence that front-loads the core purpose. It wastes no words but could be slightly more structured by separating data types for clarity. Every part earns its place, though it lacks completeness for a tool with no annotations or output schema.

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 complexity (5 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the return values, data structure, or behavioral context needed for effective use. While the schema covers parameters well, the overall context for a financial data tool with multiple data types is insufficient.

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%, providing detailed parameter documentation. The description adds no additional parameter semantics beyond what's in the schema, such as explaining interactions between parameters or data format examples. With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

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 retrieves comprehensive performance data for US-listed companies, including income statements, balance sheets, cash flow statements, and financial indicators. It specifies the resource (US-listed companies) and data types, but doesn't explicitly differentiate from sibling tools like 'company_performance' or 'company_performance_hk' beyond the 'us' 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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites, exclusions, or compare it to sibling tools like 'company_performance' or 'stock_data', leaving the agent to infer usage from the name and parameters alone.

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

Related 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/guangxiangdebizi/FinanceMCP'

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