Skip to main content

MCP server for US federal spending data via api.usaspending.gov

Project description

usaspending-mcp

CI Python 3.11+ License: MIT MCP

Production-grade MCP server for US federal spending data via api.usaspending.gov.

Features

  • 8 decision-tree tools covering the full USASpending API (awards, agencies, recipients, spending, disaster funding, accounts, downloads)
  • Dual transport: STDIO (Claude Desktop/Code) and Streamable HTTP + SSE (hosted deployments)
  • Progress notifications for long-running paginated searches and bulk downloads
  • 4 MCP resources: agencies list, current fiscal year, data freshness, glossary
  • Lazy-loaded reference data with TTL cache (no blocking startup calls)
  • No authentication required — USASpending API is public

Installation

# 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]"

Quick Start

# 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

Configuration

Claude Desktop

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

Claude Code

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

Remote HTTP (e.g., gateway deployment)

# 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"]
    }
  }
}

Environment Variables

Variable Default Description
USASPENDING_MCP_TRANSPORT (auto) Force transport: stdio or http
USASPENDING_MCP_HOST 0.0.0.0 HTTP bind host
USASPENDING_MCP_PORT 8765 HTTP bind port

Tools

Tool Description
search_awards Search federal awards by keyword, agency, type, NAICS, PSC, recipient, amount
get_award Get award detail, funding, subawards, transactions by award ID
query_agency Agency overview + 7 breakdown types (budgets, sub-agencies, accounts, etc.)
query_recipient Recipient autocomplete search and full profile detail
query_spending Spending explorer by agency, budget function, object class, program activity
query_disaster Disaster/emergency funding by DEFC code with 6 breakdown categories
query_accounts Federal account detail, treasury account breakdown, account listing
manage_download Initiate and poll bulk CSV download jobs

Resources

URI Description
usaspending://agencies Full list of toptier federal agencies
usaspending://fiscal-year/current Current US federal fiscal year
usaspending://data-freshness Last updated timestamp from the API
usaspending://glossary Federal spending glossary terms

Deployment

Docker

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

DigitalOcean App Platform

The .do/app.yaml spec deploys the server as a container. Use the DO CLI or dashboard:

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

The server listens on port 8765 (/mcp). Connect Claude Desktop/Code via mcp-remote:

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

Cloudflare Workers (edge proxy)

CF Workers can't host a persistent Python server, but workers/proxy.js puts CF's edge network in front of your DO deployment:

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

# Deploy
wrangler deploy

Then update your mcp-remote URL to the CF Worker endpoint.

Development

# 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

Architecture

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usaspending_mcp-0.1.1.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usaspending_mcp-0.1.1-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file usaspending_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: usaspending_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for usaspending_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 75da954d0b62db7ae48cfbc5f892d44c4a30b9089faec523b0084a28f8b4bd44
MD5 978bb8cc0fc0c76fa936567ac57ff522
BLAKE2b-256 1f4b43ee972d0738f0d345b3a7a89c76beb6a28fb6f5898614f0aa0cbae66ac9

See more details on using hashes here.

Provenance

The following attestation bundles were made for usaspending_mcp-0.1.1.tar.gz:

Publisher: publish.yml on asachs01/usaspending-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usaspending_mcp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for usaspending_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ed74162bd94bb40f7b75c679fa93aa8c0492699003429d671a52712a7483334
MD5 3133783b58a55344e3f7bea91487a5d5
BLAKE2b-256 e90c62e5b5590f4599f725669e9b1fef4dbbc51575117093d7e3110d3c769bd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for usaspending_mcp-0.1.1-py3-none-any.whl:

Publisher: publish.yml on asachs01/usaspending-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page