How to connect Claude to government data
Add an MCP server to Claude and it can search public sources like Census, BLS and FRED, run SQL on the tables and link each number to its dataset.
Riley Hilliard8 min read
datamcpagents
To connect Claude to government data, you give it a tool that can reach the data. That tool is an MCP server: a small service Claude calls when a question needs facts it doesn’t have. Without one, Claude answers questions about unemployment, rent or electricity prices from whatever it absorbed in training, which is out of date at best and invented at worst. With one, it can fetch the actual table, run the math and show you where the number came from.
There are two ways to set this up. You can wire each agency in yourself: get an API key from the Census Bureau, another from FRED, another from BLS, and install a separate MCP server for each, or download CSVs and paste them in. That works if you only ever need one source. Once your questions cross sources, you’re dealing with a separate API, identifier scheme and set of quirks per agency, and the model still has to guess which dataset answers your question. The other way is one server that already holds many sources in a common shape. We build one, OpenData, and the second half of this post covers what it does differently.
How do you connect Claude to public data?
You add the server’s URL to your Claude client and sign in when it asks. The steps below use OpenData’s URL, https://mcp.tryopendata.ai/mcp; any remote MCP server follows the same flow with its own URL.
Claude on the web and in the desktop app
- Open Customize > Connectors in Claude.
- Click Add custom connector.
- Paste the server URL and click Add.
The first time Claude uses it, a browser window opens so you can sign in to the service. Once it’s added, you can switch it on or off for a single chat from the + button under Connectors. On the Free plan you can add one custom connector. On Team and Enterprise plans an Owner adds it under Organization settings > Connectors, and each member then clicks Connect on it. Anthropic’s page on adding a connector that isn’t in the directory has the full details, including the security notes.
Claude Code
Claude Code adds remote servers from the command line. Use --scope user if you want it in every project rather than only the current one:
$ claude mcp add --transport http --scope user opendata https://mcp.tryopendata.ai/mcpThen run /mcp inside Claude Code and follow the browser sign-in. The Claude Code MCP docs cover scopes and the other flags.
What is an MCP server for data?
An MCP server for data is a program that exposes a set of tools (search, query, chart) over the Model Context Protocol, so any client that speaks MCP can call them. Claude decides when to call a tool based on your question and the tool’s description, reads the result and writes its answer from that.
The single-source servers you’ll find usually wrap one agency’s API. A FRED server takes a series ID and returns observations. A Census server takes a dataset, variable codes and a geography. These are thin layers over the agency’s own interface, which means you inherit that interface’s rules:
| Source | What you need first | What the model has to know |
|---|---|---|
| Census | An API key from the Census Bureau | Variable codes like P1_001N and geography clauses like for=state:* |
| FRED | An API key from the St. Louis Fed | Series IDs like UNRATE |
| BLS | A registration key for version 2 of the BLS API | Series IDs like CUUR0000SA0 for the consumer price index |
Each server is configured separately, with its key in an environment variable. When a question needs two of them, say wages against rent by state, the model calls both, gets two differently shaped responses and joins them itself in the conversation. Nothing checks that the state codes or date ranges line up, so that join is where mistakes happen.
Which government data sources can you query?
With single-source servers, you can query whatever you’ve installed. With OpenData, the catalog covers more than 200 sources, including BLS, Census, FRED, FEC, the World Bank and the EPA. It turns CSV, Excel, PDF and API responses into tables, so a dataset published as a spreadsheet on an agency website is queried the same way as one that came from an API.
Every dataset is addressed as provider/dataset, and they all answer the same DuckDB SQL, so a question that spans sources becomes one query instead of two API calls and a hand-merged result. OpenData’s query_sql tool accepts up to five datasets in one query, joined on whatever key they share: state FIPS codes, country codes or dates.
When the catalog doesn’t have what you asked about, the model is told to say so, and it can file the gap with the request_dataset tool.
How does the model find the right dataset?
Single-source servers skip the search step. A FRED server can fetch any series, but only if the model already knows the series ID. Ask it about “rent in Austin” and it has to recall an identifier from memory.
OpenData’s flow starts with search instead. The model calls search_datasets with plain-language queries, and the top results come back with their column names, types, descriptions and the allowed values of low-cardinality columns. That’s enough for the model to write a correct query without a separate schema lookup.
Multi-part questions go in as several queries in one call, and the response suggests joins between the datasets it found. Before a cross-dataset join, find_related_datasets returns a ready-to-run JOIN statement with the exact key columns. If a query still names a column that doesn’t exist, the error that comes back lists the real columns, so the model can fix it on the next try.
Here is a session from our home page, run against OpenData on November 4, 2026. The question was “Are AI data centers driving up electricity bills?” Claude searched for three things at once: residential electricity prices by state, data center locations and PJM capacity auction prices. Those matched eia/retail-electricity-prices, im3/data-center-atlas and pjm/capacity-market-clearing-prices.
Claude then ran one SQL query comparing each state’s home electricity price over the latest 12 months with its 2022 average. The District of Columbia came out on top, from 14.27 to 24.3 cents per kilowatt-hour, up 70.3%, with EIA data through August 2026. Virginia, which has the most mapped data center floor space, was up 24.2%. That gap led to the follow-up question about what changed in PJM, the grid operator for D.C. and several of the states near the top of the list.
The last step is openchart, which takes the same SQL and draws the chart from it, so the model never copies rows by hand into the chart. Why a validated spec works better than generated plotting code is covered in how to generate charts with an LLM.
How do you check a number Claude gives you?
You check it against the query and the dataset it came from. Ask Claude to show the SQL it ran; a correct answer should come with a query you can read.
OpenData puts that trail in the result. Each query_sql call carries a one-sentence description of what it looks for, shown above the results in clients that render OpenData’s interface, and the result includes a link that opens the same query in OpenData’s browser sandbox. Dataset details include the source’s landing page, so you can go from a number to the table to the agency that published it. Charts have a source line for the attribution.
A few habits catch most errors, whatever server you use:
- Check the definition. “Electricity price” could be residential or all sectors, monthly or annual. Ask which one the query used.
- Check the date range. Agencies revise and publish on a lag, so “latest” means the latest month in the table, which may be several months back.
- Rerun the query yourself when the number matters. If it came from SQL, you can paste the SQL into the sandbox and see the same rows.
What about ChatGPT and other clients?
MCP is an open protocol, so the same server URL works in other clients that support remote MCP servers over HTTP. OpenData’s server uses Streamable HTTP and standard OAuth sign-in, and its sign-in is set up for Claude, ChatGPT and Cursor.
ChatGPT adds custom MCP servers through its connector settings, which aren’t available on every plan. Check OpenAI’s help center for where the option sits on your account. In Cursor, add the URL to your mcp.json:
{
"mcpServers": {
"opendata": {
"url": "https://mcp.tryopendata.ai/mcp"
}
}
}
Clients that support MCP Apps, which include Claude and ChatGPT, show OpenData’s results as interactive tables and charts inside the conversation. Clients that don’t get the same numbers and source links as text: a summary, a table of rows and the next query to run.
OpenData is where to start if you want to try it.