{
  "markdown": "<div align=\"center\">\n  <h1>@cyanheads/census-mcp-server</h1>\n  <p><b>Query U.S. Census Bureau data, variables, and geography via MCP. STDIO or Streamable HTTP.</b>\n  <div>8 Tools</div>\n  </p>\n</div>\n\n<div align=\"center\">\n\n[![Version](https://img.shields.io/badge/Version-0.3.3-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/census-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.0.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/census-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/census-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.0-blueviolet.svg?style=flat-square)](https://bun.sh/)\n\n</div>\n\n<div align=\"center\">\n\n[![Install in Claude Desktop](https://img.shields.io/badge/Install_in-Claude_Desktop-D97757?style=for-the-badge&logo=anthropic&logoColor=white)](https://github.com/cyanheads/census-mcp-server/releases/latest/download/census-mcp-server.mcpb) [![Install in Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=census-mcp-server&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBjeWFuaGVhZHMvY2Vuc3VzLW1jcC1zZXJ2ZXIiXX0=) [![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Server-0098FF?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect?url=vscode:mcp/install?%7B%22name%22%3A%22census-mcp-server%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40cyanheads%2Fcensus-mcp-server%22%5D%7D)\n\n[![Framework](https://img.shields.io/badge/Built%20on-@cyanheads/mcp--ts--core-67E8F9?style=flat-square)](https://www.npmjs.com/package/@cyanheads/mcp-ts-core)\n\n</div>\n\n<div align=\"center\">\n\n**Public Hosted Server:** [https://census.caseyjhand.com/mcp](https://census.caseyjhand.com/mcp)\n\n</div>\n\n---\n\n## Tools\n\n8 tools covering the full Census data workflow — from dataset discovery and variable search through geography resolution and ranked comparisons:\n\n| Tool | Description |\n|:-----|:------------|\n| `census_list_datasets` | Browse available Census Bureau datasets (ACS5, ACS1, Population Estimates, Decennial, County Business Patterns, Economic Census, Nonemployer Statistics) with vintage years and dataset codes. |\n| `census_list_geographies` | List the geography levels supported by a dataset and year, with parent requirements and example FIPS values. |\n| `census_search_variables` | Keyword search across variable labels and concept groups. On ACS, returns estimate and margin-of-error codes together. |\n| `census_get_variable` | Fetch full metadata for one or more variable codes — label, concept, predicate type, universe, MOE sibling. |\n| `census_list_predicate_values` | List the codes a filter dimension accepts (`EMPSZES`, `LFO`, `POPGROUP`, `NAICS2017`…), from the dataset dictionary or a live wildcard enumeration. |\n| `census_resolve_geography` | Convert place names (e.g., \"King County, WA\") or street addresses to Census FIPS identifiers via TIGERweb and Census Geocoder. |\n| `census_query_data` | Query a Census dataset for variables at a specific geography. Returns estimates with MOE, suppression codes resolved to readable reasons, and predicate filtering for the business datasets. |\n| `census_compare_geographies` | Rank and compare variables across multiple geographies — all counties in a state, all states nationally, or a named set. Sorted table output, with the same predicate filtering. |\n\n### `census_list_datasets`\n\nBrowse available Census Bureau datasets.\n\n- Returns dataset codes, names, descriptions, and available vintage years\n- Covers ACS5, ACS5 Data Profiles, ACS5 Subject Tables, ACS1, ACS1 Data Profiles, Population Estimates, Decennial Redistricting (P.L. 94-171), Decennial DHC, County Business Patterns (`cbp`), Economic Census (`ecnbasic`), and Nonemployer Statistics (`nonemp`)\n- Each description names the filter predicates the dataset requires and the geography levels it publishes — both vary by dataset\n- Accepts an optional keyword filter\n- Dataset codes (e.g., `acs/acs5`) are the values to pass to other tools\n- `available_years` is exhaustive, not a sample: any other year fails with `year_not_available` before a request goes out, naming the years that do work. It is narrower than what the Census API hosts — `pep/charv` reaches its 2020-2022 estimates through the `YEAR` filter inside the 2023 vintage, and the `cbp`/`nonemp` vintages left out reject the `NAME` column every query here sends\n\n---\n\n### `census_search_variables`\n\nSearch Census variables by keyword.\n\n- Full-text search across label and concept fields with relevance scoring (exact concept match > label match > partial)\n- On ACS datasets, returns estimate (E suffix) and margin-of-error (M suffix) codes together so both can be requested in one query — no other family publishes margins of error, and an E-final code there is an ordinary code\n- Also surfaces the predicate codes a dataset filters on, such as `NAICS2017` in `cbp`\n- Configurable limit (default 20, max 100); `total_matches` indicates how many matched before the limit\n- Cache-backed: variables.json is fetched once per dataset+year with a configurable TTL (default 24h)\n\n---\n\n### `census_list_predicate_values`\n\nList the codes a filter dimension accepts, so a `predicates` map can be written without guessing.\n\n- Two routes, picked by where the answer lives: a dimension with a published value list is read from the dataset dictionary, one without is enumerated live by wildcarding it on the data endpoint. `NAICS*` and `POPGROUP` always publish one (thousands of codes — narrow them with `query`); on the current vintages `EMPSZES`, `LFO`, `RCPSZES`, `TAXSTAT`, and `TYPOP` publish none, so the live route is the only place their codes appear\n- A dictionary value list is a classification shared across Census products, not a record of what one dataset serves — `dec/ddhca` declares 5,543 `POPGROUP` codes and publishes 2,996, `cbp` declares 6,694 `NAICS2017` codes and publishes 2,003. The declared list is checked against the dataset's own published rows and the dead codes are dropped; `source` says whether that check ran and the notice says how many were withheld. A keyword that matched only withheld codes names them, so \"total population\" on `dec/ddhca` reports that `001` is declared and serves nothing rather than reading like a typo\n- Keyword `query` matches code and label; results are sorted by code and a truncated list is disclosed rather than passed off as complete\n- `ecnbasic` publishes `TAXSTAT` and `TYPOP` per industry, so `within_naics` scopes the enumeration — and the notice says the result is complete for that industry alone. A per-industry dimension is left unchecked for the same reason, since an unscoped check would withhold codes a scoped query does return\n- Live enumerations are cached per dataset, year, dimension, industry scope, and probe measure\n\n---\n\n### `census_resolve_geography`\n\nConvert place names and addresses to Census FIPS identifiers.\n\n- Named places (e.g., \"King County, WA\", \"Seattle, WA\", \"California\") resolved via TIGERweb MapServer\n- Street addresses resolved to tract level via Census Geocoder\n- Auto-detects the geography level — state for an abbreviation or spelled-out state name, county for \"County\"/\"Borough\"/\"Parish\", tract for \"Tract\", otherwise place falling back to county; `geography_type` overrides it\n- Also resolves metropolitan/micropolitan statistical areas, combined statistical areas, and consolidated cities — never auto-detected, since their names overlap city names, so each needs an explicit `geography_type`. The value is the level's own Census API name, so it feeds `geography_level` unchanged\n- Optional `county_fips` pins a tract name to one county, since a tract name is unique only inside its county. Only county and tract sit within a county, so it restricts resolution to those two levels rather than being dropped on a layer that cannot apply it\n- Prefers an exactly-named match, so \"Kansas City, MO\" does not resolve to North Kansas City\n- Never picks between matches: anything still matching more than one geography comes back as `ambiguous_name`, with every candidate carrying the code resolving it would have returned, plus the state that separates same-named places\n- Returns `state_fips` (→ `parent_fips`) and `fips_summary` (→ `geography_fips`) ready to pass to other tools; a statistical area omits `state_fips`, since it can span several states and takes no parent\n\n---\n\n### `census_query_data`\n\nQuery a Census dataset for one or more variables at a specific geography.\n\n- Requires FIPS codes — use `census_resolve_geography` first for place names\n- Use `geography_fips: \"*\"` to return all geographies at the level within the parent\n- The level and its parents are checked against the dataset's own geography metadata before the query runs: a missing `parent_fips` returns `parent_required` naming what to add, and a parent the level does not sit within returns `parent_not_accepted` naming the input to drop — neither reaches the API as an opaque 400\n- `parent_fips` and `county_fips` are zero-padded to the widths the Census matches on, so `\"5\"` and `\"05\"` both find Arkansas; either also takes `\"*\"`, which is what reaches every block group in a state. `geography_fips` takes its width from `geography_level` and is passed through as given\n- Each row carries both `geography_fips` (bare level code, round-trips back into this tool) and `geography_geoid` (level plus parents, nationally unique)\n- A query that matches nothing returns `no_data` with dataset-aware recovery, not a retried upstream error\n- Optional `predicates` map for the datasets that filter on one — `{\"NAICS2017\": \"5112\"}` narrows a `cbp` count to software publishers, and `census_list_predicate_values` supplies the codes. Keys are validated against the dataset's own variables before the query\n- Dimensions left unset are named in a notice and their applied default is echoed per row in `applied_filters`. That label is load-bearing: `cbp` defaults `NAICS2017` to the all-industries total, but `dec/ddhca` defaults `POPGROUP` to one population group and `ecnbasic` defaults its NAICS dimension to a single sector, so an unfiltered value can read like a total without being one. A dimension that publishes no label attribute (`pep/charv` `YEAR`, the `nonemp` NAICS codes before 2012) has no default to echo, and the notice says so rather than leaving it looking undefaulted\n- One geography can come back on more than one row: `pep/charv` publishes an April 1 estimates base alongside its July 1 estimate, and `MONTH` is what separates them — not `YEAR`, which both rows carry. Each row names its record in a `record` field and on its rendered heading, and the notice gives the predicate that pins one (`{\"MONTH\": \"7\"}`)\n- Suppression codes (geography too small, data not collected, etc.) resolved to human-readable reasons\n- A cell that holds text rather than a number keeps it, under `value`, so a null `estimate` says which of three things it is: `suppressed` is a number the Census withheld, a `value` alongside it is text (`GEO_ID` returns `\"0500000US53033\"`), and neither is an empty cell\n- Variable labels enriched from cache and surfaced alongside estimates\n- Requires `CENSUS_API_KEY`\n\n---\n\n### `census_compare_geographies`\n\nRank and compare variables across multiple geographies.\n\n- Fetches all geographies at a level (e.g., all WA counties) in one API call, then sorts and slices\n- Optional `within` parameter to constrain to a parent FIPS; omit for national comparison\n- Optional `geographies` list to filter to specific geographies — full GEOIDs (`\"53033\"`, `\"06037\"`) work across states; bare level codes (`\"033\"`) need `within` to disambiguate. Entries matching no row, and bare codes that matched more than one state, are named in a notice\n- Same pre-query level and parent validation as `census_query_data`, reported against `within` / `within_county`\n- Configurable sort variable, direction, and limit (default 50, max 500)\n- Same `predicates` map as `census_query_data`, applied to every geography — without it the ranking runs on whatever default the API picks, named in the notice and echoed per row in `applied_filters`\n- A dataset that publishes several records per geography is refused rather than ranked twice: a rank is a statement about one geography, so `pep/charv` without a pinned record fails with `ambiguous_rows` naming `MONTH` and the code to pass. With one pinned, each geography ranks once and the row says which record it is\n- Suppressed values sorted to end of results and labeled rather than passed through as negative sentinels\n- Same `value` field as `census_query_data` for a text cell; text has no ordering, so sorting on a column of it leaves every row tied\n- Requires `CENSUS_API_KEY`\n\n---\n\n## Features\n\nBuilt on [`@cyanheads/mcp-ts-core`](https://www.npmjs.com/package/@cyanheads/mcp-ts-core):\n\n- Declarative tool definitions — single file per tool, framework handles registration and validation\n- Unified error handling — handlers throw, framework catches, classifies, and formats with recovery hints\n- Structured logging with optional OpenTelemetry tracing\n- STDIO and Streamable HTTP transports\n\nCensus-specific:\n\n- In-process variable cache with configurable TTL — variables.json fetched once per dataset+year, searched client-side\n- Three-API backend: Census Data API for data queries, TIGERweb for named-place resolution, Census Geocoder for address-to-tract\n- Automatic retry with backoff on all external API calls\n- FIPS formatting helpers — zero-padded state, county, and tract codes ready to pass between tools\n\nAgent-friendly output:\n\n- Workflow-oriented tool surface — `fips_summary` and `state_fips` return values are ready to pass as `geography_fips` and `parent_fips` to the next tool\n- Suppression codes decoded — Census negative sentinel values (e.g., `-666666666`) surfaced as human-readable reasons instead of raw numbers\n- Recovery hints on errors — ambiguous geography names include candidate lists; missing API key errors include registration URL\n\n---\n\n## Getting started\n\n> **API key:** Register a free key at [api.census.gov/data/key_signup.html](https://api.census.gov/data/key_signup.html). Variable search and geography resolution work without a key; data queries (`census_query_data`, `census_compare_geographies`) require one.\n\nAdd the following to your MCP client configuration file:\n\n```json\n{\n  \"mcpServers\": {\n    \"census-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"bunx\",\n      \"args\": [\"@cyanheads/census-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\",\n        \"CENSUS_API_KEY\": \"your-census-api-key\"\n      }\n    }\n  }\n}\n```\n\nOr with npx (no Bun required):\n\n```json\n{\n  \"mcpServers\": {\n    \"census-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@cyanheads/census-mcp-server@latest\"],\n      \"env\": {\n        \"MCP_TRANSPORT_TYPE\": \"stdio\",\n        \"MCP_LOG_LEVEL\": \"info\",\n        \"CENSUS_API_KEY\": \"your-census-api-key\"\n      }\n    }\n  }\n}\n```\n\nOr with Docker:\n\n```json\n{\n  \"mcpServers\": {\n    \"census-mcp-server\": {\n      \"type\": \"stdio\",\n      \"command\": \"docker\",\n      \"args\": [\n        \"run\", \"-i\", \"--rm\",\n        \"-e\", \"MCP_TRANSPORT_TYPE=stdio\",\n        \"-e\", \"CENSUS_API_KEY=your-census-api-key\",\n        \"ghcr.io/cyanheads/census-mcp-server:latest\"\n      ]\n    }\n  }\n}\n```\n\nFor Streamable HTTP, set the transport and start the server:\n\n```sh\nMCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 CENSUS_API_KEY=... bun run start:http\n# Server listens at http://localhost:3010/mcp\n```\n\n### Prerequisites\n\n- [Bun v1.3.0](https://bun.sh/) or higher (or Node.js v24+).\n- A Census API key — register free at [api.census.gov/data/key_signup.html](https://api.census.gov/data/key_signup.html). Required for `census_query_data` and `census_compare_geographies`; other tools work without it.\n\n### Installation\n\n1. **Clone the repository:**\n\n```sh\ngit clone https://github.com/cyanheads/census-mcp-server.git\n```\n\n2. **Navigate into the directory:**\n\n```sh\ncd census-mcp-server\n```\n\n3. **Install dependencies:**\n\n```sh\nbun install\n```\n\n4. **Configure environment:**\n\n```sh\ncp .env.example .env\n# edit .env and set CENSUS_API_KEY\n```\n\n---\n\n## Configuration\n\n| Variable | Description | Default |\n|:---------|:------------|:--------|\n| `CENSUS_API_KEY` | **Required for data queries.** Register free at api.census.gov/data/key_signup.html. | — |\n| `CENSUS_DEFAULT_YEAR` | Default vintage year when no year is specified. | `2024` |\n| `CENSUS_VARIABLE_CACHE_TTL_HOURS` | Hours to cache variables.json per dataset+year in memory. | `24` |\n| `MCP_TRANSPORT_TYPE` | Transport: `stdio` or `http`. | `stdio` |\n| `MCP_SESSION_MODE` | HTTP session mode: `stateful`, `stateless`, or `auto`. `auto` resolves to `stateful`; the Docker image sets `stateless`. | `auto` |\n| `MCP_HTTP_PORT` | Port for HTTP server. | `3010` |\n| `MCP_AUTH_MODE` | Auth mode: `none`, `jwt`, or `oauth`. | `none` |\n| `MCP_LOG_LEVEL` | Log level (`debug`, `info`, `notice`, `warning`, `error`). | `info` |\n| `OTEL_ENABLED` | Enable OpenTelemetry instrumentation. | `false` |\n\nSee [`.env.example`](./.env.example) for the full list of optional overrides.\n\n---\n\n## Running the server\n\n### Local development\n\n```sh\n# One-time build\nbun run rebuild\n\n# Run the built server\nbun run start:stdio\n# or\nbun run start:http\n```\n\nRun checks and tests:\n\n```sh\nbun run devcheck   # Lint, format, typecheck, security audit\nbun run test       # Vitest test suite\nbun run lint:mcp   # Validate MCP definitions against spec\n```\n\n### Docker\n\n```sh\ndocker build -t census-mcp-server .\ndocker run --rm -e CENSUS_API_KEY=your-key -p 3010:3010 census-mcp-server\n```\n\nThe Dockerfile defaults to HTTP transport, stateless session mode, and logs to `/var/log/census-mcp-server`. OpenTelemetry peer dependencies are installed by default — build with `--build-arg OTEL_ENABLED=false` to omit them.\n\n---\n\n## Project structure\n\n| Path | Purpose |\n|:-----|:--------|\n| `src/index.ts` | `createApp()` entry point — registers tools and initializes services. |\n| `src/config/server-config.ts` | Census-specific env var parsing and validation with Zod. |\n| `src/mcp-server/tools/definitions/` | Tool definitions (`*.tool.ts`). |\n| `src/services/census-api/` | Census Data API client — data queries, suppression code mapping, retry logic. |\n| `src/services/geography/` | Geography resolution — TIGERweb named-place lookup and Census Geocoder address-to-tract. |\n| `src/services/variable-cache/` | In-process variables.json cache with TTL and keyword search. |\n| `tests/` | Vitest tests mirroring `src/` structure. |\n\n---\n\n## Development guide\n\nSee [`CLAUDE.md`](./CLAUDE.md) for development guidelines and architectural rules. The short version:\n\n- Handlers throw, framework catches — no `try/catch` in tool logic\n- Use `ctx.log` for request-scoped logging, `ctx.state` for tenant-scoped storage\n- Register new tools via the barrel in `src/mcp-server/tools/definitions/index.ts`\n- Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields\n\n---\n\n## Contributing\n\nIssues and pull requests are welcome. Run checks and tests before submitting:\n\n```sh\nbun run devcheck\nbun run test\n```\n\n---\n\n## License\n\nApache-2.0 — see [LICENSE](LICENSE) for details.\n",
  "bytes": 19841,
  "sha": "ca86ac3ced0fe874bc177cf4fb908dbd4d904e8b7cebd0c9af558345f22e5dfb",
  "repo_slug": "cyanheads/census-mcp-server",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_cyanheads_census_mcp_server_21de47f1/readme"
}