Magnificent 7金融分析师——MCP服务器
一 MCP(模型上下文协议) 服务器 为AI助手提供结构化的年度报告数据访问权限 华丽7 科技公司:
| Ticker | 公司 |
|---|---|
| AAPL | 苹果 |
| 微软 | |
| GOOGL | 字母表 |
| 亚马逊 | |
| NVDA | 英伟达 |
| META | META |
| 特斯拉 |
______________________________________________________________________
建筑
mcp_server/
├── main.py ← FastMCP app, uvicorn entrypoint, lifespan hooks
├── auth.py ← JWT middleware + UserContext helpers
├── config.py ← Pydantic-settings (reads .env)
├── requirements.txt
├── .env ← secrets (gitignored)
├── .env.example ← template to copy
│
├── tools/
│ ├── vector_tools.py ← search_report_text, search_report_tables
│ ├── financial_tools.py ← get_financial_metric, compare_*
│ ├── graph_tools.py ← diagnostic and utility tools for Neo4j graph
│ ├── event_tools.py ← get_key_developments
│ └── people_tools.py ← get_key_persons
│
└── services/
├── pinecone_service.py ← Pinecone index wrapper
├── neo4j_service.py ← Neo4j Cypher query wrapper
└── auth_service.py ← (placeholder — auth removed)知识库
| 存储 | 内容 |
|---|---|
| 松果 | 从10-K表格年度报告中分块的段落文本和Markdown表格。文本块带有 text 元数据密钥;桌块携带 table_markdown 钥匙。 |
| Neo4j | 结构化财务事实(Company → Document → FiscalYear → Fact → Metric)、关键人物和从年度报告中提取的关键发展。 |
______________________________________________________________________
设置
1.克隆并安装依赖项
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt2.配置机密
cp .env.example .env
# Edit .env with your real credentials3.运行服务器
# Development — run directly
fastmcp run mcp_server/main.py服务器启动于 http://localhost:8000 默认情况下。
4.健康检查
curl http://localhost:8000/health
# {"status": "ok", "server": "mag7-financial-analyst"}______________________________________________________________________
连接MCP客户端
克劳德桌面/Claude.ai
将服务器添加到MCP配置文件中(通常 ~/.config/claude/claude_desktop_config.json 在macOS/Linux上):
{
"mcpServers": {
"mag7-analyst": {
"url": "http://localhost:8000"
}
}
}程序化(Python——FastMCP客户端)
from fastmcp import Client
async with Client("http://localhost:8000") as client:
tools = await client.list_tools()
result = await client.call_tool("get_financial_metric", {
"ticker": "AAPL",
"metric_name": "Revenue",
"fiscal_year": 2023,
})卷曲
curl http://localhost:8000/health______________________________________________________________________
可用工具
矢量搜索工具
search_report_text
语义搜索结束 段落文本 在年度报告中。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query | string | ✅ | 自然语言问题 |
tickers | string\[\] | ❌ | 默认为所有允许的股票代码 |
top_k | int | ❌ | 返回的结果(1-20,默认值5) |
fiscal_year | int | ❌ | 筛选到特定年份 |
示例提示: *“苹果对其服务收入战略有何看法?”*
______________________________________________________________________
search_report_tables
语义搜索结束 Markdown格式的表格 在年度报告中。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query | string | ✅ | 自然语言问题 |
tickers | string\[\] | ❌ | 默认为所有允许的股票代码 |
top_k | int | ❌ | 返回的结果(1-20,默认值5) |
fiscal_year | int | ❌ | 筛选到特定年份 |
示例提示: *“查找微软2023年的细分收入明细表。”*
______________________________________________________________________
财务图表工具
get_financial_metric
检索一家公司的特定财务指标。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ticker | string | ✅ | 公司股票代码,例如。 "AAPL" |
metric_name | string | ✅ | 例如 "Revenue", "Net Income", "EPS" |
fiscal_year | int | ❌ | 具体年份;省略所有年份 |
______________________________________________________________________
compare_metric_across_years
一家公司指标的同比时间序列。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ticker | string | ✅ | 公司股票代码 |
metric_name | string | ✅ | 财务指标名称 |
______________________________________________________________________
compare_metric_across_companies
多家Magnificent 7公司的并排指标比较。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
tickers | string\[\] | ✅ | 两个或多个自动收报机 |
metric_name | string | ✅ | 财务指标名称 |
fiscal_year | int | ✅ | 用于比较的财政年度 |
______________________________________________________________________
关键人物工具
get_key_persons
检索年度报告中提到的高管和董事会成员。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ticker | string | ✅ | 公司股票代码 |
role | 枚举 | ❌ | 按角色筛选(见下文) |
角色价值观: CEO · CFO · COO · Chairperson · BoardMember
______________________________________________________________________
关键开发工具
get_key_developments
从年度报告文件中检索公司事件和发展。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
ticker | string | ✅ | 公司股票代码 |
category | 枚举 | ❌ | 按类别筛选(见下文) |
fiscal_year | int | ❌ | 筛选到特定年份 |
类别值:
| 值 | 描述 |
|---|---|
M&A | 合并、收购、资产剥离 |
Restructuring | 裁员、重组、工厂关闭 |
Litigation | 诉讼、罚款、和解 |
ProductLaunch | 新产品、服务、平台 |
RegulatoryAction | 政府调查、同意令 |
GuidanceChange | 前瞻性指导修订 |
______________________________________________________________________
查询示例
# Compare revenue across all Mag-7 for FY2023
compare_metric_across_companies(
tickers=["AAPL","MSFT","GOOGL","AMZN","NVDA","META","TSLA"],
metric_name="Revenue",
fiscal_year=2023
)
# Apple's net income over time
compare_metric_across_years(ticker="AAPL", metric_name="Net Income")
# NVIDIA product launches in 2023
get_key_developments(ticker="NVDA", category="ProductLaunch", fiscal_year=2023)
# Microsoft board members
get_key_persons(ticker="MSFT", role="BoardMember")
# Search for AI strategy discussion in GOOGL 2023 10-K
search_report_text(
query="artificial intelligence strategy and investments",
tickers=["GOOGL"],
fiscal_year=2023
)______________________________________________________________________
Neo4j图形模式参考
(:Company {ticker, name})
(:Document {id, type, filing_date})
(:FiscalYear {year})
(:Metric {name, unit})
(:Fact {value, period})
(:key_person {name, role, description})
(:key_development {title, category, description, date})
(Document)-[:BELONGS_TO]->(Company)
(Document)-[:BELONGS_TO]->(FiscalYear)
(Document)-[:REPORTS]->(Fact)
(Fact)-[:FOR_METRIC]->(Metric)
(Document)-[:MENTIONS]->(key_person)
(Document)-[:MENTIONS]->(key_development)______________________________________________________________________
许可证
麻省理工学院
