联邦支出数据服务

USASpending-MCP是一个生产级的MCP服务器,提供对美国联邦支出数据的访问,支持多种传输方式和工具,无需认证即可使用。

  • by asachs01
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 asachs01/usaspending-mcp

使用说明

美国支出mcp

用于美国联邦支出数据的生产级MCP服务器 api.usasspending.gov.

特性

  • 8个决策树工具 涵盖整个USASpending API(奖项、机构、接受者、支出、灾难资金、账户、下载)
  • 双重运输: STDIO(克劳德桌面/代码)和流式HTTP+SSE(托管部署)
  • 进度通知 用于长时间分页搜索和批量下载
  • 4 MCP资源: 机构列表、当前财政年度、数据新鲜度、术语表
  • 延迟加载参考数据 带TTL缓存(无阻塞启动调用)
  • 不要求进行验证 -USASpending API是公开的

安装

# From PyPI (when published)
pip install usaspending-mcp

# From GitHub
pip install git+https://github.com/asachs01/usaspending-mcp.git

# For development
git clone https://github.com/asachs01/usaspending-mcp.git
cd usaspending-mcp
pip install -e ".[dev]"

快速开始

# STDIO mode (default — for Claude Desktop / Claude Code)
usaspending-mcp

# HTTP mode (for hosted/remote deployments)
usaspending-mcp-http

# With custom port
usaspending-mcp-http --port 9000

# Auto-detect transport
python -m usaspending_mcp.server --transport http

配置

克劳德桌面版

{
  "mcpServers": {
    "usaspending": {
      "command": "uvx",
      "args": ["usaspending-mcp"]
    }
  }
}

克劳德代码

{
  "mcpServers": {
    "usaspending": {
      "command": "uvx",
      "args": ["usaspending-mcp"]
    }
  }
}

远程HTTP(例如网关部署)

# Start the HTTP server
USASPENDING_MCP_PORT=8765 usaspending-mcp-http

# Connect via mcp-remote in Claude Desktop
{
  "mcpServers": {
    "usaspending": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "http://your-server:8765/mcp"]
    }
  }
}

环境变量

变量 默认值 描述
USASPENDING_MCP_TRANSPORT (自动) 强制运输: stdio 或 http
USASPENDING_MCP_HOST 0.0.0.0 HTTP绑定主机
USASPENDING_MCP_PORT 8765 HTTP绑定端口

工具

工具 说明
search_awards 按关键字、机构、类型、NAICS、PSC、收件人、金额搜索联邦奖项
get_award 按奖励ID获取奖励详情、资金、子奖励和交易
query_agency 机构概述+7种细分类型(预算、子机构、账户等)
query_recipient 收件人自动完成搜索和完整的个人资料详细信息
query_spending 按机构、预算函数、对象类、程序活动划分的支出浏览器
query_disaster 按DEFC代码划分的灾难/紧急资金,分为6个细分类别
query_accounts 联邦账户详细信息、国库账户明细、账户列表
manage_download 启动并轮询批量CSV下载作业

资源

URI 描述
usaspending://agencies 顶级联邦机构的完整列表
usaspending://fiscal-year/current 当前美国联邦财政年度
usaspending://data-freshness API最近更新的时间戳
usaspending://glossary 联邦支出术语表

部署

码头工人

docker build -t usaspending-mcp .
docker run -p 8765:8765 usaspending-mcp

数字海洋应用平台

这 .do/app.yaml spec将服务器部署为容器。使用DO CLI或仪表板:

doctl apps create --spec .do/app.yaml

服务器监听端口8765(/mcp).通过以下方式连接克劳德桌面/代码 mcp-remote:

{
  "mcpServers": {
    "usaspending": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://your-app.ondigitalocean.app/mcp"]
    }
  }
}

Cloudflare Workers(边缘代理)

CF Workers不能承载持久的Python服务器,但是 workers/proxy.js 将CF的边缘网络置于DO部署之前:

# Point the worker at your DO app URL
wrangler secret put BACKEND_URL
# → https://usaspending-mcp-api-xxxxx.ondigitalocean.app

# Deploy
wrangler deploy

然后更新您的 mcp-remote CF Worker终结点的URL。

发展

# Install with dev dependencies (requires uv)
uv sync --group dev

# Run tests
uv run pytest tests/ -v

# Run a specific test file
uv run pytest tests/test_tools_awards.py -v

建筑

usaspending_mcp/
  __init__.py          # MCPB extension manifest
  server.py            # Entry point, transport detection, FastMCP setup
  client/
    api.py             # Async httpx wrapper for all API domains
    cache.py           # In-memory lazy cache with per-key TTL
  tools/
    registry.py        # Imports all tool modules for registration
    awards.py          # search_awards, get_award
    agency.py          # query_agency (8 sub-routes)
    recipients.py      # query_recipient
    spending.py        # query_spending
    disaster.py        # query_disaster
    accounts.py        # query_accounts
    downloads.py       # manage_download
  decision_tree/
    router.py          # Parameter inspection and missing-param detection
    elicitor.py        # JSON Schema builder for elicitation
  resources/
    registry.py        # MCP resource definitions
  transport/
    http.py            # HTTP config
    session.py         # Per-session subscription tracking
  notifications/
    progress.py        # Progress notification helpers

许可证

麻省理工学院