How to Add US Census Data to Codex
Codex CLI fits neatly into a terminal-first workflow, but when a task requires real demographic data — population figures, income stats, housing numbers — it has nothing to pull from. AgentPatch adds a Census Data tool that queries the US Census Bureau’s American Community Survey directly, so Codex can fetch the numbers it needs without you leaving the terminal.
Why This Matters
Working with demographic data usually means visiting data.census.gov, figuring out the right table codes, and exporting CSVs. If you need that data as part of a coding task — building seed data, validating a model, creating test fixtures — the context switch is expensive.
The Census Data tool handles the translation for you. You ask for variables like total_population or median_home_value in plain English, specify a geography level (state, county, zip, place, or national), and get back clean results. State names like “Florida” work directly — no need to look up FIPS codes. The tool covers 16 variables across population, income, education, housing, and demographic categories, all from the ACS 5-year estimates.
Setup
Add AgentPatch to ~/.codex/config.toml:
[mcp_servers.agentpatch]
url = "https://agentpatch.ai/mcp"
bearer_token_env_var = "AGENTPATCH_API_KEY"
Then set your API key:
export AGENTPATCH_API_KEY=your_api_key
Replace your_api_key with your actual key from the AgentPatch dashboard. Codex discovers all AgentPatch tools automatically on next start.
Example
You’re building an API that returns housing affordability metrics by zip code and need realistic test data. You ask Codex:
“Pull median home value, median rent, and median household income for zip codes in Colorado. I need a few examples to build my test fixtures.”
Codex calls the Census Data tool:
Fetching Census ACS data for Colorado zip codes...
Variables: median_home_value, median_rent, median_household_income
Geography: zip code level, state: Colorado
Year: 2023, Dataset: acs5
Sample results:
80202 (Denver): $478,300 home value, $1,685 rent, $85,412 income
80301 (Boulder): $762,500 home value, $1,812 rent, $92,174 income
80903 (Colorado Springs): $318,700 home value, $1,245 rent, $58,903 income
Writing these into test/fixtures/housing.json with the schema matching
your HousingMetrics interface.
Codex fetched real housing data across different Colorado zip codes, giving you natural variation in the test fixtures — high-cost, mid-range, and affordable areas — without you opening a browser.
Wrapping Up
Connecting AgentPatch to Codex gives it live access to US Census Bureau data from the terminal. Each call costs 75 credits and returns human-readable results across 16 demographic and economic variables. The same MCP connection also unlocks every other tool on the marketplace. See what’s available at agentpatch.ai.