Spaces:
Runtime error
Runtime error
| # API Enhancements Summary | |
| ## Overview | |
| The MCP Server has been enhanced to include all important methods from `FinancialAnalyzer`, providing both basic and advanced financial data analysis capabilities. | |
| ## Total API Endpoints: 9 | |
| ### Basic Endpoints (6) - Using `EdgarDataClient` | |
| 1. **POST /api/search_company** | |
| - Search company by name | |
| - Returns: CIK, name, ticker | |
| 2. **POST /api/get_company_info** | |
| - Get detailed company information | |
| - Returns: Full company details with SIC | |
| 3. **POST /api/get_company_filings** | |
| - Get company SEC filings | |
| - Supports: 10-K, 10-Q, 20-F, etc. | |
| 4. **POST /api/get_company_facts** | |
| - Get complete XBRL financial facts | |
| - Returns: Raw financial data | |
| 5. **POST /api/get_financial_data** | |
| - Get financial data for specific period | |
| - Supports: Annual (YYYY) and Quarterly (YYYYQX) | |
| 6. **GET /health** | |
| - Health check endpoint | |
| - Returns: Server status | |
| ### Advanced Endpoints (3) - Using `FinancialAnalyzer` β | |
| #### 7. POST /api/advanced_search | |
| **Purpose**: Intelligent company search supporting both name and CIK | |
| **From**: `FinancialAnalyzer.search_company()` | |
| **Request**: | |
| ```json | |
| { | |
| "company_input": "Apple" // or "0000320193" | |
| } | |
| ``` | |
| **Features**: | |
| - Auto-detects input type (name vs CIK) | |
| - Returns complete company information | |
| - More intelligent than basic search | |
| **Use Case**: When you don't know if user input is name or CIK | |
| --- | |
| #### 8. POST /api/extract_financial_metrics | |
| **Purpose**: Extract multi-year financial metrics (annual + quarterly) | |
| **From**: `FinancialAnalyzer.extract_financial_metrics()` | |
| **Request**: | |
| ```json | |
| { | |
| "cik": "0001045810", | |
| "years": 3 | |
| } | |
| ``` | |
| **Response**: | |
| ```json | |
| { | |
| "metrics": [ | |
| { | |
| "period": "2024", | |
| "total_revenue": 60922000000, | |
| "net_income": 29760000000, | |
| "earnings_per_share": 12.04, | |
| ... | |
| }, | |
| { | |
| "period": "2024Q4", | |
| ... | |
| }, | |
| { | |
| "period": "2024Q3", | |
| ... | |
| } | |
| ], | |
| "count": 15 | |
| } | |
| ``` | |
| **Features**: | |
| - Returns both annual and quarterly data | |
| - Automatically formats data | |
| - Sorted by period (newest first) | |
| - Configurable years (1-10) | |
| **Use Cases**: | |
| - Historical trend analysis | |
| - Multi-period comparison | |
| - Financial modeling | |
| - Data visualization | |
| --- | |
| #### 9. POST /api/get_latest_financial_data | |
| **Purpose**: Get the most recent annual financial data | |
| **From**: `FinancialAnalyzer.get_latest_financial_data()` | |
| **Request**: | |
| ```json | |
| { | |
| "cik": "0001045810" | |
| } | |
| ``` | |
| **Response**: | |
| ```json | |
| { | |
| "period": "2024", | |
| "total_revenue": 60922000000, | |
| "net_income": 29760000000, | |
| "earnings_per_share": 12.04, | |
| "operating_expenses": 11822000000, | |
| "operating_cash_flow": 28091000000, | |
| "source_url": "https://www.sec.gov/...", | |
| "source_form": "10-K" | |
| } | |
| ``` | |
| **Features**: | |
| - Automatically finds latest fiscal year | |
| - No need to know the year | |
| - Returns most recent 10-K or 20-F data | |
| **Use Cases**: | |
| - Quick company snapshot | |
| - Current financial position | |
| - Latest performance metrics | |
| --- | |
| ## Key Benefits | |
| ### 1. **Flexibility** | |
| - Basic endpoints for precise queries | |
| - Advanced endpoints for intelligent analysis | |
| ### 2. **Efficiency** | |
| - `extract_financial_metrics` - Get multiple years in one call | |
| - `get_latest_financial_data` - No need to determine fiscal year | |
| - `advanced_search` - Flexible input handling | |
| ### 3. **Complete Coverage** | |
| All important `FinancialAnalyzer` methods are now exposed: | |
| - β `search_company()` β `/api/advanced_search` | |
| - β `extract_financial_metrics()` β `/api/extract_financial_metrics` | |
| - β `get_latest_financial_data()` β `/api/get_latest_financial_data` | |
| ### 4. **Data Quality** | |
| - Automatic data formatting | |
| - Consistent response structure | |
| - Comprehensive error handling | |
| ## Comparison: Basic vs Advanced | |
| | Feature | Basic Endpoint | Advanced Endpoint | | |
| |---------|---------------|-------------------| | |
| | Company Search | `/api/search_company` | `/api/advanced_search` | | |
| | Input Type | Name only | Name or CIK | | |
| | Return Data | Basic (CIK, name, ticker) | Complete (includes SIC) | | |
| | | | | | |
| | Financial Data | `/api/get_financial_data` | `/api/extract_financial_metrics` | | |
| | Period | Single period | Multiple years | | |
| | Data Type | Annual OR quarterly | Annual AND quarterly | | |
| | Request Count | 1 per period | 1 for all periods | | |
| | | | | | |
| | Latest Data | `/api/get_financial_data` | `/api/get_latest_financial_data` | | |
| | Year Required | Yes (must specify) | No (auto-detects) | | |
| | Convenience | Manual | Automatic | | |
| ## Usage Examples | |
| ### Example 1: Quick Company Analysis | |
| ```python | |
| import requests | |
| BASE_URL = "https://YOUR_SPACE.hf.space" | |
| # Step 1: Advanced search (works with name or CIK) | |
| response = requests.post( | |
| f"{BASE_URL}/api/advanced_search", | |
| json={"company_input": "NVIDIA"} | |
| ) | |
| company = response.json() | |
| cik = company['cik'] | |
| # Step 2: Get latest data (no year needed!) | |
| response = requests.post( | |
| f"{BASE_URL}/api/get_latest_financial_data", | |
| json={"cik": cik} | |
| ) | |
| latest = response.json() | |
| print(f"Latest FY{latest['period']} Revenue: ${latest['total_revenue']:,.0f}") | |
| ``` | |
| ### Example 2: Multi-Year Trend Analysis | |
| ```python | |
| # Get 5 years of data in one call | |
| response = requests.post( | |
| f"{BASE_URL}/api/extract_financial_metrics", | |
| json={"cik": cik, "years": 5} | |
| ) | |
| data = response.json() | |
| # Analyze trends | |
| import pandas as pd | |
| df = pd.DataFrame(data['metrics']) | |
| annual_data = df[~df['period'].str.contains('Q')] # Filter annual only | |
| print(annual_data[['period', 'total_revenue', 'net_income']]) | |
| ``` | |
| ### Example 3: Flexible Search | |
| ```python | |
| # Works with either input type | |
| def search_company(input_str): | |
| response = requests.post( | |
| f"{BASE_URL}/api/advanced_search", | |
| json={"company_input": input_str} | |
| ) | |
| return response.json() | |
| # Both work! | |
| result1 = search_company("Apple") # By name | |
| result2 = search_company("0000320193") # By CIK | |
| ``` | |
| ## Documentation | |
| - **Complete API Examples**: See `mcp_client_examples.json` | |
| - **Interactive Testing**: Visit `/docs` (Swagger UI) | |
| - **Detailed Usage**: See `API_USAGE.md` | |
| ## Summary | |
| The MCP Server now provides **9 comprehensive API endpoints** covering: | |
| - β Basic data retrieval (EdgarDataClient) | |
| - β Advanced analysis (FinancialAnalyzer) | |
| - β Flexible search options | |
| - β Multi-year data extraction | |
| - β Automatic latest data retrieval | |
| All important functionality from both `edgar_client.py` and `financial_analyzer.py` is now accessible via RESTful APIs! π | |