federal-spend-ai
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
federal-spend-ai
Open-source Canadian federal spending analysis with MCP tools, local DuckDB storage, NLP, semantic search, anomaly detection, and money-flow tracing over official open data.
Not affiliated with or endorsed by the Government of Canada. Data is provided under the Open Government Licence – Canada.
Features
MCP server — 20+ tools for contracts, Public Accounts, NLP, search, anomalies, and graphs
Data pipeline — CanadaBuys awards + Public Accounts CSVs via CKAN, bilingual normalization, DuckDB
NLP — spaCy / optional Blackstone NER, procurement risk flags, summaries
Semantic search — sentence-transformers embeddings with hybrid keyword search
Anomaly detection — department/vendor spend z-score outliers with investigation workflows
Money-flow graphs — NetworkX vendor→department flows with Public Accounts linking
Cognitive Substrate hooks — JSON event emission (
FlowGraphExported,AnomalyFlagged,EmbeddingIndexed)
Related MCP server: USAspending MCP
Architecture
flowchart TB
subgraph sources [OpenData]
CB[CanadaBuys]
PA[PublicAccounts]
end
subgraph app [FederalSpendAI]
Ingest[ingest]
DB[(DuckDB)]
NLP[nlp]
Emb[embeddings]
Anom[anomalies]
Graph[graphs]
MCP[FastMCP]
Events[substrate_events]
end
CB --> Ingest
PA --> Ingest
Ingest --> DB
DB --> NLP
DB --> Emb
DB --> Anom
DB --> Graph
NLP --> MCP
Emb --> MCP
Anom --> MCP
Graph --> MCP
MCP --> EventsQuickstart
pip install -e ".[dev]"
python -m spacy download en_core_web_sm
# Ingest sample fixtures
federalspendai ingest --datasets awards,public_accounts --fixture-dir tests/fixtures
# Build embedding index (downloads model on first run)
federalspendai embed
# Analyze, detect anomalies, trace money flow
federalspendai analyze --reference-number MX-444028039551
federalspendai detect-anomalies --json
federalspendai trace "Irving Oil Limited"
# MCP server (standalone tools only)
federalspendai serve
# Engine: auto-pull, analyze, and host MCP plugins (recommended on VPS)
federalspendai engineMCP tools (summary)
Category | Tools |
Data |
|
NLP |
|
Search |
|
Analytics |
|
Graphs |
|
Engine |
|
Engine (VPS / auto-pull)
The engine is the recommended production mode. It runs on a schedule and:
Pulls open Canada data (awards, public accounts) from CKAN
Embeds new/changed contracts (incremental)
Detects spending anomalies
Hosts MCP plugins on a shared endpoint (
federalspendai engine)
MCP servers are plugins registered in {data_dir}/plugins.json. The built-in federal-spend-ai plugin provides all core tools. External MCP servers can be mounted as namespaced plugins (pluginname__toolname).
# Run engine locally
federalspendai engine
# One analysis cycle (ingest → embed → anomalies)
federalspendai engine --once
# Standalone MCP without background engine
federalspendai servePlugin config (~/.federalspendai/plugins.json)
{
"plugins": [
{ "name": "federal-spend-ai", "type": "builtin", "enabled": true },
{
"name": "my-plugin",
"type": "mcp",
"enabled": true,
"command": "my-mcp-server",
"args": ["serve"]
}
]
}Engine environment variables
Variable | Default | Purpose |
|
| Enable background scheduler |
|
| Seconds between auto-pull cycles |
|
| Datasets to pull each cycle |
|
| Run a cycle when the engine starts |
Substrate events (IngestCompleted, EmbeddingIndexed, AnomalyFlagged, EngineCycleCompleted) are written to {data_dir}/events/ each cycle.
Anomaly storage and investigation
Detected anomalies are persisted in DuckDB with stable IDs (department/vendor + month). Each anomaly tracks:
Field | Purpose |
| Hash of amounts, z-score, and sample contracts |
|
|
| Cached investigation JSON |
investigate_anomaly returns a cached report when evidence is unchanged. It re-runs only when the fingerprint changes or force=true. Use list_stored_anomalies_tool to see open anomalies and investigation status.
Cognitive Substrate integration
Events are written to ~/.federalspendai/events/ in two formats:
Legacy —
FlowGraphExported,AnomalyFlagged, etc. (events/*.json)ExperienceEvent — Cognitive Substrate
experience.rawcompatible records (events/experience/*.json)
Optionally POST to FEDERALSPEND_SUBSTRATE_EVENT_URL. Set FEDERALSPEND_SUBSTRATE_EVENT_FORMAT to legacy, experience, or both (default).
See examples/substrate_event_consumer.py and the BigPines companion demo:
python examples/bigpines_companion_demo.py --skip-embedFixture note: Examples using
MX-444028039551/ Irving Oil use synthetic illustrative fixtures intests/fixtures/for reproducible demos — not verified live government records. Run live ingest before publishing real findings.
Data sources
Dataset | CKAN ID |
CanadaBuys awards |
|
Contract history |
|
Proactive Disclosure |
|
Public Accounts (Prof. Services) |
|
Container
The repo includes a Dockerfile, docker-compose.yml, and setup.sh for running the engine (auto-pull + MCP plugins) in Docker.
VPS quick install (CyberPanel / bare Linux)
On a fresh VPS (Ubuntu, AlmaLinux, Rocky — with or without CyberPanel), run as root:
curl -fsSL https://raw.githubusercontent.com/SBPnet/federal-spend-ai/main/setup.sh -o setup.sh
chmod +x setup.sh
./setup.sh --with-swapThis installs Docker, builds the image, runs an initial live data analysis cycle, and starts the engine on 127.0.0.1:8000. Use --data fixtures for offline sample data.
Or clone first and run locally:
git clone https://github.com/SBPnet/federal-spend-ai.git /opt/federalspendai
cd /opt/federalspendai
sudo ./setup.sh --with-swapConnect from your machine via SSH tunnel:
ssh -L 8000:127.0.0.1:8000 root@YOUR_VPS_IPOptions: ./setup.sh --help — --skip-docker-install if CyberPanel Docker is already configured.
Build
docker build -t federalspendai .Run engine (SSE over HTTP)
docker run -d \
--name federalspendai \
-p 127.0.0.1:8000:8000 \
-v federalspendai-data:/data \
-e FEDERALSPEND_ENGINE_ENABLED=true \
federalspendaiThe default image CMD runs federalspendai engine with auto-pull enabled.
One-time analysis cycle with Compose
docker compose --profile init run --rm engine-once
docker compose up -d federalspendaiCLI examples
# Ingest sample fixtures (no network required)
docker run --rm \
-v federalspendai-data:/data \
-v "$(pwd)/tests/fixtures:/fixtures:ro" \
federalspendai \
federalspendai ingest --datasets awards,public_accounts --fixture-dir /fixtures
# Build embeddings (downloads model on first run)
docker run --rm \
-v federalspendai-data:/data \
federalspendai \
federalspendai embed
# Check database status
docker run --rm \
-v federalspendai-data:/data \
federalspendai \
federalspendai statusMCP over stdio (Cursor / local MCP clients)
For clients that spawn the process and communicate over stdin/stdout:
{
"mcpServers": {
"federal-spend-ai": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-v", "federalspendai-data:/data",
"federalspendai",
"federalspendai", "serve"
]
}
}
}Pre-populate the federalspendai-data volume with ingest/embed before connecting.
Environment variables
Variable | Purpose |
| Root for DuckDB, cache, and events (default in image: |
| Override DuckDB file path |
| Optional webhook for Cognitive Substrate events |
|
|
Mount a volume at FEDERALSPEND_DATA_DIR so data persists across container restarts. The first embed run downloads a sentence-transformers model; live ingest requires outbound HTTPS to open.canada.ca.
Development
pip install -e ".[dev]"
pytest # 40 tests
ruff check src testsLicense
MIT — see LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
B2B, GovCon & LegalTech MCP server for live RFPs, contract parsing, compliance & proposal tools.
MCP access to the U.S. federal procurement graph: contracts, opportunities, entities, and more.
Canada Government Procurement MCP — CanadaBuys open data (keyless).
One MCP server for all web data. Scrape, search, crawl, and AI research in one install.
Related MCP Servers
- AlicenseAqualityDmaintenanceRead-only MCP server for exploring US federal spending data via the USAspending.gov API, enabling natural language queries on awards, agencies, recipients, and spending trends.12MIT
- AlicenseNot gradedqualityDmaintenanceA free, key-less MCP server for querying U.S. federal spending data from USAspending.gov, including contracts, grants, loans, recipients, agencies, and geographic breakdowns.MIT
- AlicenseAqualityDmaintenanceMCP server for searching government tenders from CanadaBuys and SAM.gov with free stats and paid search, latest, and AI matching tools using x402 micropayments.41MIT
- FlicenseNot gradedqualityDmaintenanceMCP server for Peruvian government data, enabling search and anomaly detection in public procurement (OSCE) and legislative tracking (Congress), plus semantic search over both domains.-