金融数据服务器

基于Azure Container Apps的MCP服务器,为AI代理提供公司收益数据。

  • by dannygar
  • PowerShell
  • 本地部署
  • 更新于
在 GitHub 查看 dannygar/mcp-finance-data

使用说明

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/mcp

MCP检验员测试

# 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.ps1

3.验证部署

# Check health endpoint
Invoke-WebRequest -Uri "https://<your-container-app>.azurecontainerapps.io/health"

# The MCP endpoint is available at:
# https://<your-container-app>.azurecontainerapps.io/mcp

4.拆卸

# Remove all Azure resources
azd down

连接到Azure AI Foundry

将MCP服务器添加到Foundry代理

  1. 导航到您的AI Foundry项目:https://ai.azure.com
  2. 首选 代理 → 工具 → MCP服务器
  3. 点击 添加MCP服务器
  4. 配置:
    • 名字: mcp-finance
    • 传输类型:流式HTTP
    • 端点URL: https://<your-container-app>.azurecontainerapps.io/mcp
    • 认证:无
  5. 点击 保存

在Chat Playground中测试

尝试以下提示:

  • “微软2024财年第四季度的收入是多少?”
  • “获得特斯拉2024财年第二季度的自由现金流”
  • “比较NVIDIA在2024财年第一季度至第四季度的收入”

连接到VS Code GitHub副本

添加到您的 .vscode/mcp.json:

{
  "servers": {
    "mcp-finance-remote": {
      "type": "http",
      "url": "https://<your-container-app>.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 <container-app-name> `
  --resource-group <resource-group> `
  --follow

# Or use azd
azd monitor --logs

本地调试

  1. 启动服务器: cd container-app && uv run python server.py
  2. 在中设置断点 server.py
  3. 附加调试器(VS代码:Python:附加到本地进程)

文档


许可证

麻省理工学院