MCP财务数据服务器
基于Azure容器应用程序的MCP(模型上下文协议)服务器为AI代理提供公司收益数据。
建筑
- 远程MCP服务器 使用Azure容器应用程序(FastMCP+Python 3.12)
- HTTP传输 (流式HTTP)用于Azure AI Foundry集成
- 2公司盈利工具 用于收入和自由现金流分析
- 数据提供程序:AlphaVantage API(美国证券交易委员会备案)
- 支持的公司:微软(MSFT)、特斯拉(TSLA)、英伟达(NVDA)
- 通过Azure Developer CLI部署 (
azd)
先决条件
- Python 3.11+ (3.12推荐)
- 码头工人 (用于本地开发和容器构建)
- Azure开发者命令行界面 (azd)用于部署
- Azure命令行界面 用于资源管理
设置:
# Install uv (if not already installed)
irm https://astral.sh/uv/install.ps1 | iex
# Sync dependencies
uv sync快速开始
地方发展
选项1:使用Docker在本地运行容器应用程序
# Build the container
docker build -t mcp-finance-server -f container-app/Dockerfile container-app/
# Run with your API key
docker run -p 3000:3000 -e ALPHAVANTAGE_API_KEY="your_key" mcp-finance-server
# Server available at http://localhost:3000/mcp选项2:直接用Python运行
cd container-app
# Set your API key
$env:ALPHAVANTAGE_API_KEY = "your_key"
# Run the server
uv run python server.py
# Server available at http://localhost:3000/mcpMCP检验员测试
# Install MCP Inspector
yarn install
# Start the server first, then launch inspector
yarn inspector检查员打开 http://localhost:5173 您可以在哪里:
- 浏览可用工具(
get_company_revenue,get_company_free_cash_flow) - 使用自定义参数调用测试工具
- 实时查看请求/响应有效载荷
______________________________________________________________________
部署到Azure
1.配置API密钥
# Required: Set your Alpha Vantage API key
$env:ALPHAVANTAGE_API_KEY = "your_alpha_vantage_key"获取免费的API密钥: https://www.alphavantage.co/support/#api-钥匙
2.使用Azure Developer CLI进行部署
# Deploy infrastructure + container
azd up
# Or use the deployment script for more control
.\scripts\deploy-container-app.ps13.验证部署
# Check health endpoint
Invoke-WebRequest -Uri "https://.azurecontainerapps.io/health"
# The MCP endpoint is available at:
# https://.azurecontainerapps.io/mcp4.拆卸
# Remove all Azure resources
azd down______________________________________________________________________
连接到Azure AI Foundry
将MCP服务器添加到Foundry代理
- 导航到您的AI Foundry项目:https://ai.azure.com
- 首选 代理 → 工具 → MCP服务器
- 点击 添加MCP服务器
- 配置:
- 名字: mcp-finance - 传输类型:流式HTTP - 端点URL: https://.azurecontainerapps.io/mcp - 认证:无
- 点击 保存
在Chat Playground中测试
尝试以下提示:
- “微软2024财年第四季度的收入是多少?”
- “获得特斯拉2024财年第二季度的自由现金流”
- “比较NVIDIA在2024财年第一季度至第四季度的收入”
______________________________________________________________________
连接到VS Code GitHub副本
添加到您的 .vscode/mcp.json:
{
"servers": {
"mcp-finance-remote": {
"type": "http",
"url": "https://.azurecontainerapps.io/mcp"
},
"mcp-finance-local": {
"type": "http",
"url": "http://localhost:3000/mcp"
}
}
}______________________________________________________________________
MCP工具
get_company_revenue
获取公司季度收益报告的总收入(单位:百万美元)。
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
company_symbol | string | 公司股票代码(MSFT、TSLA或NVDA) |
fiscal_year | 数字 | 财政年度(例如2024年) |
fiscal_quarter | number | 财政季度(1、2、3或4) |
示例响应:
{
"company": "MSFT",
"fiscal_year": 2024,
"fiscal_quarter": 4,
"fiscal_date_ending": "2024-06-30",
"total_revenue_usd_millions": 64725.00,
"currency": "USD",
"data_source": "Alpha Vantage"
}______________________________________________________________________
get_company_free_cash_flow
从公司的季度收益报告中获得数百万美元的自由现金流。
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
company_symbol | string | 公司股票代码(MSFT、TSLA或NVDA) |
fiscal_year | 数字 | 财政年度(例如2024年) |
fiscal_quarter | number | 财政季度(1、2、3或4) |
示例响应:
{
"company": "MSFT",
"fiscal_year": 2024,
"fiscal_quarter": 4,
"fiscal_date_ending": "2024-06-30",
"free_cash_flow_usd_millions": 23255.00,
"operating_cash_flow_usd_millions": 28515.00,
"capital_expenditures_usd_millions": 5260.00,
"currency": "USD",
"data_source": "Alpha Vantage"
}______________________________________________________________________
支持的公司
| 符号 | 公司名称 |
|---|---|
| 微软公司 | |
| TSLA | 特斯拉股份有限公司 |
| NVDA | 英伟达公司 |
______________________________________________________________________
项目结构
├── container-app/
│ ├── server.py # MCP server (FastMCP + Streamable HTTP)
│ ├── Dockerfile # Container image definition
│ ├── requirements.txt # Python dependencies
│ └── pyproject.toml # Project metadata
├── infra/
│ └── container-app/
│ ├── main.bicep # Azure infrastructure
│ └── container-app.bicep # Container App definition
├── config/
│ ├── .env.prod # Production API keys
│ └── .env.dev # Development API keys
├── scripts/
│ └── deploy-container-app.ps1 # Deployment script
├── docs/
│ └── AZURE_DEPLOYMENT.md # Detailed Azure setup guide
├── azure.yaml # azd configuration
├── package.json # MCP Inspector dependencies
└── .vscode/
└── mcp.json # VS Code MCP configuration______________________________________________________________________
配置
环境变量
| 变量 | 必填 | 描述 |
|---|---|---|
ALPHAVANTAGE_API_KEY | 是 | Alpha Vantage API财务数据密钥 |
PORT | 无 | 服务器端口(默认值:3000) |
HOST | 否 | 服务器主机(默认值:0.0.0.0) |
API费率限制
Alpha Vantage免费版:
- 每天25个请求
- 每分钟5个请求
考虑升级以供生产使用。
______________________________________________________________________
调试
查看容器日志
# Stream logs from Azure Container Apps
az containerapp logs show `
--name `
--resource-group `
--follow
# Or use azd
azd monitor --logs本地调试
- 启动服务器:
cd container-app && uv run python server.py - 在中设置断点
server.py - 附加调试器(VS代码:Python:附加到本地进程)
______________________________________________________________________
文档
______________________________________________________________________
许可证
麻省理工学院
