JC321 commited on
Commit
1256221
·
verified ·
1 Parent(s): 605be71

Upload 2 files

Browse files
EasyReportDataMCP/edgar_client.py CHANGED
@@ -397,15 +397,25 @@ class EdgarDataClient:
397
  print("sec_edgar_api library not installed")
398
  return []
399
 
 
 
 
400
  # Convert list to tuple for caching (lists are not hashable)
401
  if form_types and isinstance(form_types, list):
402
  form_types = tuple(form_types)
403
 
404
  try:
405
  self._rate_limit()
 
 
 
406
  # Get company submissions (now has timeout protection)
407
  submissions = self.edgar.get_submissions(cik=cik)
408
 
 
 
 
 
409
  # Extract filing information
410
  filings = []
411
  recent = submissions.get("filings", {}).get("recent", {})
@@ -437,6 +447,11 @@ class EdgarDataClient:
437
 
438
  filings.append(filing)
439
 
 
 
 
 
 
440
  return filings
441
  except TimeoutError as e:
442
  print(f"Timeout getting company filings for CIK {cik}: {e}")
 
397
  print("sec_edgar_api library not installed")
398
  return []
399
 
400
+ # ✅ 添加调试日志
401
+ print(f"[DEBUG] get_company_filings called with CIK: {cik}, form_types: {form_types}")
402
+
403
  # Convert list to tuple for caching (lists are not hashable)
404
  if form_types and isinstance(form_types, list):
405
  form_types = tuple(form_types)
406
 
407
  try:
408
  self._rate_limit()
409
+ # ✅ 调试: 打印实际调用SEC API的CIK
410
+ print(f"[DEBUG] Calling SEC API get_submissions with CIK: {cik}")
411
+
412
  # Get company submissions (now has timeout protection)
413
  submissions = self.edgar.get_submissions(cik=cik)
414
 
415
+ # ✅ 调试: 打印返回的基本信息
416
+ print(f"[DEBUG] Got submissions for: {submissions.get('name', 'Unknown')}")
417
+ print(f"[DEBUG] Available form types in recent filings: {set(submissions.get('filings', {}).get('recent', {}).get('form', [])[:20])}")
418
+
419
  # Extract filing information
420
  filings = []
421
  recent = submissions.get("filings", {}).get("recent", {})
 
447
 
448
  filings.append(filing)
449
 
450
+ # ✅ 调试: 打印过滤后的结果
451
+ print(f"[DEBUG] After filtering, found {len(filings)} filings matching form_types: {form_types}")
452
+ if len(filings) > 0:
453
+ print(f"[DEBUG] First filing: {filings[0]}")
454
+
455
  return filings
456
  except TimeoutError as e:
457
  print(f"Timeout getting company filings for CIK {cik}: {e}")
EasyReportDataMCP/mcp_server_fastmcp.py CHANGED
@@ -213,15 +213,29 @@ def extract_financial_metrics(cik: str, years: int = 3) -> dict:
213
  if years < 1 or years > 10:
214
  return {"error": "Years parameter must be between 1 and 10"}
215
 
 
 
 
216
  # Check if company has filings (use tuple for caching)
217
  filings_10k = edgar_client.get_company_filings(cik, ('10-K',))
218
  filings_20f = edgar_client.get_company_filings(cik, ('20-F',))
 
 
 
 
 
 
 
 
219
  total_filings = len(filings_10k) + len(filings_20f)
220
 
221
  if total_filings == 0:
 
222
  return {
223
- "error": f"No annual filings found for CIK: {cik}",
224
- "suggestion": "Please check if the CIK is correct"
 
 
225
  }
226
 
227
  # Extract metrics
@@ -302,7 +316,13 @@ def get_latest_financial_data(cik: str) -> dict:
302
  if result and "period" in result:
303
  return result
304
  else:
305
- return {"error": f"No latest financial data found for CIK: {cik}"}
 
 
 
 
 
 
306
 
307
 
308
  @mcp.tool()
 
213
  if years < 1 or years > 10:
214
  return {"error": "Years parameter must be between 1 and 10"}
215
 
216
+ # ✅ 添加调试日志,查看实际CIK格式和查询结果
217
+ print(f"[DEBUG] extract_financial_metrics called with CIK: {cik}, type: {type(cik)}, years: {years}")
218
+
219
  # Check if company has filings (use tuple for caching)
220
  filings_10k = edgar_client.get_company_filings(cik, ('10-K',))
221
  filings_20f = edgar_client.get_company_filings(cik, ('20-F',))
222
+
223
+ # ✅ 打印查询结果
224
+ print(f"[DEBUG] Found {len(filings_10k)} 10-K filings, {len(filings_20f)} 20-F filings")
225
+ if len(filings_10k) > 0:
226
+ print(f"[DEBUG] Latest 10-K: {filings_10k[0]}")
227
+ if len(filings_20f) > 0:
228
+ print(f"[DEBUG] Latest 20-F: {filings_20f[0]}")
229
+
230
  total_filings = len(filings_10k) + len(filings_20f)
231
 
232
  if total_filings == 0:
233
+ # ✅ 提供更详细的错误信息,帮助用户了解问题
234
  return {
235
+ "error": f"No 10-K or 20-F annual filings found for CIK: {cik}",
236
+ "suggestion": "This company might not have filed 10-K or 20-F forms yet. Please verify the CIK is correct.",
237
+ "note": "Some companies may use different filing forms or may be newly listed.",
238
+ "cik": cik
239
  }
240
 
241
  # Extract metrics
 
316
  if result and "period" in result:
317
  return result
318
  else:
319
+ # 提供更有帮助的错误信息
320
+ return {
321
+ "error": f"No latest financial data found for CIK: {cik}",
322
+ "suggestion": "The company may not have recent 10-K or 20-F filings, or the data format may not be supported.",
323
+ "note": "Try using a different CIK or check if the company has filed recent annual reports.",
324
+ "cik": cik
325
+ }
326
 
327
 
328
  @mcp.tool()