经济数据API集成

MCP-FREDAPI通过Model Context Protocol集成FRED API,提供对美国联邦储备经济数据的访问,适用于AI助手和经济分析场景。

  • by Jaldekoa
  • Python
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 jaldekoa/mcp-fredapi

使用说明

MCP-FREDAPI

FRED(美联储经济数据)API与模型上下文协议(MCP)的集成

目录

引言

MCP-FREDAPI通过模型上下文协议提供对圣路易斯联邦储备银行(FRED)经济数据的访问。这种集成允许像Claude这样的人工智能助手在与Cursor或其他兼容MCP的环境一起使用时直接检索经济时间序列数据。

此软件包与 官方FRED API,特别关注 系列观测终点 它为经济指标提供时间序列数据。

安装

有两种安装方法:

方法1:使用pip

安装所需的依赖项:

pip install "mcp[cli]" httpx python-dotenv

克隆此存储库:

git clone https://github.com/Jaldekoa/mcp-fredapi.git
cd mcp-fredapi

方法2:使用紫外线(推荐)

建议使用此方法,因为它与mcp.json中显示的配置相匹配。

  1. 首先,如果你还没有安装uv:
pip install uv
  1. 克隆此存储库:
git clone https://github.com/Jaldekoa/mcp-fredapi.git
cd mcp-fredapi
  1. 使用uv运行服务器(无需单独安装依赖项):
uv run --with mcp --with httpx mcp run server.py

配置

FRED API密钥

您需要一个FRED API密钥,您可以从 FRED API公司.

创建一个 .env 项目根目录中的文件:

FRED_API_KEY=your_api_key_here

克劳德/光标配置

要配置Cursor以使用此MCP服务器,请将以下内容添加到您的 ~/.cursor/mcp.json 文件:

{
  "mcpServers": {
    "mcp-fredapi": {
      "command": "uv",
      "args": ["--directory", "/path/to/mcp-fredapi", "run", "--with", "mcp", "--with", "httpx", "mcp", "run", "server.py"]
    }
  }
}

替换 /path/to/mcp-fredapi 使用系统上存储库的实际路径。例如:

{
  "mcpServers": {
    "mcp-fredapi": {
      "command": "uv",
      "args": ["--directory", "/path/to/mcp-fredapi", "run", "--with", "mcp", "--with", "httpx", "mcp", "run", "server.py"]
    }
  }
}

注意:在Windows上,您可以使用正斜杠 / 或双反睫毛 \\ 在路上。

可用工具

get_fred_series_observations

从FRED检索经济时间序列观测值。

在Cursor中使用Claude时,您可以通过以下方式直接访问此工具:

@mcp-fredapi:get_fred_series_observations

参数

这 get_fred_series_observations 该工具接受以下参数。有关每个参数的完整技术细节,请参阅 FRED API官方文件.

参数 类型 描述 允许值 默认值 状态
series_id str 经济序列的id - (必填) ✅ 作品
sort_order str 观测值的排序顺序 “asc”,“desc” “asc” ✅ 作品
units str 数据值转换 'lin','chg','ch4','pch','pca','cch','cca','log' 'lin' ✅ 作品
frequency str 观测频率 “d”、“w”、“bw”、“m”、“q”、“sa”、“a”、“wef”、“wet”、✅ 作品
aggregation_method str 频率聚合方法 “avg”、“sum”、“eop” “avg'” ✅ 作品
output_type int 观测值的输出类型 1、2、3、4 1 ✅ 作品
realtime_start str 实时周期开始(YYYY-MM-DD) - 无 ❌ 不工作
realtime_end str 实时周期结束(YYYY-MM-DD) - 无 ❌ 不工作
limit int/str 要返回的最大观测值数 介于1和100000之间 10 ❌ 不工作
offset int/str 从头开始跳过的观测值数 - 0 ❌ 不工作
observation_start str 观测开始日期(YYYY-MM-DD) - 无 ❌ 不工作
observation_end str 观测结束日期(YYYY-MM-DD) - 无 ❌ 不工作
vintage_dates str 逗号分隔的年份列表 - 无 ❌ 不工作

[!警告]

由于MCP实现的当前限制,只有某些参数正常工作:

  • ✅ 工作参数: series_id, sort_order, units, frequency ,聚合_方法, and output_type `。
  • ❌ 非工作参数: realtime_start, realtime_end, limit, offset, observation_start, observation_end,以及 vintage_dates.

为了获得最佳结果,请在查询中坚持使用工作参数。未来的更新可能会解决这些限制。

例子

获取美国GDP数据

在Cursor中使用Claude时,您可以要求提供GDP数据,如下所示:

Can you get the latest GDP data from FRED?

@mcp-fredapi:get_fred_series_observations
{
  "series_id": "GDP"
}

按降序获取GDP数据

Can you get the GDP data in descending order (newest first)?

@mcp-fredapi:get_fred_series_observations
{
  "series_id": "GDP",
  "sort_order": "desc"
}

获取年度GDP数据

Can you get annual GDP data?

@mcp-fredapi:get_fred_series_observations
{
  "series_id": "GDP",
  "frequency": "a"
}

获得通货膨胀率

要获取变化百分比的消费者价格指数数据:

What's the recent inflation rate in the US?

@mcp-fredapi:get_fred_series_observations
{
  "series_id": "CPIAUCSL",
  "units": "pch",
  "frequency": "m"
}

不同的输出格式

Show me GDP data in a different format.

@mcp-fredapi:get_fred_series_observations
{
  "series_id": "GDP",
  "output_type": 2
}

贡献

欢迎捐款。请按照以下步骤操作:

  1. 分叉存储库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 进行更改
  4. 提交您的更改(git commit -m 'Add an amazing feature')
  5. 推到分支(git push origin feature/amazing-feature)
  6. 打开拉取请求

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

参考文献