JC321 commited on
Commit
88cda27
·
verified ·
1 Parent(s): a2a2dc9

Upload easy_financial_mcp.py

Browse files
EasyFinancialAgent/easy_financial_mcp.py CHANGED
@@ -115,18 +115,8 @@ def extract_financial_metrics(cik: str, years: int = 3) -> dict:
115
  if years < 1 or years > 10:
116
  return {"error": "Years parameter must be between 1 and 10"}
117
 
118
- # Check if company has filings (use tuple for caching)
119
- filings_10k = edgar_client.get_company_filings(cik, ('"10-K"',))
120
- filings_20f = edgar_client.get_company_filings(cik, ('"20-F"',))
121
- total_filings = len(filings_10k) + len(filings_20f)
122
-
123
- if total_filings == 0:
124
- return {
125
- "error": f"No annual filings found for CIK: {cik}",
126
- "suggestion": "Please check if the CIK is correct"
127
- }
128
-
129
- # Extract metrics
130
  metrics = financial_analyzer.extract_financial_metrics(cik, years)
131
 
132
  if metrics:
@@ -136,30 +126,11 @@ def extract_financial_metrics(cik: str, years: int = 3) -> dict:
136
  "data": formatted
137
  }
138
  else:
139
- # Return debug info
140
- debug_info = {
141
- "error": f"No financial metrics extracted for CIK: {cik}",
142
- "debug": {
143
- "cik": cik,
144
- "years_requested": years,
145
- "filings_found": {
146
- "10-K": len(filings_10k),
147
- "20-F": len(filings_20f)
148
- },
149
- "latest_filings": []
150
- },
151
- "suggestion": "Try using get_latest_financial_data or get_financial_data with a specific period"
152
  }
153
-
154
- # Add latest filing dates
155
- all_filings = filings_10k + filings_20f
156
- for filing in all_filings[:5]:
157
- debug_info["debug"]["latest_filings"].append({
158
- "form": filing.get("form_type"),
159
- "date": filing.get("filing_date")
160
- })
161
-
162
- return debug_info
163
 
164
 
165
  @mcp.tool()
 
115
  if years < 1 or years > 10:
116
  return {"error": "Years parameter must be between 1 and 10"}
117
 
118
+ # 直接调用 extract_financial_metrics,不做预检查
119
+ # extract_financial_metrics 内部会处理所有情况(10-K, 20-F, 数据缺失等)
 
 
 
 
 
 
 
 
 
 
120
  metrics = financial_analyzer.extract_financial_metrics(cik, years)
121
 
122
  if metrics:
 
126
  "data": formatted
127
  }
128
  else:
129
+ # 如果没有数据,返回简洁错误信息
130
+ return {
131
+ "error": f"No financial metrics found for CIK: {cik}",
132
+ "suggestion": "Please verify the CIK is correct or try get_latest_financial_data"
 
 
 
 
 
 
 
 
 
133
  }
 
 
 
 
 
 
 
 
 
 
134
 
135
 
136
  @mcp.tool()