MCP-FREDAPI

MIT License
2
  • Apple
  • Linux

Integrations

  • Used for configuration to securely store and access the FRED API key through environment variables

MCP-FREDAPI

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

目录

介绍

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

该软件包与官方 FRED API集成,特别关注为经济指标提供时间序列数据的series_observations 端点

安装

安装方法有两种:

方法 1:使用 pip

安装所需的依赖项:

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

克隆此存储库:

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

方法二:使用 uv(推荐)

推荐使用此方法,因为它与 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

Claude/Cursor 配置

要配置 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 上,您可以在路径中使用正斜杠/或双反斜杠\\

可用工具

获取fred_series_observations

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

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

@mcp-fredapi:get_fred_series_observations

参数

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

范围类型描述允许值默认值地位
系列 ID字符串经济系列ID-(必需的)✅ 有效
排序顺序字符串对观察结果进行排序‘升序’,‘降序’‘升序’✅ 有效
单位字符串数据价值转化'lin'、'chg'、'ch1'、'pch'、'pc1'、'pca'、'cch'、'cca'、'log'✅ 有效
频率字符串观察频率'd'、'w'、'bw'、'm'、'q'、'sa'、'a'、'wef'、'weth'、'wew'、'wetu'、'wem'、'wesu'、'wesa'、'bwew'、'bwem'没有任何✅ 有效
聚合方法字符串频率聚合方法“平均值”、“总和”、“eop”‘平均’✅ 有效
输出类型整数观测值的输出类型1、2、3、41✅ 有效
实时启动字符串实时周期的开始 (YYYY-MM-DD)-没有任何❌ 不工作
realtime_end字符串实时周期结束时间 (YYYY-MM-DD)-没有任何❌ 不工作
限制整数/字符串返回的最大观测数介于 1 到 100000 之间10❌ 不工作
抵消整数/字符串从头开始跳过的观察次数-0❌ 不工作
观察开始字符串观察开始日期(YYYY-MM-DD)-没有任何❌ 不工作
观察结束字符串观察结束日期(YYYY-MM-DD)-没有任何❌ 不工作
年份日期字符串以逗号分隔的年份列表-没有任何❌ 不工作

关于参数兼容性的注意事项

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

  • 工作参数series_idsort_orderunitsfrequency 、aggregation_method , and output_type。
  • 非工作参数realtime_startrealtime_endlimitoffsetobservation_startobservation_endvintage_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 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。

参考

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

通过模型上下文协议提供来自圣路易斯联邦储备银行 (FRED) 的经济数据访问,允许 AI 助手直接检索经济时间序列数据。

  1. Table of Contents
    1. Introduction
      1. Installation
        1. Method 1: Using pip
        2. Method 2: Using uv (Recommended)
      2. Configuration
        1. FRED API Key
        2. Claude/Cursor Configuration
      3. Available Tools
        1. get_fred_series_observations
      4. Parameters
        1. Examples
          1. Getting US GDP Data
          2. Getting GDP Data in Descending Order
          3. Getting Annual GDP Data
          4. Getting Inflation Rate
          5. Different Output Format
        2. Contributing
          1. License
            1. References
              ID: 2ty3iyx3qe