big update
Browse files- .python-version +1 -0
- README.md +48 -8
- app.py +6 -5
- assets/mcp-census.png +0 -0
- {mcp_functions β functions}/__init__.py +0 -0
- {mcp_functions β functions}/census_api_calls.py +2 -4
- {mcp_functions β functions}/census_api_docs.py +0 -0
- {mcp_functions β functions}/census_utils.py +2 -2
- {mcp_functions β functions}/utils.py +0 -0
- {vector_databases β functions/vector_databases}/__init__.py +0 -0
- {vector_databases β functions/vector_databases}/census_dhc_dp_techdoc/2020census-demographic-and-housing-characteristics-file-and-demographic-profile-techdoc.pdf +0 -0
- {vector_databases β functions/vector_databases}/census_dhc_dp_techdoc/__init__.py +0 -0
- {vector_databases β functions/vector_databases}/census_dhc_dp_techdoc/census_dhc_dp_techdoc.py +1 -1
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
3.13
|
README.md
CHANGED
@@ -1,21 +1,61 @@
|
|
1 |
---
|
2 |
title: ποΈ Mcp Census
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.33.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
short_description:
|
11 |
tags:
|
12 |
- mcp-server-track
|
13 |
---
|
14 |
|
15 |
-
#
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: ποΈ Mcp Census
|
3 |
+
emoji: ποΈ
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.33.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
short_description: MCP server leveraging U.S. Census Bureau tooling
|
11 |
tags:
|
12 |
- mcp-server-track
|
13 |
---
|
14 |
|
15 |
+
# mcp-census
|
16 |
|
17 |
+
A work-in-progress MCP server leveraging U.S. Census Bureau tooling for LLM interoperability.
|
18 |
+
|
19 |
+
## Example usage
|
20 |
+
|
21 |
+
Right now, we recommend using `mcp-census` in conjunction with a MCP Client like Claude Desktop or Cursor. If you prefer to run your own client application, check out [Local Agent Quickstart](#local-agent-quickstart).
|
22 |
+
|
23 |
+
**What is the population of Hennepin County, MN for those who are 65 and older?**
|
24 |
+
|
25 |
+
https://github.com/user-attachments/assets/c979b9aa-8299-4eec-ad32-362d28ced5e4
|
26 |
+
|
27 |
+
**What is the racial/ethnic breakdown of Yolo County?**
|
28 |
+
|
29 |
+
https://github.com/user-attachments/assets/d7c34ecb-4503-4bde-a7eb-b865a6f076c8
|
30 |
+
|
31 |
+
**Lookup data from the US 2020 Decennial Census and provide a CSV containing data about the number of housing units, total population, and median age for all counties in New York State. For the column containing the county identifier, please provide a complete FIPS containing the state and county as a joined value.**
|
32 |
+
|
33 |
+
https://github.com/user-attachments/assets/cffd80f0-0830-4534-ab1a-9574608967ad
|
34 |
+
|
35 |
+
## Local MCP server quickstart
|
36 |
+
|
37 |
+
We suggest using [`uv`](https://docs.astral.sh/uv/) to manage dependencies, but you can install the required packages directly from the [`pyproject.toml` file](pyproject.toml)
|
38 |
|
39 |
|
40 |
+
```zsh
|
41 |
+
uv run python app.py
|
42 |
+
```
|
43 |
+
|
44 |
+
Assuming you have no other gradio applications running, this will serve your MCP server at http://localhost:7860/gradio_api/mcp/sse
|
45 |
+
|
46 |
+
|
47 |
+
## MCP architecture
|
48 |
+
|
49 |
+
<img src="assets/mcp-census.png" alt="MCP Census" width="200" height="auto">
|
50 |
+
|
51 |
+
## Possible improvements
|
52 |
+
|
53 |
+
### Evaluation
|
54 |
+
|
55 |
+
* We recommend starting here to provide a strong benchmark with which to evaluate improvements.
|
56 |
+
* MCP server tools can be evaluated via unit tests. Agentic behavior can be evaluated on criteria described [here](https://hamel.dev/blog/posts/evals/) and emerging frameworks such as [RAGAS](https://docs.ragas.io/en/stable/).
|
57 |
+
|
58 |
+
### MCP Client
|
59 |
+
|
60 |
+
* Rather than build tool sets for every Census dataset (decennial, american community survey, etc.), it may be more comprensive to build tooling around the [machine readable dataset discovery tool](https://www.census.gov/data/developers/updates/new-discovery-tool.html).
|
61 |
+
* The Census Bureau publishes myriad documentation. Enabling semantic retrieval via RAG should provide agents with information to better respond to user queries.
|
app.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
dec2020_dp,
|
4 |
dec2020_dp_fips_lookup,
|
5 |
)
|
6 |
-
from
|
7 |
import_dec2020_datasets_homepage,
|
8 |
import_dec2020_dp_geographies,
|
9 |
import_dec2020_dp_variables,
|
10 |
)
|
11 |
-
from
|
12 |
dec2020_dhc_semantic_search,
|
13 |
required_geograpy_hierarchy_parents,
|
14 |
)
|
@@ -71,7 +72,7 @@ dec2020_datasets_homepage_interface = gr.Interface(
|
|
71 |
)
|
72 |
|
73 |
|
74 |
-
|
75 |
[
|
76 |
dec2020_datasets_homepage_interface,
|
77 |
dec2020_dp_geographies_interface,
|
@@ -94,4 +95,4 @@ mcp_server_demo = gr.TabbedInterface(
|
|
94 |
|
95 |
|
96 |
if __name__ == "__main__":
|
97 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
+
from functions.census_api_calls import (
|
4 |
dec2020_dp,
|
5 |
dec2020_dp_fips_lookup,
|
6 |
)
|
7 |
+
from functions.census_api_docs import (
|
8 |
import_dec2020_datasets_homepage,
|
9 |
import_dec2020_dp_geographies,
|
10 |
import_dec2020_dp_variables,
|
11 |
)
|
12 |
+
from functions.census_utils import (
|
13 |
dec2020_dhc_semantic_search,
|
14 |
required_geograpy_hierarchy_parents,
|
15 |
)
|
|
|
72 |
)
|
73 |
|
74 |
|
75 |
+
mcp_server = gr.TabbedInterface(
|
76 |
[
|
77 |
dec2020_datasets_homepage_interface,
|
78 |
dec2020_dp_geographies_interface,
|
|
|
95 |
|
96 |
|
97 |
if __name__ == "__main__":
|
98 |
+
mcp_server.launch(mcp_server=True)
|
assets/mcp-census.png
ADDED
![]() |
{mcp_functions β functions}/__init__.py
RENAMED
File without changes
|
{mcp_functions β functions}/census_api_calls.py
RENAMED
@@ -6,7 +6,7 @@ from typing import List, Tuple
|
|
6 |
import requests
|
7 |
from dotenv import load_dotenv
|
8 |
|
9 |
-
from
|
10 |
|
11 |
|
12 |
def parse_required_parent_geographies_string(data_str: str) -> List[Tuple[str, str]]:
|
@@ -110,9 +110,7 @@ def dec2020_dp_fips_lookup(
|
|
110 |
)
|
111 |
|
112 |
|
113 |
-
def dec2020_dp(
|
114 |
-
get_variables: str, for_clauses: str, in_clauses: str
|
115 |
-
):
|
116 |
"""
|
117 |
Fetches demographic profile data from the U.S. Census Bureau API.
|
118 |
|
|
|
6 |
import requests
|
7 |
from dotenv import load_dotenv
|
8 |
|
9 |
+
from functions.utils import build_fips_lookup, find_required_parent_geographies
|
10 |
|
11 |
|
12 |
def parse_required_parent_geographies_string(data_str: str) -> List[Tuple[str, str]]:
|
|
|
110 |
)
|
111 |
|
112 |
|
113 |
+
def dec2020_dp(get_variables: str, for_clauses: str, in_clauses: str):
|
|
|
|
|
114 |
"""
|
115 |
Fetches demographic profile data from the U.S. Census Bureau API.
|
116 |
|
{mcp_functions β functions}/census_api_docs.py
RENAMED
File without changes
|
{mcp_functions β functions}/census_utils.py
RENAMED
@@ -1,9 +1,9 @@
|
|
1 |
from typing import List
|
2 |
|
3 |
from langchain_core.documents import Document
|
4 |
-
from vector_databases.census_dhc_dp_techdoc import census_dhc_dp_techdoc
|
5 |
|
6 |
-
from
|
|
|
7 |
|
8 |
|
9 |
def required_geograpy_hierarchy_parents(geography_hierarchy: str) -> List[str | None]:
|
|
|
1 |
from typing import List
|
2 |
|
3 |
from langchain_core.documents import Document
|
|
|
4 |
|
5 |
+
from functions.utils import find_required_parent_geographies
|
6 |
+
from functions.vector_databases.census_dhc_dp_techdoc import census_dhc_dp_techdoc
|
7 |
|
8 |
|
9 |
def required_geograpy_hierarchy_parents(geography_hierarchy: str) -> List[str | None]:
|
{mcp_functions β functions}/utils.py
RENAMED
File without changes
|
{vector_databases β functions/vector_databases}/__init__.py
RENAMED
File without changes
|
{vector_databases β functions/vector_databases}/census_dhc_dp_techdoc/2020census-demographic-and-housing-characteristics-file-and-demographic-profile-techdoc.pdf
RENAMED
File without changes
|
{vector_databases β functions/vector_databases}/census_dhc_dp_techdoc/__init__.py
RENAMED
File without changes
|
{vector_databases β functions/vector_databases}/census_dhc_dp_techdoc/census_dhc_dp_techdoc.py
RENAMED
@@ -5,7 +5,7 @@ from langchain_huggingface import HuggingFaceEmbeddings
|
|
5 |
|
6 |
def load_pages():
|
7 |
loader = PyPDFLoader(
|
8 |
-
"vector_databases/census_dhc_dp_techdoc/2020census-demographic-and-housing-characteristics-file-and-demographic-profile-techdoc.pdf"
|
9 |
)
|
10 |
pages = []
|
11 |
for page in loader.load():
|
|
|
5 |
|
6 |
def load_pages():
|
7 |
loader = PyPDFLoader(
|
8 |
+
"functions/vector_databases/census_dhc_dp_techdoc/2020census-demographic-and-housing-characteristics-file-and-demographic-profile-techdoc.pdf"
|
9 |
)
|
10 |
pages = []
|
11 |
for page in loader.load():
|