Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- Dockerfile +4 -3
- README.md +1 -0
- app.py +409 -0
- requirements.txt +2 -1
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
@@ -13,6 +13,7 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 13 |
COPY edgar_client.py .
|
| 14 |
COPY financial_analyzer.py .
|
| 15 |
COPY mcp_server_fastmcp.py .
|
|
|
|
| 16 |
|
| 17 |
# Expose port
|
| 18 |
EXPOSE 7860
|
|
@@ -26,5 +27,5 @@ ENV HOST=0.0.0.0
|
|
| 26 |
# Health check
|
| 27 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 CMD curl -f http://localhost:7860/ || exit 1
|
| 28 |
|
| 29 |
-
# Run MCP
|
| 30 |
-
CMD ["python", "
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 13 |
COPY edgar_client.py .
|
| 14 |
COPY financial_analyzer.py .
|
| 15 |
COPY mcp_server_fastmcp.py .
|
| 16 |
+
COPY app.py .
|
| 17 |
|
| 18 |
# Expose port
|
| 19 |
EXPOSE 7860
|
|
|
|
| 27 |
# Health check
|
| 28 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 CMD curl -f http://localhost:7860/ || exit 1
|
| 29 |
|
| 30 |
+
# Run Gradio UI (which starts MCP server internally)
|
| 31 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -5,6 +5,7 @@ colorFrom: blue
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
app_port: 7860
|
|
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
|
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
app_port: 7860
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Gradio UI for SEC Financial Data MCP Server
|
| 3 |
+
Provides usage guide and examples for MCP clients
|
| 4 |
+
"""
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import subprocess
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# Start MCP server in background
|
| 10 |
+
mcp_process = None
|
| 11 |
+
|
| 12 |
+
def start_mcp_server():
|
| 13 |
+
"""Start the MCP server in background"""
|
| 14 |
+
global mcp_process
|
| 15 |
+
if mcp_process is None:
|
| 16 |
+
mcp_process = subprocess.Popen(
|
| 17 |
+
["python", "mcp_server_fastmcp.py"],
|
| 18 |
+
stdout=subprocess.PIPE,
|
| 19 |
+
stderr=subprocess.PIPE
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Start server on module load
|
| 23 |
+
start_mcp_server()
|
| 24 |
+
|
| 25 |
+
# Usage guide content
|
| 26 |
+
USAGE_GUIDE = """
|
| 27 |
+
# 📊 SEC Financial Data MCP Server
|
| 28 |
+
|
| 29 |
+
Welcome! This is a **Model Context Protocol (MCP)** server providing access to SEC EDGAR financial data.
|
| 30 |
+
|
| 31 |
+
## 🔗 MCP Endpoint
|
| 32 |
+
|
| 33 |
+
```
|
| 34 |
+
https://jc321-easyreportsmcpserver.hf.space/sse
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## 🛠️ Available Tools (7)
|
| 38 |
+
|
| 39 |
+
1. **search_company** - Search for a company by name
|
| 40 |
+
2. **get_company_info** - Get detailed company information
|
| 41 |
+
3. **get_company_filings** - Get list of SEC filings
|
| 42 |
+
4. **get_financial_data** - Get financial data for a specific period
|
| 43 |
+
5. **extract_financial_metrics** - Extract multi-year financial metrics
|
| 44 |
+
6. **get_latest_financial_data** - Get the most recent financial data
|
| 45 |
+
7. **advanced_search_company** - Advanced search supporting name/CIK
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
## 📝 How to Use
|
| 50 |
+
|
| 51 |
+
### Option 1: MCP Client (Recommended)
|
| 52 |
+
|
| 53 |
+
**Claude Desktop Configuration:**
|
| 54 |
+
|
| 55 |
+
Add to your `claude_desktop_config.json`:
|
| 56 |
+
|
| 57 |
+
```json
|
| 58 |
+
{
|
| 59 |
+
"mcpServers": {
|
| 60 |
+
"sec-financial-data": {
|
| 61 |
+
"url": "https://jc321-easyreportsmcpserver.hf.space/sse",
|
| 62 |
+
"transport": "sse"
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
**Then ask Claude:**
|
| 69 |
+
- "Search for Tesla's financial information"
|
| 70 |
+
- "Get Apple's latest financial data"
|
| 71 |
+
- "Show me Microsoft's revenue trends for the last 3 years"
|
| 72 |
+
|
| 73 |
+
### Option 2: Direct API Call
|
| 74 |
+
|
| 75 |
+
**Example: List Available Tools**
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
curl -X POST https://jc321-easyreportsmcpserver.hf.space/sse \\
|
| 79 |
+
-H "Content-Type: application/json" \\
|
| 80 |
+
-d '{
|
| 81 |
+
"jsonrpc": "2.0",
|
| 82 |
+
"method": "tools/list",
|
| 83 |
+
"id": 1
|
| 84 |
+
}'
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
**Example: Search Company**
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
curl -X POST https://jc321-easyreportsmcpserver.hf.space/sse \\
|
| 91 |
+
-H "Content-Type: application/json" \\
|
| 92 |
+
-d '{
|
| 93 |
+
"jsonrpc": "2.0",
|
| 94 |
+
"method": "tools/call",
|
| 95 |
+
"params": {
|
| 96 |
+
"name": "search_company",
|
| 97 |
+
"arguments": {
|
| 98 |
+
"company_name": "Tesla"
|
| 99 |
+
}
|
| 100 |
+
},
|
| 101 |
+
"id": 2
|
| 102 |
+
}'
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
**Example: Get 3-Year Financial Trends**
|
| 106 |
+
|
| 107 |
+
```bash
|
| 108 |
+
curl -X POST https://jc321-easyreportsmcpserver.hf.space/sse \\
|
| 109 |
+
-H "Content-Type: application/json" \\
|
| 110 |
+
-d '{
|
| 111 |
+
"jsonrpc": "2.0",
|
| 112 |
+
"method": "tools/call",
|
| 113 |
+
"params": {
|
| 114 |
+
"name": "extract_financial_metrics",
|
| 115 |
+
"arguments": {
|
| 116 |
+
"cik": "0001318605",
|
| 117 |
+
"years": 3
|
| 118 |
+
}
|
| 119 |
+
},
|
| 120 |
+
"id": 3
|
| 121 |
+
}'
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
## 🔑 Key Features
|
| 127 |
+
|
| 128 |
+
- ✅ **Pure JSON responses** - No emoji or formatting, easy to parse
|
| 129 |
+
- ✅ **Chronological ordering** - Data sorted newest first (FY → Q4 → Q3 → Q2 → Q1)
|
| 130 |
+
- ✅ **Comprehensive metrics** - Revenue, Net Income, EPS, Operating Expenses, Cash Flow
|
| 131 |
+
- ✅ **Real-time data** - Direct access to SEC EDGAR database
|
| 132 |
+
- ✅ **7 powerful tools** - Search, analyze, and extract financial data
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
## 📚 Tool Reference
|
| 137 |
+
|
| 138 |
+
### 1. search_company
|
| 139 |
+
Search for a company by name.
|
| 140 |
+
|
| 141 |
+
**Parameters:**
|
| 142 |
+
- `company_name` (string): Company name (e.g., "Microsoft", "Apple")
|
| 143 |
+
|
| 144 |
+
**Returns:** Company CIK, name, tickers, SIC code
|
| 145 |
+
|
| 146 |
+
### 2. get_company_info
|
| 147 |
+
Get detailed company information.
|
| 148 |
+
|
| 149 |
+
**Parameters:**
|
| 150 |
+
- `cik` (string): Company CIK code (10-digit format)
|
| 151 |
+
|
| 152 |
+
**Returns:** Full company details
|
| 153 |
+
|
| 154 |
+
### 3. get_company_filings
|
| 155 |
+
Get list of SEC filings.
|
| 156 |
+
|
| 157 |
+
**Parameters:**
|
| 158 |
+
- `cik` (string): Company CIK code
|
| 159 |
+
- `form_types` (array, optional): Filter by form types (e.g., ["10-K", "10-Q"])
|
| 160 |
+
|
| 161 |
+
**Returns:** List of filings with dates and links (max 20)
|
| 162 |
+
|
| 163 |
+
### 4. get_financial_data
|
| 164 |
+
Get financial data for a specific period.
|
| 165 |
+
|
| 166 |
+
**Parameters:**
|
| 167 |
+
- `cik` (string): Company CIK code
|
| 168 |
+
- `period` (string): Period in format "YYYY" or "YYYYQX" (e.g., "2024", "2024Q3")
|
| 169 |
+
|
| 170 |
+
**Returns:** Financial data for the period
|
| 171 |
+
|
| 172 |
+
### 5. extract_financial_metrics
|
| 173 |
+
Extract comprehensive financial metrics for multiple years.
|
| 174 |
+
|
| 175 |
+
**Parameters:**
|
| 176 |
+
- `cik` (string): Company CIK code
|
| 177 |
+
- `years` (integer): Number of recent years (1-10, default: 3)
|
| 178 |
+
|
| 179 |
+
**Returns:** Multi-year financial data with both annual and quarterly metrics
|
| 180 |
+
|
| 181 |
+
### 6. get_latest_financial_data
|
| 182 |
+
Get the most recent financial data available.
|
| 183 |
+
|
| 184 |
+
**Parameters:**
|
| 185 |
+
- `cik` (string): Company CIK code
|
| 186 |
+
|
| 187 |
+
**Returns:** Latest available financial data
|
| 188 |
+
|
| 189 |
+
### 7. advanced_search_company
|
| 190 |
+
Advanced search supporting both company name and CIK code.
|
| 191 |
+
|
| 192 |
+
**Parameters:**
|
| 193 |
+
- `company_input` (string): Company name, ticker, or CIK code
|
| 194 |
+
|
| 195 |
+
**Returns:** Company information
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
## 🌐 Data Source
|
| 200 |
+
|
| 201 |
+
All data is sourced from the **SEC EDGAR database** - the official financial disclosure system of the U.S. Securities and Exchange Commission.
|
| 202 |
+
|
| 203 |
+
## 📞 Support
|
| 204 |
+
|
| 205 |
+
For issues or questions, visit: [GitHub Repository](https://github.com/yourusername/EasyReportDateMCP)
|
| 206 |
+
|
| 207 |
+
---
|
| 208 |
+
|
| 209 |
+
**Status:** 🟢 Server Running | **Protocol:** MCP 2024-11-05 | **Transport:** SSE
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
EXAMPLE_CODE = """
|
| 213 |
+
# Python Example using MCP SDK
|
| 214 |
+
|
| 215 |
+
```python
|
| 216 |
+
from mcp import ClientSession, StdioServerParameters
|
| 217 |
+
from mcp.client.stdio import stdio_client
|
| 218 |
+
|
| 219 |
+
# Connect to MCP server
|
| 220 |
+
server_params = StdioServerParameters(
|
| 221 |
+
command="curl",
|
| 222 |
+
args=[
|
| 223 |
+
"-X", "POST",
|
| 224 |
+
"https://jc321-easyreportsmcpserver.hf.space/sse",
|
| 225 |
+
"-H", "Content-Type: application/json",
|
| 226 |
+
"-d", "@-"
|
| 227 |
+
]
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
async with stdio_client(server_params) as (read, write):
|
| 231 |
+
async with ClientSession(read, write) as session:
|
| 232 |
+
# List available tools
|
| 233 |
+
tools = await session.list_tools()
|
| 234 |
+
print(f"Available tools: {tools}")
|
| 235 |
+
|
| 236 |
+
# Search for a company
|
| 237 |
+
result = await session.call_tool(
|
| 238 |
+
"search_company",
|
| 239 |
+
arguments={"company_name": "Tesla"}
|
| 240 |
+
)
|
| 241 |
+
print(f"Company info: {result}")
|
| 242 |
+
|
| 243 |
+
# Get financial metrics
|
| 244 |
+
metrics = await session.call_tool(
|
| 245 |
+
"extract_financial_metrics",
|
| 246 |
+
arguments={"cik": "0001318605", "years": 3}
|
| 247 |
+
)
|
| 248 |
+
print(f"Financial data: {metrics}")
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
# JavaScript Example
|
| 252 |
+
|
| 253 |
+
```javascript
|
| 254 |
+
// Using SSE client
|
| 255 |
+
const evtSource = new EventSource(
|
| 256 |
+
'https://jc321-easyreportsmcpserver.hf.space/sse'
|
| 257 |
+
);
|
| 258 |
+
|
| 259 |
+
// Send request
|
| 260 |
+
fetch('https://jc321-easyreportsmcpserver.hf.space/sse', {
|
| 261 |
+
method: 'POST',
|
| 262 |
+
headers: { 'Content-Type': 'application/json' },
|
| 263 |
+
body: JSON.stringify({
|
| 264 |
+
jsonrpc: '2.0',
|
| 265 |
+
method: 'tools/call',
|
| 266 |
+
params: {
|
| 267 |
+
name: 'search_company',
|
| 268 |
+
arguments: { company_name: 'Apple' }
|
| 269 |
+
},
|
| 270 |
+
id: 1
|
| 271 |
+
})
|
| 272 |
+
})
|
| 273 |
+
.then(response => response.json())
|
| 274 |
+
.then(data => console.log(data));
|
| 275 |
+
```
|
| 276 |
+
"""
|
| 277 |
+
|
| 278 |
+
# Create Gradio interface
|
| 279 |
+
with gr.Blocks(title="SEC Financial Data MCP Server", theme=gr.themes.Soft()) as demo:
|
| 280 |
+
gr.Markdown("# 📊 SEC Financial Data MCP Server")
|
| 281 |
+
gr.Markdown("### Access real-time SEC EDGAR financial data via Model Context Protocol")
|
| 282 |
+
|
| 283 |
+
with gr.Tabs():
|
| 284 |
+
with gr.Tab("📖 Usage Guide"):
|
| 285 |
+
gr.Markdown(USAGE_GUIDE)
|
| 286 |
+
|
| 287 |
+
with gr.Tab("💻 Code Examples"):
|
| 288 |
+
gr.Markdown(EXAMPLE_CODE)
|
| 289 |
+
|
| 290 |
+
with gr.Tab("🧪 Quick Test"):
|
| 291 |
+
gr.Markdown("### Test the MCP Server")
|
| 292 |
+
|
| 293 |
+
with gr.Row():
|
| 294 |
+
with gr.Column():
|
| 295 |
+
test_method = gr.Dropdown(
|
| 296 |
+
choices=["tools/list", "search_company", "extract_financial_metrics"],
|
| 297 |
+
label="Select Test Method",
|
| 298 |
+
value="search_company"
|
| 299 |
+
)
|
| 300 |
+
company_name = gr.Textbox(
|
| 301 |
+
label="Company Name (for search_company)",
|
| 302 |
+
value="Tesla",
|
| 303 |
+
visible=True
|
| 304 |
+
)
|
| 305 |
+
cik_input = gr.Textbox(
|
| 306 |
+
label="CIK (for extract_financial_metrics)",
|
| 307 |
+
value="0001318605",
|
| 308 |
+
visible=False
|
| 309 |
+
)
|
| 310 |
+
years_input = gr.Number(
|
| 311 |
+
label="Years (for extract_financial_metrics)",
|
| 312 |
+
value=3,
|
| 313 |
+
visible=False
|
| 314 |
+
)
|
| 315 |
+
test_btn = gr.Button("🚀 Test", variant="primary")
|
| 316 |
+
|
| 317 |
+
with gr.Column():
|
| 318 |
+
result_output = gr.JSON(label="Response")
|
| 319 |
+
|
| 320 |
+
def update_inputs(method):
|
| 321 |
+
if method == "tools/list":
|
| 322 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 323 |
+
elif method == "search_company":
|
| 324 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 325 |
+
else: # extract_financial_metrics
|
| 326 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
|
| 327 |
+
|
| 328 |
+
test_method.change(
|
| 329 |
+
update_inputs,
|
| 330 |
+
inputs=[test_method],
|
| 331 |
+
outputs=[company_name, cik_input, years_input]
|
| 332 |
+
)
|
| 333 |
+
|
| 334 |
+
def test_mcp_call(method, company, cik, years):
|
| 335 |
+
import requests
|
| 336 |
+
import json
|
| 337 |
+
|
| 338 |
+
url = "https://jc321-easyreportsmcpserver.hf.space/sse"
|
| 339 |
+
|
| 340 |
+
if method == "tools/list":
|
| 341 |
+
payload = {
|
| 342 |
+
"jsonrpc": "2.0",
|
| 343 |
+
"method": "tools/list",
|
| 344 |
+
"id": 1
|
| 345 |
+
}
|
| 346 |
+
elif method == "search_company":
|
| 347 |
+
payload = {
|
| 348 |
+
"jsonrpc": "2.0",
|
| 349 |
+
"method": "tools/call",
|
| 350 |
+
"params": {
|
| 351 |
+
"name": "search_company",
|
| 352 |
+
"arguments": {"company_name": company}
|
| 353 |
+
},
|
| 354 |
+
"id": 2
|
| 355 |
+
}
|
| 356 |
+
else: # extract_financial_metrics
|
| 357 |
+
payload = {
|
| 358 |
+
"jsonrpc": "2.0",
|
| 359 |
+
"method": "tools/call",
|
| 360 |
+
"params": {
|
| 361 |
+
"name": "extract_financial_metrics",
|
| 362 |
+
"arguments": {"cik": cik, "years": int(years)}
|
| 363 |
+
},
|
| 364 |
+
"id": 3
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
try:
|
| 368 |
+
response = requests.post(url, json=payload, timeout=10)
|
| 369 |
+
return response.json()
|
| 370 |
+
except Exception as e:
|
| 371 |
+
return {"error": str(e)}
|
| 372 |
+
|
| 373 |
+
test_btn.click(
|
| 374 |
+
test_mcp_call,
|
| 375 |
+
inputs=[test_method, company_name, cik_input, years_input],
|
| 376 |
+
outputs=[result_output]
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
with gr.Tab("ℹ️ About"):
|
| 380 |
+
gr.Markdown("""
|
| 381 |
+
## About This Server
|
| 382 |
+
|
| 383 |
+
**Version:** 1.0.0 (FastMCP)
|
| 384 |
+
**Protocol:** Model Context Protocol (MCP) 2024-11-05
|
| 385 |
+
**Transport:** Server-Sent Events (SSE)
|
| 386 |
+
**Data Source:** SEC EDGAR Database
|
| 387 |
+
|
| 388 |
+
### Technology Stack
|
| 389 |
+
- **Framework:** Anthropic FastMCP SDK
|
| 390 |
+
- **API:** SEC EDGAR API
|
| 391 |
+
- **Deployment:** Hugging Face Spaces
|
| 392 |
+
|
| 393 |
+
### Features
|
| 394 |
+
- ✅ 7 financial data tools
|
| 395 |
+
- ✅ Real-time SEC EDGAR access
|
| 396 |
+
- ✅ Pure JSON responses
|
| 397 |
+
- ✅ Chronological data ordering
|
| 398 |
+
- ✅ Comprehensive financial metrics
|
| 399 |
+
|
| 400 |
+
### Maintained by
|
| 401 |
+
Juntao Peng (jtyxabc@gmail.com)
|
| 402 |
+
|
| 403 |
+
### License
|
| 404 |
+
MIT License
|
| 405 |
+
""")
|
| 406 |
+
|
| 407 |
+
# Launch the interface
|
| 408 |
+
if __name__ == "__main__":
|
| 409 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
|
| 2 |
fastapi==0.109.0
|
| 3 |
uvicorn[standard]>=0.30
|
| 4 |
pydantic>=2.10.1
|
| 5 |
sec-edgar-api==1.1.0
|
| 6 |
requests==2.31.0
|
|
|
|
|
|
| 1 |
+
mcp[cli]==1.2.0
|
| 2 |
fastapi==0.109.0
|
| 3 |
uvicorn[standard]>=0.30
|
| 4 |
pydantic>=2.10.1
|
| 5 |
sec-edgar-api==1.1.0
|
| 6 |
requests==2.31.0
|
| 7 |
+
gradio==4.44.0
|